allow the installer to check configs signatures when the BASH is older than v4
Costa Tsaousis (ktsaou) committed
Mar 15, 2017 at 02:21 UTC
963bfdb2067243dbb36a91720b06e809ce784d39
1 file changed
+23
-11
netdata-installer.sh
+23
-11
@@ -507,6 +507,24 @@ then
507
fi
508
fi
509
510
+config_signature_matches() {
511
+ local md5="${1}" file="${2}"
512
+
513
+ if [ "${BASH_VERSINFO[0]}" -ge "4" ]
514
+ then
515
+ [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
516
+ return 1
517
+ fi
518
+
519
+ if [ -f "configs.signatures" ]
520
+ then
521
+ grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
522
+ return $?
523
+ fi
524
+
525
+ return 1
526
+}
527
+
528
# backup user configurations
529
installer_backup_suffix="${PID}.${RANDOM}"
530
for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
@@ -534,19 +552,13 @@ do
552
cp "conf.d/${f}" "${x}.orig"
553
fi
554
537
- if [ "${BASH_VERSINFO[0]}" -ge "4" ]
538
- then
539
- if [ "${configs_signatures[${md5}]}" = "${f}" ]
555
+ if config_signature_matches "${md5}" "${f}"
556
then
541
- # it is a stock version - don't keep it
542
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
543
- else
544
- # edited by user - keep it
545
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
546
- run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
547
- fi
557
+ # it is a stock version - don't keep it
558
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
559
else
549
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
560
+ # edited by user - keep it
561
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
562
run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
563
fi
564
fi