]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Fixing init command and checking for empty recipients file
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 5 Feb 2012 15:48:14 +0000 (13:48 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 5 Feb 2012 15:48:14 +0000 (13:48 -0200)
lib/keyringer/functions

index 58f7ad1d056812af72b2af8094bf1339f2232224..da8be2e8cc3f916ee4e34eaea2b443d1e657a870 100644 (file)
@@ -95,10 +95,9 @@ function keyringer_is_git {
   elif [ -d "$1/.git" ]; then
     true
   else
-    cwd="`pwd`"
-    cd "$1" && git="`git status &> /dev/null`" && cd "$cwd"
+    ( cd "$1" && git status &> /dev/null )
 
-    if [ "$git" != "128" ]; then
+    if [ "$?" != "128" ]; then
       true
     else
       false
@@ -225,7 +224,9 @@ function keyringer_check_version {
   if [ ! -f "$VERSION_INFO" ]; then
     echo "Creating configuration version file..."
     echo 0 > "$VERSION_INFO"
-    keyringer_exec git "$BASEDIR" add config/version
+    if keyringer_is_git "$BASEDIR"; then
+      keyringer_exec git "$BASEDIR" add config/version
+    fi
   fi
 
   VERSION="`cat $VERSION_INFO`"
@@ -282,6 +283,13 @@ function keyringer_action_usage {
 
 # Check recipients
 function keyringer_check_recipients {
+  # Check if recipients file is empty.
+  if [ "`grep -vE "^#|^$" "$RECIPIENTS" | wc -l`" == 0 ] && [ "$SUBCOMMAND" != "edit" ]; then
+    echo "Fatal: no recipients configured for this keyring."
+    echo "Please edit your recipients file first."
+    exit 1
+  fi
+
   # Check recipients header for updates.
   if grep -qe ' XXXXXXXX$' "$RECIPIENTS"; then
     echo "Updating recipients file..."