Last active
October 12, 2017 19:39
-
-
Save timmc/6c397644668bcf41041f to your computer and use it in GitHub Desktop.
Mount a ramdisk over target
This file contains 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 | |
# Overwrite ./target with a tmpfs ramdisk. Prompts for sudo. | |
function usage() { | |
echo 'Usage: `ramdisk-target.sh recreate|restore`' | |
} | |
if [ ! -f "project.clj" ]; then | |
echo "Not in Clojure project." | |
exit 2 | |
fi | |
function remove-old() { | |
if mountpoint -q ./target; then | |
if fuser --mount ./target; then | |
echo "Processes are currently using the ramdisk!" | |
exit 2 | |
fi | |
echo "Unmounting ./target" | |
sudo umount ./target || exit 1 | |
fi | |
if [ "`stat --format="%F" ./target`" = 'directory' ]; then | |
echo "Deleting ./target directory" | |
rm -rf ./target || exit 1 | |
fi | |
} | |
## Primitives | |
function restore() { | |
remove-old | |
mkdir ./target | |
} | |
function mount-on-point() { | |
group=`stat --format='%G' .` | |
user=`stat --format='%U' .` | |
echo "Creating mount point with ownership $user:$group" | |
sudo mount -t tmpfs -o size=400M tmpfs ./target | |
sudo chown $group:$user ./target | |
} | |
## Actions | |
function become-mounted() { | |
# Remove any existing target so that we don't end up with old stuff | |
# exposed when we umount. | |
restore | |
mount-on-point | |
} | |
## Dispatch | |
case "$1" in | |
recreate) | |
become-mounted | |
;; | |
restore) | |
restore | |
;; | |
*) | |
usage | |
exit 0 | |
;; | |
esac |
This file contains 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 | |
for p in ~/work/{repo1,repo2,repo3} | |
do | |
(cd $p; ramdisk-target.sh recreate) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment