Add detailed reporting of failed checksums in kickstart script. (#18265)
* Add detailed reporting of failed checksums in kickstart script. * Fix output.
Austin S. Hemmelgarn committed
Aug 8, 2024 at 07:24 UTC
6089849cf6ce909a73a78c39819bbe648e18de11
1 file changed
+26
-7
packaging/installer/kickstart.sh
+26
-7
@@ -455,7 +455,7 @@ deferred_warnings() {
455
456
fatal() {
457
deferred_warnings
458
- printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}"
458
+ printf >&2 "%b\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}"
459
printf >&2 "%s\n" "For community support, you can connect with us on:"
460
support_list
461
telemetry_event "INSTALL_FAILED" "${1}" "${2}"
@@ -743,8 +743,6 @@ get_redirect() {
743
}
744
745
safe_sha256sum() {
746
- # Within the context of the installer, we only use -c option that is common between the two commands
747
- # We will have to reconsider if we start using non-common options
746
if command -v shasum > /dev/null 2>&1; then
747
shasum -a 256 "$@"
748
elif command -v sha256sum > /dev/null 2>&1; then
@@ -754,6 +752,17 @@ safe_sha256sum() {
752
fi
753
}
754
755
+report_bad_sha256sum() {
756
+ file="${1}"
757
+ sums="${2}"
758
+
759
+ actual="$(safe_sha256sum "${file}" | awk '{ print $1 }')"
760
+ expected="$(grep "${file}" "${sums}" | awk '{ print $1 }')"
761
+
762
+ printf "Expected: %s\n" "${expected}"
763
+ printf "Actual: %s\n" "${actual}"
764
+}
765
+
766
get_system_info() {
767
SYSARCH="$(uname -m)"
768
@@ -1809,7 +1818,8 @@ try_static_install() {
1818
else
1819
if [ -z "${INSTALL_VERSION}" ]; then
1820
if ! grep "${netdata_agent}" ./sha256sum.txt | safe_sha256sum -c - > /dev/null 2>&1; then
1812
- fatal "Static binary checksum validation failed. ${BADCACHE_MSG}." F0207
1821
+ bad_sums_report="$(report_bad_sha256sum "${netdata_agent}" "./sha256sum.txt")"
1822
+ fatal "Static binary checksum validation failed.\n${bad_sums_report}\n${BADCACHE_MSG}." F0207
1823
fi
1824
fi
1825
fi
@@ -1984,7 +1994,8 @@ try_build_install() {
1994
if [ -z "${INSTALL_VERSION}" ]; then
1995
# shellcheck disable=SC2086
1996
if ! grep netdata-latest.tar.gz "./sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
1987
- fatal "Tarball checksum validation failed. ${BADCACHE_MSG}." F0005
1997
+ bad_sums_report="$(report_bad_sha256sum netdata-latest.tar.gz "./sha256sum.txt")"
1998
+ fatal "Tarball checksum validation failed.\n${bad_sums_report}\n${BADCACHE_MSG}." F0005
1999
fi
2000
fi
2001
fi
@@ -2077,8 +2088,16 @@ prepare_offline_install_source() {
2088
2089
if [ "${DRY_RUN}" -ne 1 ]; then
2090
progress "Verifying checksums."
2080
- if ! grep -e "$(find . -name '*.gz.run')" sha256sums.txt | safe_sha256sum -c -; then
2081
- fatal "Checksums for offline install files are incorrect. ${BADCACHE_MSG}." F0507
2091
+
2092
+ failed_files=""
2093
+ for file in $(find . -name '*.gz.run'); do
2094
+ if ! grep -e "${file}" sha256sums.txt | safe_sha256sum -c -; then
2095
+ failed_files="${failed_files}\n${file}\n$(report_bad_sha256sums "${file}" sha256sums.txt)"
2096
+ fi
2097
+ done
2098
+
2099
+ if [ -n "${failed_files}" ]; then
2100
+ fatal "Checksums for offline install files are incorrect.\n${failed_files}\n${BADCACHE_MSG}." F0507
2101
fi
2102
else
2103
progress "Would verify SHA256 checksums of downloaded installation files."