@cryptotaxi247 / netdata-1 / commits / 03b5b94b4

dont use BASH 4 features when BASH 4+ is not available #733; fallback to systemctl if service is not available - fixes start/restart on Arch Linux

Costa Tsaousis committed Jul 31, 2016 at 02:41 UTC 03b5b94b44f5bf81d1d5120686d0bd24e6d91432
1 file changed +41 -15
netdata-installer.sh
+41 -15
@@ -23,6 +23,23 @@ printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
23 printf "%q " "$0" "${@}" >>netdata-installer.log
24 printf "\n" >>netdata-installer.log
25
26 +service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
27 +systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
28 +service() {
29 + local cmd="${1}" action="${2}"
30 +
31 + if [ ! -z "${service}" ]
32 + then
33 + run "${service}" "${cmd}" "${action}"
34 + return $?
35 + elif [ ! -z "${systemctl}" ]
36 + then
37 + run "${systemctl}" "${action}" "${cmd}"
38 + return $?
39 + fi
40 + return 1
41 +}
42 +
43 ME="$0"
44 DONOTSTART=0
45 DONOTWAIT=0
@@ -382,10 +399,13 @@ fi
399 echo >&2 "Compiling netdata ..."
400 run make || exit 1
401
385 -declare -A configs_signatures=()
386 -if [ -f "configs.signatures" ]
387 - then
388 - source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
402 +if [ "${BASH_VERSINFO[0]}" -ge "4" ]
403 +then
404 + declare -A configs_signatures=()
405 + if [ -f "configs.signatures" ]
406 + then
407 + source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
408 + fi
409 fi
410
411 # migrate existing configuration files
@@ -393,7 +413,7 @@ fi
413 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
414 then
415 # the configuration directory exists
396 -
416 +
417 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
418 then
419 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
@@ -455,13 +475,19 @@ do
475 cp "conf.d/${f}" "${x}.orig"
476 fi
477
458 - if [ "${configs_signatures[${md5}]}" = "${f}" ]
478 + if [ "${BASH_VERSINFO[0]}" -ge "4" ]
479 + then
480 + if [ "${configs_signatures[${md5}]}" = "${f}" ]
481 then
460 - # it is a stock version - don't keep it
461 - echo >&2 "File '${x}' is stock version."
482 + # it is a stock version - don't keep it
483 + echo >&2 "File '${x}' is stock version."
484 + else
485 + # edited by user - keep it
486 + echo >&2 "File '${x}' has been edited by user."
487 + cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
488 + fi
489 else
463 - # edited by user - keep it
464 - echo >&2 "File '${x}' has been edited by user."
490 + echo >&2 "File '${x}' cannot be check for custom edits."
491 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
492 fi
493 fi
@@ -734,22 +760,22 @@ if [ "${UID}" -eq 0 ]
760 run systemctl daemon-reload && \
761 run systemctl enable netdata
762 else
737 - run service netdata stop
763 + service netdata stop
764 fi
765
766 stop_all_netdata
741 - run service netdata restart && started=1
767 + service netdata restart && started=1
768 fi
769
770 if [ ${started} -eq 0 ]
771 then
772 # check if we can use the system service
747 - run service netdata stop
773 + service netdata stop
774 stop_all_netdata
749 - run service netdata restart && started=1
775 + service netdata restart && started=1
776 if [ ${started} -eq 0 ]
777 then
752 - run service netdata start && started=1
778 + service netdata start && started=1
779 fi
780 fi
781 fi