Skip to content

Instantly share code, notes, and snippets.

@wardenlym
Forked from redguardtoo/proj2ram
Created January 27, 2016 07:42
Show Gist options
  • Save wardenlym/d4c512afebb2006a5afa to your computer and use it in GitHub Desktop.
Save wardenlym/d4c512afebb2006a5afa to your computer and use it in GitHub Desktop.
script to copy project to tmpfs
#!/bin/sh
if [ -z "$1" ];then
echo "Usage:"
echo " proj2ram proj-name"
echo " proj2ram restore proj-name"
exit 1
fi
if [ "$1" != "restore" ];then
backup=$1-backup
link=$1
volatile=/tmp/$1-$USER
IFS=
set -efu
cd ~/projs
if [ ! -r $volatile ]; then
mkdir -m0700 $volatile
fi
# link -> volatie does not exist
if [ "$(readlink $link)" != "$volatile" ]; then
# backup project at first
mv $link $backup
# create the link
ln -s $volatile $link
fi
if [ -e $link/.unpacked ]; then
echo "Sync project from memory to backup ..."
rsync -avq --delete --exclude .unpacked ./$link/ ./$backup/
echo "DONE!"
else
echo "Sync project from disk to memory ..."
rsync -avq ./$backup/ ./$link/
touch $link/.unpacked
echo "DONE!"
fi
else
if [ -z "$2" ]; then
echo "Usage:"
echo " proj2ram restore proj-name"
else
echo "Moving project back to disk ..."
backup=$2-backup
link=$2
volatile=/tmp/$2-$USER
cd ~/projs
rm $link && mv $backup $link && rm -rf $volatile
echo "DONE!"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment