]> git.g-eek.se Git - users/gustav/scripts.git/commitdiff
First inclusion of the repo-encrypt script
authorGustav Eek <gustav@fripost.org>
Sat, 18 Apr 2015 07:56:35 +0000 (09:56 +0200)
committerGustav Eek <gustav@fripost.org>
Sat, 18 Apr 2015 07:56:35 +0000 (09:56 +0200)
repo-encrypt [new file with mode: 0755]

diff --git a/repo-encrypt b/repo-encrypt
new file mode 100755 (executable)
index 0000000..19a27f0
--- /dev/null
@@ -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 <destination-filename>
+       repo-encrypt decrypt <origin-filename> <destination-directory>
+
+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
+