]> gitweb.fluxo.info Git - keyringer.git/commitdiff
New function keyringer_check_repository
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 25 Feb 2014 16:00:50 +0000 (13:00 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 25 Feb 2014 16:00:50 +0000 (13:00 -0300)
lib/keyringer/actions/check
lib/keyringer/functions

index 83401b809a5994cf3a421a7dc77f9a006d6c830e..70fa7b47f9efbc9704a185a026815a06206d2c61 100755 (executable)
@@ -16,7 +16,8 @@
 LIB="`dirname $0`/../functions"
 source "$LIB" || exit 1
 
-# The following should run automatically from keyringer_check_recipients:
+# The following should run automatically from keyringer_check_recipients
+# and keyringer_check_repository:
 #
 # TODO: Pull the keyring repository.
 # TODO: Fetch absent keys from all recipients.
@@ -24,16 +25,7 @@ source "$LIB" || exit 1
 # TODO: Time to expire can be configured via repository options.
 # TODO: Users can be alerted by mail if configured by user preferences.
 # TODO: Outgoing emails can be encrypted.
+# TODO: Git maintenance operations.
 
 # This should be done here:
 # TODO: Check canaries' timestamps, warning by mail if configured by user preferences.
-
-# Git maintenance operations.
-if [ -d "$BASEDIR/.git" ]; then
-  echo "Running git maintenance operations..."
-  keyringer_exec git "$BASEDIR" fsck
-  keyringer_exec git "$BASEDIR" gc --prune=all
-else
-  echo "Fatal: not a git repository: $BASEDIR"
-  exit 1
-fi
index 47468591cc631015d22874a9a558cba735c87870..e594fd1a88f2a6e5ca503f7b9a8ab2e0e2e5c0e0 100755 (executable)
@@ -301,6 +301,11 @@ function keyringer_set_env {
   # Upgrade configuration
   keyringer_upgrade
 
+  # Check repository integrity
+  if [ "$BASENAME" == "check" ]; then
+    keyringer_check_repository
+  fi
+
   # Check recipients file
   keyringer_check_recipients $SUBCOMMAND
 
@@ -513,6 +518,28 @@ function keyringer_usage {
   fi
 }
 
+# Check repository integrity
+function keyringer_check_repository {
+  # Check if it's a git repository
+  if [ ! -d "$BASEDIR/.git" ]; then
+    echo "Fatal: not a git repository: $BASEDIR"
+    exit 1
+  fi
+
+  # Git maintenance operations
+  echo "Running git maintenance operations..."
+  keyringer_exec git "$BASEDIR" fsck
+  keyringer_exec git "$BASEDIR" gc --prune=all
+  echo ""
+
+  # Sync the repository
+  if [ "`keyringer_exec git "$BASEDIR" remote | wc -l`" != "0" ]; then
+    echo "Syncing git repository..."
+    keyringer_exec git "$BASEDIR" pull
+    echo ""
+  fi
+}
+
 # Check recipients
 # TODO: break in smaller pieces
 function keyringer_check_recipients {
@@ -524,13 +551,6 @@ function keyringer_check_recipients {
   # Local variables
   local processed=":"
 
-  # Sync the repository
-  if [ "$BASENAME" == "check" ]; then
-    echo "Syncing git repository..."
-    keyringer_exec git "$BASEDIR" pull
-    echo ""
-  fi
-
   # Check if recipients file is empty.
   if [ "`grep -vE "^#|^$" "$RECIPIENTS"/* | wc -l`" == 0 ] && [ "$SUBCOMMAND" != "edit" ]; then
     echo "Fatal: no recipients configured for this keyring."