@cryptotaxi247 / netdata-1 / commits / e1d0b5a27

netdata/packaging: Adjust auto-updater installation logic (#6035)

* netdata/packaging: Adjust auto-updater installation logic 1) Always install updater script under libexec, together with the uninstall script 2) When the user asks for auto-update, then just link the script to the cron directory 3) When the user hasnt asked for auto-update, make sure the cron link is removed Added extra info along all those lines. There was also an algorithmic cleanup, in the way we do the checks so things are clearer Note: When user hasnt provided auto-update flag, means he doesnt want auto-update so we remove it. The automatic run of the updater knows it has to use the flag (its saved in .environment), so we wont face problems there * netdata/packaging: Fix naming, bash extension can be set on install destination and only omit on the symlink

Paul Emm. Katsoulakis committed May 17, 2019 at 16:48 UTC e1d0b5a27160d17518c52a839118b5294795cc9b
1 file changed +46 -27
netdata-installer.sh
+46 -27
@@ -958,39 +958,58 @@ To start netdata run:
958
959 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
960
961 -
961 END
962 echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh${TPUT_RESET}"
963 +echo >&2
964
965 -if [ "${AUTOUPDATE}" = "1" ]; then
966 - if [ "${UID}" -ne "0" ]; then
967 - echo >&2 "You need to run the installer as root for auto-updating via cron."
968 - else
969 - crondir=
970 - [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
971 - [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
965 +progress "Install netdata updater tool"
966
973 - if [ -z "${crondir}" ]; then
974 - echo >&2 "Cannot figure out the cron directory to install netdata-updater"
975 - else
976 - if [ -f "${crondir}/netdata-updater.sh" ]; then
977 - progress "Removing incorrect netdata-updater filename in cron"
978 - rm -f "${crondir}/netdata-updater.sh"
979 - fi
980 - progress "Installing new netdata-updater in cron"
967 +if [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
968 + sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" || exit 1
969 +else
970 + sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" || exit 1
971 +fi
972
982 - rm -f "${crondir}/netdata-updater"
983 - if [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
984 - sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
985 - else
986 - sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
987 - fi
973 +chmod 0755 ${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh
974 +echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh${TPUT_RESET}"
975 +echo >&2
976
989 - chmod 0755 ${crondir}/netdata-updater
990 - echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${crondir}/netdata-updater${TPUT_RESET}"
991 - echo >&2
992 - echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
993 - echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
977 +# Figure out the cron directory for the distro
978 +crondir=
979 +[ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
980 +[ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
981 +
982 +if [ -z "${crondir}" ]; then
983 + echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
984 +elif [ "${UID}" -ne "0" ]; then
985 + # We cant touch cron if we are not running as root
986 + echo >&2 "You need to run the installer as root for auto-updating via cron."
987 +else
988 + progress "Check if we must enable/disable the netdata updater"
989 + if [ "${AUTOUPDATE}" = "1" ]; then
990 + if [ -f "${crondir}/netdata-updater.sh" ]; then
991 + progress "Removing incorrect netdata-updater filename in cron"
992 + rm -f "${crondir}/netdata-updater.sh"
993 + fi
994 +
995 + echo >&2 "Adding to cron"
996 +
997 + rm -f "${crondir}/netdata-updater"
998 + ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" "${crondir}/netdata-updater"
999 +
1000 + echo >&2 "Auto-updating has been enabled. Updater script linked to: ${TPUT_RED}${TPUT_BOLD}${crondir}/netdata-update${TPUT_RESET}"
1001 + echo >&2
1002 + echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
1003 + echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
1004 + else
1005 + echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
1006 + echo >&2
1007 +
1008 + if [ -f "${crondir}/netdata-updater" ]; then
1009 + echo >&2 "Removing cron reference: ${crondir}/netdata-updater"
1010 + rm -f "${crondir}/netdata-updater"
1011 + else
1012 + echo >&2 "Did not find any cron entries to remove"
1013 fi
1014 fi
1015 fi