summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/keyringer/functions34
-rwxr-xr-xshare/keyringer/append12
-rwxr-xr-xshare/keyringer/decrypt12
-rwxr-xr-xshare/keyringer/del13
-rwxr-xr-xshare/keyringer/edit12
-rwxr-xr-xshare/keyringer/recrypt12
6 files changed, 45 insertions, 50 deletions
diff --git a/lib/keyringer/functions b/lib/keyringer/functions
index adaf576..24df5af 100644
--- a/lib/keyringer/functions
+++ b/lib/keyringer/functions
@@ -176,3 +176,37 @@ function keyringer_set_env {
exit 1
fi
}
+
+# Get a single argument
+function keyringer_get_arg {
+ if [ -z "$1" ]; then
+ keyringer_action_usage
+ exit 1
+ fi
+
+ echo $1
+}
+
+# Get a file argument
+function keyringer_get_file {
+ FILE="`keyringer_filename $1`"
+
+ if [ -z "$FILE" ]; then
+ keyringer_action_usage
+ exit 1
+ elif [ ! -f "$KEYDIR/$FILE" ]; then
+ echo "File not found: $KEYDIR/$FILE"
+ exit 1
+ fi
+}
+
+# Run the action usage
+function keyringer_action_usage {
+ if [ "`type -t "keyringer_usage_$BASENAME"`" == "function" ]; then
+ # Use custom action usage
+ keyringer_usage_$BASENAME
+ else
+ # Default usage
+ echo "Usage: keyringer <keyring> $BASENAME <file>"
+ fi
+}
diff --git a/share/keyringer/append b/share/keyringer/append
index fbfe49f..309f88c 100755
--- a/share/keyringer/append
+++ b/share/keyringer/append
@@ -8,16 +8,8 @@ LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*
-# Aditional parameters
-FILE="`keyringer_filename $2`"
-
-if [ -z "$FILE" ]; then
- echo "Usage: keyringer <keyring> `basename $0` <file>"
- exit 1
-elif [ ! -f "$KEYDIR/$FILE" ]; then
- echo "File not found: $KEYDIR/$FILE"
- exit 1
-fi
+# Get file
+keyringer_get_file $2
OLDIFS=$IFS
IFS=$'\n'
diff --git a/share/keyringer/decrypt b/share/keyringer/decrypt
index cb1d35b..71367f5 100755
--- a/share/keyringer/decrypt
+++ b/share/keyringer/decrypt
@@ -8,15 +8,7 @@ LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*
-# Aditional parameters
-FILE="`keyringer_filename $2`"
-
-if [ -z "$FILE" ]; then
- echo "Usage: keyringer <keyring> `basename $0` <file>"
- exit 1
-elif [ ! -f "$KEYDIR/$FILE" ]; then
- echo "File not found: $KEYDIR/$FILE"
- exit 1
-fi
+# Get file
+keyringer_get_file $2
gpg --quiet --use-agent -d $KEYDIR/$FILE
diff --git a/share/keyringer/del b/share/keyringer/del
index c699394..d8ed68f 100755
--- a/share/keyringer/del
+++ b/share/keyringer/del
@@ -8,17 +8,8 @@ LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*
-# Aditional parameters
-FILE="`keyringer_filename $2`"
-
-# Setup
-if [ -z "$FILE" ]; then
- echo "Usage: keyringer <keyring> `basename $0` <file>"
- exit 1
-elif [ ! -f "$KEYDIR/$FILE" ]; then
- echo "File not found: $KEYDIR/$FILE"
- exit 1
-fi
+# Get file
+keyringer_get_file $2
# Remove
if [ -d "$KEYDIR/.git" ]; then
diff --git a/share/keyringer/edit b/share/keyringer/edit
index dff42e6..8584c32 100755
--- a/share/keyringer/edit
+++ b/share/keyringer/edit
@@ -8,16 +8,10 @@ LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*
-# Aditional parameters
-FILE="`keyringer_filename $2`"
+# Get file
+keyringer_get_file $2
-if [ -z "$FILE" ]; then
- echo "Usage: keyringer <keyring> `basename $0` <file>"
- exit 1
-elif [ ! -f "$KEYDIR/$FILE" ]; then
- echo "File not found: $KEYDIR/$FILE"
- exit 1
-elif [ -z "$EDITOR" ]; then
+if [ -z "$EDITOR" ]; then
echo "You have to set EDITOR env variable"
exit 1
fi
diff --git a/share/keyringer/recrypt b/share/keyringer/recrypt
index 32a8a39..92afa99 100755
--- a/share/keyringer/recrypt
+++ b/share/keyringer/recrypt
@@ -8,15 +8,7 @@ LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*
-# Aditional parameters
-FILE="`keyringer_filename $2`"
-
-if [ -z "$FILE" ]; then
- echo "Usage: keyringer <keyring> `basename $0` <file>"
- exit 1
-if [ ! -f "$KEYDIR/$FILE" ]; then
- echo "File not found: $KEYDIR/$FILE"
- exit 1
-fi
+# Get file
+keyringer_get_file $2
gpg --use-agent -d $KEYDIR/$FILE | gpg --use-agent --armor -e -s $(keyringer_recipients $RECIPIENTS) > $KEYDIR/$FILE