Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Created June 1, 2016 07:51
Show Gist options
  • Save tmlbl/f6731b750a8cae5bdd255c7d24c4fc90 to your computer and use it in GitHub Desktop.
Save tmlbl/f6731b750a8cae5bdd255c7d24c4fc90 to your computer and use it in GitHub Desktop.
A quick bash script to encrypt a directory with a passkey.
#!/bin/bash
BANK_DIR=$HOME/.bank
mkdir -p $BANK_DIR;
if [ "$1" = "lock" ]; then
if [ -e $BANK_DIR.tar.gz.gpg ]; then
echo "$BANK_DIR already locked.";
exit 1;
fi
echo "Locking $BANK_DIR...";
(tar zcvf - -C $HOME .bank | gpg -c > $BANK_DIR.tar.gz.gpg) &&
rm -r $BANK_DIR;
elif [ "$1" = "unlock" ]; then
echo "Unlocking $BANK_DIR...";
(gpg --decrypt $BANK_DIR.tar.gz.gpg | tar -xzf - -C $HOME) &&
rm $BANK_DIR.tar.gz.gpg;
else
echo "Commands: lock, unlock";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment