universalize and consolidate on --fixed-list-mode
[monkeysphere.git] / src / share / common
index f8ae9dfdb5bc1a0360fd1d1daf9a0521a7277d31..baf4270c0b4b749b488fd78ec9b3203a03963a7e 100644 (file)
@@ -346,7 +346,7 @@ remove_line() {
        log debug "removing matching key lines..."
        tempfile=$(mktemp "${file}.XXXXXXX") || \
            failure "Unable to make temp file '${file}.XXXXXXX'"
-       grep -v -x -F "$lines" "$file" >"$tempfile"
+       grep -v -x -F "$lines" "$file" >"$tempfile" || :
        mv -f "$tempfile" "$file"
     fi
 }
@@ -384,6 +384,8 @@ test_gpg_expire() {
 # directories with correct permissions
 touch_key_file_or_fail() {
     local keyFile="$1"
+    local newUmask
+
     if [ ! -f "$keyFile" ]; then
        # make sure to create files and directories with the
        # appropriate write bits turned off:
@@ -652,7 +654,7 @@ process_user_id() {
     gpg_fetch_userid "$userID"
 
     # output gpg info for (exact) userid and store
-    gpgOut=$(gpg --list-key --fixed-list-mode --with-colon \
+    gpgOut=$(gpg --list-key --fixed-list-mode --with-colons \
        --with-fingerprint --with-fingerprint \
        ="$userID" 2>/dev/null) || returnCode="$?"
 
@@ -839,6 +841,8 @@ process_keys_for_file() {
            esac
        fi
 
+       ((++KEYS_PROCESSED))
+
        # if key OK, add new key line
        if [ "$ok" -eq '0' ] ; then
            case "$FILE_TYPE" in
@@ -854,14 +858,20 @@ process_keys_for_file() {
                    ;;
            esac
 
-           echo "$keyLine" | log debug
+           echo "key line: $keyLine" | log debug
            if [[ "$keyFile" == '-' ]] ; then
                echo "$keyLine"
            else
+               log debug "adding key line to file..."
                echo "$keyLine" >>"$keyFile"
            fi
+
+           ((++KEYS_VALID))
        fi
     done
+
+    log debug "KEYS_PROCESSED=$KEYS_PROCESSED"
+    log debug "KEYS_VALID=$KEYS_VALID"
 }
 
 # process an authorized_user_ids file on stdin for authorized_keys