]> arthur.barton.de Git - netdata.git/commitdiff
allow the installer to check configs signatures when the BASH is older than v4
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 15 Mar 2017 00:21:50 +0000 (02:21 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 15 Mar 2017 00:21:50 +0000 (02:21 +0200)
netdata-installer.sh

index c49ef32ceb2d14dbc2f4b486351e4db00b7c871c..d11e96236c8fc1db0bb9b74217ec4b730ec30685 100755 (executable)
@@ -507,6 +507,24 @@ then
     fi
 fi
 
     fi
 fi
 
+config_signature_matches() {
+    local md5="${1}" file="${2}"
+
+    if [ "${BASH_VERSINFO[0]}" -ge "4" ]
+        then
+        [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
+        return 1
+    fi
+
+    if [ -f "configs.signatures" ]
+        then
+        grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
+        return $?
+    fi
+
+    return 1
+}
+
 # backup user configurations
 installer_backup_suffix="${PID}.${RANDOM}"
 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
 # backup user configurations
 installer_backup_suffix="${PID}.${RANDOM}"
 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
@@ -534,19 +552,13 @@ do
                 cp "conf.d/${f}" "${x}.orig"
             fi
 
                 cp "conf.d/${f}" "${x}.orig"
             fi
 
-            if [ "${BASH_VERSINFO[0]}" -ge "4" ]
-            then
-                if [ "${configs_signatures[${md5}]}" = "${f}" ]
+            if config_signature_matches "${md5}" "${f}"
                 then
                 then
-                    # it is a stock version - don't keep it
-                    echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
-                else
-                    # edited by user - keep it
-                    echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
-                    run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
-                fi
+                # it is a stock version - don't keep it
+                echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
             else
             else
-                echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
+                # edited by user - keep it
+                echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
                 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
             fi
         fi
                 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
             fi
         fi