Last active
October 13, 2022 08:09
-
-
Save johncylee/96d8aabeb74a44029bfe5862405c1bd6 to your computer and use it in GitHub Desktop.
Use RAM as tmp overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Assuming tmpfs on $TMPDIR / /tmp | |
function cleanup { | |
echo | |
if findmnt -t overlay "$D" &>/dev/null; then | |
sudo umount -l "$D" | |
if [ -d "$UPPER" ]; then | |
if [ x"$(ls -1A ${UPPER})" != x ]; then | |
echo "Copying from upper dir to lower dir" | |
cp -av "$UPPER"/. "$D" | |
fi | |
rm -rv "$UPPER" | |
fi | |
test -d "$WORK" && sudo rm -rv "$WORK" | |
fi | |
} | |
if [ x"$1" == x ]; then | |
echo "${0} <directory>" | |
exit | |
fi | |
D=$(realpath -e "$1") | |
if [ ! -d "$D" ]; then | |
echo "${D} not a directory." | |
exit 1 | |
fi | |
UPPER=$(mktemp -d --tmpdir "$(id -u).upper.XXX") | |
WORK=$(mktemp -d --tmpdir "$(id -u).work.XXX") | |
echo "UPPER DIR: $UPPER" | |
echo "WORK DIR: $WORK" | |
trap cleanup EXIT | |
sudo mount -t overlay overlay \ | |
-olowerdir="$D",upperdir="$UPPER",workdir="$WORK" \ | |
"$D" | |
echo "Ctrl-C when you're done" | |
while true; do | |
sleep 3600 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment