From: Gustav Eek Date: Sun, 19 Apr 2015 19:29:29 +0000 (+0200) Subject: [repo-encrypt] Encryption command to take directory as argument X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=ea44029c27746a47161fe7a4181ca663f753e93c;p=users%2Fgustav%2Fscripts.git [repo-encrypt] Encryption command to take directory as argument Tor the encryption command the parameter handling is modified to take a target directory as argument instead of target file as before. --- diff --git a/repo-encrypt b/repo-encrypt index 0b0591b..1e59c71 100755 --- a/repo-encrypt +++ b/repo-encrypt @@ -7,6 +7,9 @@ # of hte 'encrypt' command to be destination directory path, since # filename should be derived from Git. # +# Comment. Already as of now, the destination directory, not the file, +# is provided as argument. +# # TODO REFACTOR Separate sentral command functionality (compression # and extractions) into functions # @@ -21,14 +24,14 @@ 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 repo-encrypt decrypt examples: - repo-encrypt encrypt /media/usb/git/configurations.gpg-zip + repo-encrypt encrypt /media/usb/git/ - repo-encrypt decrypt /media/usb/git/configurations.gpg-zip /tmp + repo-encrypt decrypt /media/usb/git/configurations.git.tar.gpg /tmp For the encryption command, parent directory need to be a git repository. " @@ -37,14 +40,14 @@ if [ ${#@} -lt 2 ]; then printf "$0: Wrong number of arguments!\n\n$help"; exit 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 + destination="$2" + 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 --recursive .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" + gpg --encrypt --recipient "$user" < "$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