#!/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.
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