Decouple the instal detection code from the handling code for existing installs. (#12110)
This will allow easy reuse in the future for things like the upcoming `--uninstall` option.
Austin S. Hemmelgarn committed
Feb 11, 2022 at 07:54 UTC
3377936f4d236f4d6b070c06a902bab97b7accca
2 files changed
+19
-12
packaging/installer/kickstart.sh
+18
-11
@@ -525,9 +525,11 @@ update() {
525
fi
526
}
527
528
-handle_existing_install() {
528
+detect_existing_install() {
529
if pkg_installed netdata; then
530
ndprefix="/"
531
+ elif [ -n "${INSTALL_PREFIX}" ]; then
532
+ ndprefix="${INSTALL_PREFIX}"
533
else
534
if [ -n "${INSTALL_PREFIX}" ]; then
535
searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
@@ -562,7 +564,13 @@ handle_existing_install() {
564
fi
565
fi
566
565
- if [ -z "${ndprefix}" ]; then
567
+ INSTALL_PREFIX="${ndprefix}"
568
+}
569
+
570
+handle_existing_install() {
571
+ detect_existing_install
572
+
573
+ if [ -z "${INSTALL_PREFIX}" ] || [ -z "${INSTALL_TYPE}" ]; then
574
progress "No existing installations of netdata found, assuming this is a fresh install."
575
return 0
576
fi
@@ -570,13 +578,13 @@ handle_existing_install() {
578
case "${INSTALL_TYPE}" in
579
kickstart-*|legacy-*|binpkg-*|manual-static|unknown)
580
if [ "${INSTALL_TYPE}" = "unknown" ]; then
573
- warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type."
581
+ warning "Found an existing netdata install at ${INSTALL_PREFIX}, but could not determine the install type."
582
else
575
- progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'."
583
+ progress "Found an existing netdata install at ${INSTALL_PREFIX}, with installation type '${INSTALL_TYPE}'."
584
fi
585
586
if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
579
- progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
587
+ progress "Found an existing netdata install at ${INSTALL_PREFIX}, but user requested reinstall, continuing."
588
589
case "${INSTALL_TYPE}" in
590
binpkg-*) NETDATA_ONLY_NATIVE=1 ;;
@@ -604,21 +612,20 @@ handle_existing_install() {
612
613
if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then
614
if ! update; then
607
- warning "Unable to find usable updater script, not updating existing install at ${ndprefix}."
615
+ warning "Unable to find usable updater script, not updating existing install at ${INSTALL_PREFIX}."
616
fi
617
else
610
- warning "Not updating existing install at ${ndprefix}."
618
+ warning "Not updating existing install at ${INSTALL_PREFIX}."
619
fi
620
621
if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
614
- progress "Attempting to claim existing install at ${ndprefix}."
615
- INSTALL_PREFIX="${ndprefix}"
622
+ progress "Attempting to claim existing install at ${INSTALL_PREFIX}."
623
claim
624
ret=$?
625
elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then
626
fatal "User asked to claim, but did not proide a claiming token." F0202
627
else
621
- progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)."
628
+ progress "Not attempting to claim existing install at ${INSTALL_PREFIX} (no claiming token provided)."
629
fi
630
631
cleanup
@@ -642,7 +649,7 @@ handle_existing_install() {
649
fi
650
fi
651
else
645
- fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103
652
+ fatal "Found an existing netdata install at ${INSTALL_PREFIX}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103
653
fi
654
;;
655
esac
packaging/installer/methods/kickstart.md
+1
-1
@@ -136,7 +136,7 @@ To use `md5sum` to verify the integrity of the `kickstart.sh` script you will do
136
run the following:
137
138
```bash
139
-[ "22039cdffef3eef21238c26605085ede" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
139
+[ "2ea326514c5166eabf02622e75d10a53" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
140
```
141
142
If the script is valid, this command will return `OK, VALID`.