2024-03-03 00:55:45 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
cd $SCRIPT_DIR
|
|
|
|
|
|
|
|
if [ $# = 0 ] || ( [ $# = 1 ] && [ $1 = "help" ] ); then
|
|
|
|
echo "Use \"unlock\" to unlock with pgp"
|
|
|
|
echo "Use \"unlock\" /path/to/key to unlock with symmetric key"
|
|
|
|
echo "Use \"lock\": to lock repository"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(git status --porcelain)" ]; then
|
|
|
|
echo "Working directory not clean."
|
|
|
|
echo "Please commit your changes or 'git stash' them before running this script"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
create_decrypt () {
|
|
|
|
touch decrypted
|
|
|
|
git add --intent-to-add decrypted
|
|
|
|
git update-index --assume-unchanged decrypted
|
|
|
|
}
|
2024-03-03 13:20:02 +01:00
|
|
|
delete_decrypt () {
|
|
|
|
rm decrypted
|
|
|
|
git rm decrypted
|
|
|
|
}
|
2024-03-03 00:55:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
if [ $# = 1 ]; then
|
|
|
|
|
|
|
|
if [ $1 = "unlock" ]; then
|
|
|
|
git-crypt unlock
|
|
|
|
create_decrypt
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $1 = "lock" ]; then
|
2024-03-03 13:20:02 +01:00
|
|
|
delete_decrypt
|
2024-03-03 00:55:45 +01:00
|
|
|
git-crypt lock
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2024-03-03 13:20:02 +01:00
|
|
|
if [ $1 = "create_decrypt" ]; then
|
|
|
|
create_decrypt
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $1 = "delete_decrypt" ]; then
|
|
|
|
delete_decrypt
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2024-03-03 00:55:45 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# = 2 ] && [ $1 = "unlock" ]; then
|
|
|
|
git-crypt unlock $2
|
|
|
|
create_decrypt
|
|
|
|
exit
|
|
|
|
fi
|