From: Gustav Eek Date: Mon, 22 Jun 2020 22:05:24 +0000 (+0200) Subject: [repo-encrypt] Update for recipients X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=47c7c1912617a1492294a5f527531aaa9333072f;p=users%2Fgustav%2Fscripts.git [repo-encrypt] Update for recipients Update script for abstract recipients. --- diff --git a/repo-encrypt b/repo-encrypt index 6ae21a8..d46176e 100755 --- a/repo-encrypt +++ b/repo-encrypt @@ -19,18 +19,20 @@ # TODO REFACTOR Use git clone (double check this) for exportion of the # ".git" repository files. -user=$USER +recipient=$USER help="\ Encrypts or decrypts a bare repository to or from some origin or destination, using gpg-zip. -usage: repo-encrypt encrypt +usage: repo-encrypt encrypt [-r ] repo-encrypt decrypt examples: repo-encrypt encrypt /media/usb/git/ + repo-encrypt encrypt -r bob@example.com /media/usb/git/ + repo-encrypt decrypt /media/usb/git/configurations.git.tar.gpg /tmp For the encryption command, parent directory need to be a git repository. @@ -38,16 +40,20 @@ For the encryption command, parent directory need to be a git repository. if [ ${#@} -lt 2 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 2; fi if [ $1 == encrypt ]; then - if [ ${#@} -ne 2 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 2; fi + shift if [ ! -d ".git" ]; then printf "$0: This is not a Git repository.\n\n$help"; exit 2; fi - destination="$2" + if [ $1 == "-r" ]; then + shift; recipient="$1"; shift + fi + if [ ${#@} -ne 1 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 2; fi + destination="$1" if [ ! -d "$destination" ]; then printf "$0: Destination is not a directory.\n\n$help"; exit 2; fi parent="$(pwd | sed -e 's:^/.*/\(.*$\):\1:')" tmp_dir="/tmp/${0##*/}-$$" mkdir "$tmp_dir" cp -R .git "$tmp_dir/$parent.git" tar --directory "$tmp_dir" --create --file "$tmp_dir/$parent.git.tar" "$parent.git" - gpg --encrypt --recipient "$user" < "$tmp_dir/$parent.git.tar" > "$destination/$parent.git.tar.gpg" + gpg --encrypt --recipient "$recipient" < "$tmp_dir/$parent.git.tar" > "$destination/$parent.git.tar.gpg" rm -fr "$tmp_dir" elif [ $1 == decrypt ]; then if [ ${#@} -ne 3 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 2; fi