kickstart-static64.sh 5.3 KB

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