From: Gustav Eek Date: Sat, 18 Apr 2015 09:36:58 +0000 (+0200) Subject: [repo-encrypt] Independecny on the gpg-zip package introduced X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=96c1cc893796a9b54b8bcfb57bb5f4df79ba790d;p=users%2Fgustav%2Fscripts.git [repo-encrypt] Independecny on the gpg-zip package introduced The procedudre used in the repo-encrypt command is simplified. Archiving happens with simple tar. The program gpg-zip is not needed. The repo-encrypt script is also added to the installation scrip list. A few TODO items is also kept in the script. --- diff --git a/Makefile b/Makefile index 792c6a3..f789392 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,9 @@ SHELL = /bin/bash INSTALL = ~/bin -scripts = msmtp-notify +scripts = \ +msmtp-notify \ +repo-encrypt \ dir := $(abspath $(wildcard $(INSTALL))) diff --git a/repo-encrypt b/repo-encrypt index 19a27f0..0b0591b 100755 --- a/repo-encrypt +++ b/repo-encrypt @@ -1,6 +1,22 @@ #!/bin/bash - -user="gustav" +# +# Issue handling in order of priority. +# +# TODO FEATURE change to usage of the Git based commands for +# extraction of root directory names etc. This will change parameter +# of hte 'encrypt' command to be destination directory path, since +# filename should be derived from Git. +# +# TODO REFACTOR Separate sentral command functionality (compression +# and extractions) into functions +# +# TODO REFACTOR Use the getopts functionality for to parce command +# line options. +# +# TODO REFACTOR Use git clone (double check this) for exportion of the +# ".git" repository files. + +user=$USER help="\ Encrypts or decrypts a bare repository to or from some origin or destination, using gpg-zip. @@ -24,18 +40,19 @@ if [ $1 == encrypt ]; then 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 - + 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" + rm -fr "$tmp_dir" 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 - + gpg --decrypt < "$origin" | tar --extract --directory "$destination" else printf "$0: Command '$1' does not exist!\n\n$help"; exit 2 fi