From: Gustav Eek Date: Sat, 18 Apr 2015 07:56:35 +0000 (+0200) Subject: First inclusion of the repo-encrypt script X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=cd6b74daf77e9a2bbd3374239978f37f60e0e618;p=users%2Fgustav%2Fscripts.git First inclusion of the repo-encrypt script --- diff --git a/repo-encrypt b/repo-encrypt new file mode 100755 index 0000000..19a27f0 --- /dev/null +++ b/repo-encrypt @@ -0,0 +1,43 @@ +#!/bin/bash + +user="gustav" +help="\ +Encrypts or decrypts a bare repository to or from some origin +or destination, using gpg-zip. + +usage: repo-encrypt encrypt + repo-encrypt decrypt + +examples: + + repo-encrypt encrypt /media/usb/git/configurations.gpg-zip + + repo-encrypt decrypt /media/usb/git/configurations.gpg-zip /tmp + +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 + if [ ! -d ".git" ]; then printf "$0: This is not a Git repository.\n\n$help"; exit 2; fi + destination=$2 + if [ ! $(echo $destination | grep "^/") ]; then destination="$(pwd)/$destination"; fi + parent="$(pwd | sed -e 's:^/.*/\(.*$\):\1:')" + cd .. + gpg-zip --encrypt --output "$destination" --gpg-args "-r $user" "${parent}/.git" + cd - +elif [ $1 == decrypt ]; then + if [ ${#@} -ne 3 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 2; fi + origin=$2 + destination=$3 + if [ ! $(echo $destination | grep "^/") ]; then destination="$(pwd)/$destination"; fi + if [ ! $(echo $origin | grep "^/") ]; then origin="$(pwd)/$origin"; fi + cd "$destination" + gpg-zip --decrypt "$origin" + cd - +else printf "$0: Command '$1' does not exist!\n\n$help"; exit 2 +fi + +# for decryption +