Created
September 13, 2016 23:15
-
-
Save DevElCuy/60bec422f93910c6983386e52f77f953 to your computer and use it in GitHub Desktop.
Copy files from "src" folder into a memory partition
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
#!/usr/bin/env bash | |
SRC_PATH="src" | |
BKP_PATH="$SRC_PATH-ondisk" | |
INIT_SCRIPT="" | |
EXIT_SCRIPT="" | |
case "$1" in | |
up|"") | |
if [ -d "$BKP_PATH" ]; then | |
echo "ERROR: Folder $BKP_PATH is present, please fix manually and try again then." | |
exit 3 | |
fi | |
if [ -d "$SRC_PATH" ]; then | |
echo "Creating RAM partition at $SRC_PATH ..." | |
# Copy files to RAM | |
mv "$SRC_PATH" "$BKP_PATH" | |
mkdir "$SRC_PATH" | |
sudo mount -t tmpfs tmpfs "$SRC_PATH" -o size=1024m | |
cp -a "$BKP_PATH"/* "$SRC_PATH"/ | |
cp -a "$BKP_PATH"/.[a-zA-Z]* "$SRC_PATH"/ | |
# Start VM/container | |
if [ "$(ls -A $SRC_PATH)" ]; then | |
eval $INIT_SCRIPT | |
else | |
echo "ERROR: Something went wrong while creating the RAM partition." | |
exit 3 | |
fi | |
else | |
ls "$SRC_PATH" | |
exit 3 | |
fi | |
;; | |
down) | |
echo "Destroying RAM partition at $SRC_PATH ..." | |
eval $EXIT_SCRIPT | |
sudo umount "$SRC_PATH" | |
if [ "$(ls -A $SRC_PATH)" ]; then | |
echo "ERROR: Can't umount '$SRC_PATH' do it manually!" | |
exit 3 | |
else | |
rm -r "$SRC_PATH" | |
mv "$BKP_PATH" "$SRC_PATH" | |
fi | |
;; | |
*) | |
echo "Usage: pj_start.sh up|down" >&2 | |
exit 3 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment