netdata-installer.sh follow-up based on #7060 review (#7200)
* netdata-installer.sh: Improve message about updater installation * packaging/installer/functions.sh: get_crondir() fails if crondir is not found * packaging/installer/functions.sh: Mark get_crondir and check_crondir_permissions functions as private
Konstantinos Natsakis committed
Nov 6, 2019 at 12:50 UTC
e3b4a62c1e08ec07a42fb2c780230a0fe7d4537b
2 files changed
+19
-17
netdata-installer.sh
+1
-1
@@ -1051,7 +1051,7 @@ echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/u
1051
echo >&2
1052
1053
# -----------------------------------------------------------------------------
1054
-progress "Install (but not enable) netdata updater tool"
1054
+progress "Installing (but not enabling) the netdata updater tool"
1055
cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool."
1056
install_netdata_updater || run_failed "Cannot install netdata updater tool."
1057
packaging/installer/functions.sh
+18
-16
@@ -728,19 +728,21 @@ safe_sha256sum() {
728
fi
729
}
730
731
-get_crondir() {
732
- crondir=
733
- [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
734
- [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
731
+_get_crondir() {
732
+ if [ -d /etc/cron.daily ]; then
733
+ echo /etc/cron.daily
734
+ elif [ -d /etc/periodic/daily ]; then
735
+ echo /etc/periodic/daily
736
+ else
737
+ echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
738
+ return 1
739
+ fi
740
736
- echo "${crondir}"
741
+ return 0
742
}
743
739
-check_crondir_permissions() {
740
- if [ -z "${1}" ]; then
741
- echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
742
- return 1
743
- elif [ "${UID}" -ne "0" ]; then
744
+_check_crondir_permissions() {
745
+ if [ "${UID}" -ne "0" ]; then
746
# We cant touch cron if we are not running as root
747
echo >&2 "You need to run the installer as root for auto-updating via cron"
748
return 1
@@ -773,8 +775,8 @@ cleanup_old_netdata_updater() {
775
rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh
776
fi
777
776
- crondir="$(get_crondir)"
777
- check_crondir_permissions "${crondir}" || return 1
778
+ crondir="$(_get_crondir)" || return 1
779
+ _check_crondir_permissions "${crondir}" || return 1
780
781
if [ -f "${crondir}/netdata-updater.sh" ]; then
782
echo >&2 "Removing incorrect netdata-updater filename in cron"
@@ -785,8 +787,8 @@ cleanup_old_netdata_updater() {
787
}
788
789
enable_netdata_updater() {
788
- crondir="$(get_crondir)"
789
- check_crondir_permissions "${crondir}" || return 1
790
+ crondir="$(_get_crondir)" || return 1
791
+ _check_crondir_permissions "${crondir}" || return 1
792
793
echo >&2 "Adding to cron"
794
@@ -803,8 +805,8 @@ enable_netdata_updater() {
805
}
806
807
disable_netdata_updater() {
806
- crondir="$(get_crondir)"
807
- check_crondir_permissions "${crondir}" || return 1
808
+ crondir="$(_get_crondir)" || return 1
809
+ _check_crondir_permissions "${crondir}" || return 1
810
811
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)"
812
echo >&2