Merge commit 'dkg/master'
[monkeysphere.git] / src / common
index b4e786bf0fb343b1dada37a722619c4e9e8e3a3b..9c76bd1e7e236b1d7183e1c6236ee70e083b9ee4 100644 (file)
@@ -64,11 +64,16 @@ check_capability() {
     return 0
 }
 
+# hash of a file
+file_hash() {
+    md5sum "$1" 2> /dev/null
+}
+
 # convert escaped characters from gpg output back into original
 # character
 # FIXME: undo all escape character translation in with-colons gpg output
 unescape() {
-    echo "$1" | sed 's/\\x3a/:/'
+    echo "$1" | sed 's/\\x3a/:/g'
 }
 
 # remove all lines with specified string from specified file
@@ -573,7 +578,7 @@ update_known_hosts() {
     lockfile-create "$KNOWN_HOSTS"
 
     # note pre update file checksum
-    fileCheck="$(cat "$KNOWN_HOSTS" | md5sum)"
+    fileCheck="$(file_hash "$KNOWN_HOSTS")"
 
     for host ; do
        # process the host
@@ -596,7 +601,7 @@ update_known_hosts() {
     lockfile-remove "$KNOWN_HOSTS"
 
     # note if the known_hosts file was updated
-    if [ "$(cat "$KNOWN_HOSTS" | md5sum)" != "$fileCheck" ] ; then
+    if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
        log "known_hosts file updated."
     fi
 
@@ -711,7 +716,7 @@ update_authorized_keys() {
     lockfile-create "$AUTHORIZED_KEYS"
 
     # note pre update file checksum
-    fileCheck="$(cat "$AUTHORIZED_KEYS" | md5sum)"
+    fileCheck="$(file_hash "$AUTHORIZED_KEYS")"
 
     # remove any monkeysphere lines from authorized_keys file
     remove_monkeysphere_lines "$AUTHORIZED_KEYS"
@@ -739,7 +744,7 @@ update_authorized_keys() {
     lockfile-remove "$AUTHORIZED_KEYS"
 
     # note if the authorized_keys file was updated
-    if [ "$(cat "$AUTHORIZED_KEYS" | md5sum)" != "$fileCheck" ] ; then
+    if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then
        log "authorized_keys file updated."
     fi