From deaa785e1f662274d51f5918a4ab36b74d214f56 Mon Sep 17 00:00:00 2001 From: materus Date: Sun, 3 Mar 2024 00:55:45 +0100 Subject: [PATCH] git-crypt: add simple script to unlock repo --- crypt.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 crypt.sh diff --git a/crypt.sh b/crypt.sh new file mode 100755 index 0000000..75deba5 --- /dev/null +++ b/crypt.sh @@ -0,0 +1,46 @@ +#!/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 +} + + +if [ $# = 1 ]; then + + if [ $1 = "unlock" ]; then + git-crypt unlock + create_decrypt + exit + fi + + if [ $1 = "lock" ]; then + rm decrypted + git-crypt lock + exit + fi + +fi + +if [ $# = 2 ] && [ $1 = "unlock" ]; then + git-crypt unlock $2 + create_decrypt + exit +fi \ No newline at end of file