kickstart-static64.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # shellcheck disable=SC1117,SC2039,SC2059,SC2086
  4. # External files
  5. NIGHTLY_PACKAGE_TARBALL="https://storage.googleapis.com/netdata-nightlies/netdata-latest.gz.run"
  6. NIGHTLY_PACKAGE_CHECKSUM="https://storage.googleapis.com/netdata-nightlies/sha256sums.txt"
  7. # ---------------------------------------------------------------------------------------------------------------------
  8. # library functions copied from packaging/installer/functions.sh
  9. setup_terminal() {
  10. TPUT_RESET=""
  11. TPUT_YELLOW=""
  12. TPUT_WHITE=""
  13. TPUT_BGRED=""
  14. TPUT_BGGREEN=""
  15. TPUT_BOLD=""
  16. TPUT_DIM=""
  17. # Is stderr on the terminal? If not, then fail
  18. test -t 2 || return 1
  19. if command -v tput >/dev/null 2>&1; then
  20. if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
  21. # Enable colors
  22. TPUT_RESET="$(tput sgr 0)"
  23. TPUT_YELLOW="$(tput setaf 3)"
  24. TPUT_WHITE="$(tput setaf 7)"
  25. TPUT_BGRED="$(tput setab 1)"
  26. TPUT_BGGREEN="$(tput setab 2)"
  27. TPUT_BOLD="$(tput bold)"
  28. TPUT_DIM="$(tput dim)"
  29. fi
  30. fi
  31. return 0
  32. }
  33. progress() {
  34. echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
  35. }
  36. escaped_print() {
  37. if printf "%q " test >/dev/null 2>&1; then
  38. printf "%q " "${@}"
  39. else
  40. printf "%s" "${*}"
  41. fi
  42. return 0
  43. }
  44. run() {
  45. local dir="${PWD}" info_console
  46. if [ "${UID}" = "0" ]; then
  47. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
  48. else
  49. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
  50. fi
  51. escaped_print "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" "${@}" "${TPUT_RESET}\n" >&2
  52. "${@}"
  53. local ret=$?
  54. if [ ${ret} -ne 0 ]; then
  55. printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
  56. else
  57. printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
  58. fi
  59. return ${ret}
  60. }
  61. # ---------------------------------------------------------------------------------------------------------------------
  62. fatal() {
  63. printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
  64. exit 1
  65. }
  66. download() {
  67. url="${1}"
  68. dest="${2}"
  69. if command -v curl >/dev/null 2>&1; then
  70. run curl -L --connect-timeout 5 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}"
  71. elif command -v wget >/dev/null 2>&1; then
  72. run wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
  73. else
  74. fatal "I need curl or wget to proceed, but neither is available on this system."
  75. fi
  76. }
  77. umask 022
  78. sudo=""
  79. [ -z "${UID}" ] && UID="$(id -u)"
  80. [ "${UID}" -ne "0" ] && sudo="sudo"
  81. setup_terminal || echo >/dev/null
  82. # ---------------------------------------------------------------------------------------------------------------------
  83. if [ "$(uname -m)" != "x86_64" ]; then
  84. fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
  85. fi
  86. if [ "$(uname -s)" != "Linux" ]; then
  87. fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
  88. fi
  89. # ---------------------------------------------------------------------------------------------------------------------
  90. # Check if tmp is mounted as noexec
  91. if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then
  92. pattern="$(pwd)/netdata-kickstart-static-XXXXXX"
  93. else
  94. pattern="/tmp/netdata-kickstart-static-XXXXXX"
  95. fi
  96. tmpdir="$(mktemp -d $pattern)"
  97. cd "${tmpdir}" || :
  98. progress "Downloading static netdata binary: ${NIGHTLY_PACKAGE_TARBALL}"
  99. download "${NIGHTLY_PACKAGE_CHECKSUM}" "${tmpdir}/sha256sum.txt"
  100. download "${NIGHTLY_PACKAGE_TARBALL}" "${tmpdir}/netdata-latest.gz.run"
  101. if ! grep netdata-latest.gz.run sha256sum.txt | sha256sum --check - >/dev/null 2>&1; then
  102. failed "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${tmpdir}"
  103. fi
  104. # ---------------------------------------------------------------------------------------------------------------------
  105. opts=
  106. inner_opts=
  107. while [ ! -z "${1}" ]; do
  108. if [ "${1}" = "--dont-wait" ] || [ "${1}" = "--non-interactive" ] || [ "${1}" = "--accept" ]; then
  109. opts="${opts} --accept"
  110. elif [ "${1}" = "--dont-start-it" ]; then
  111. inner_opts="${inner_opts} ${1}"
  112. else
  113. echo >&2 "Unknown option '${1}'"
  114. exit 1
  115. fi
  116. shift
  117. done
  118. [ ! -z "${inner_opts}" ] && inner_opts="-- ${inner_opts}"
  119. # ---------------------------------------------------------------------------------------------------------------------
  120. progress "Installing netdata"
  121. run ${sudo} sh "${tmpdir}/netdata-latest.gz.run" ${opts} ${inner_opts}
  122. #shellcheck disable=SC2181
  123. if [ $? -eq 0 ]; then
  124. rm "${tmpdir}/netdata-latest.gz.run"
  125. else
  126. echo >&2 "NOTE: did not remove: ${tmpdir}/netdata-latest.gz.run"
  127. fi