From 96c1cc893796a9b54b8bcfb57bb5f4df79ba790d Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Sat, 18 Apr 2015 11:36:58 +0200 Subject: [PATCH] [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. --- Makefile | 4 +++- repo-encrypt | 33 +++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) 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 -- 2.39.2