]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Making code that checks for command argument as a common function
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Sep 2010 16:27:02 +0000 (13:27 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Sep 2010 16:27:02 +0000 (13:27 -0300)
lib/keyringer/functions
share/keyringer/newkeys
share/keyringer/options
share/keyringer/recipients
share/keyringer/recrypt

index 96ca7e6230cc833f1d58b2824fddff4e3e30b7df..630f5192cf1ef98ac2e74a536a5927a3997f4715 100644 (file)
@@ -192,16 +192,6 @@ function keyringer_set_env {
   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`"
@@ -222,6 +212,21 @@ function keyringer_action_usage {
     keyringer_usage_$BASENAME
   else
     # Default usage
-    echo "Usage: keyringer <keyring> $BASENAME <file>"
+    if [ "$1" == "command" ]; then
+      echo "Usage: keyringer <keyring> $BASENAME <command> [arguments]"
+    else
+      echo "Usage: keyringer <keyring> $BASENAME <file>"
+    fi
+  fi
+}
+
+# Get a command argument
+function keyringer_get_command {
+  # Aditional parameters
+  COMMAND="$1"
+  
+  if [ -z "$COMMAND" ]; then
+    keyringer_action_usage command
+    exit 1
   fi
 }
index c7eb562fbfa462562755c2b3c8c97cbca19ebfdd..eff529e778f2a3055e95b19d724217c08896f65a 100755 (executable)
@@ -3,14 +3,6 @@
 # Create keys for new nodes.
 #
 
-# Load functions
-LIB="`dirname $0`/../../lib/keyringer/functions"
-source $LIB
-keyringer_set_env $*
-
-# Aditional parameters
-COMMAND="$2"
-
 function newkeys_nodes {
   # See http://www.mail-archive.com/puppet-users@googlegroups.com/msg01615.html
   grep ^node $* | sed -e 's/^node //' | awk -F, '{for(i=1;i<=NF;i++) {print $i}}' | cut -d "'" -f2
@@ -45,11 +37,10 @@ function newkeys_puppet {
 # Load functions
 LIB="`dirname $0`/../../lib/keyringer"
 source $LIB/functions
+keyringer_set_env $*
 
-if [ -z "$COMMAND" ]; then
-  echo "Usage: keyringer <keyring> `basename $0` <command> [arguments]"
-  exit 1
-fi
+# Command parser
+keyringer_get_command $2
 
 source $OPTIONS
 keyringer_config_load_preferences
index 4fe80924f9529a360f68e2ce0c3423469503c357..6708b54070ddaada41a454603cc9bada84e7a1a6 100755 (executable)
@@ -8,13 +8,8 @@ LIB="`dirname $0`/../../lib/keyringer"
 source $LIB/functions
 keyringer_set_env $*
 
-# Aditional parameters
-COMMAND="$2"
-
-if [ -z "$COMMAND" ]; then
-  echo "Usage: keyringer <keyring> `basename $0` <command> [arguments]"
-  exit 1
-fi
+# Command parser
+keyringer_get_command $2
 
 # Create options file if old repository
 if [ ! -e "$OPTIONS" ]; then
index 3410b3d38ce032311f9bbd68325cf0e3f2376e9f..36eefcc1fa73e9def5e7bd13a7ed921b2edb6e74 100755 (executable)
@@ -8,13 +8,8 @@ LIB="`dirname $0`/../../lib/keyringer"
 source $LIB/functions
 keyringer_set_env $*
 
-# Aditional parameters
-COMMAND="$2"
-
-if [ -z "$COMMAND" ]; then
-  echo "Usage: keyringer <keyring> `basename $0` <command> [arguments]"
-  exit 1
-fi
+# Command parser
+keyringer_get_command $2
 
 if [ "$COMMAND" == "ls" ]; then
   cat $RECIPIENTS
index 92afa99274fa2a9a0c523c0a47c9a0769c8b935e..a45efa112df22d3534ec23fc843ba42ee111e8d4 100755 (executable)
@@ -11,4 +11,5 @@ keyringer_set_env $*
 # Get file
 keyringer_get_file $2
 
+# Recrypt
 gpg --use-agent -d $KEYDIR/$FILE | gpg --use-agent --armor -e -s $(keyringer_recipients $RECIPIENTS) > $KEYDIR/$FILE