kickstart-static64.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0+
  3. umask 022
  4. # ---------------------------------------------------------------------------------------------------------------------
  5. # library functions copied from installer/functions.sh
  6. which_cmd() {
  7. which "${1}" 2>/dev/null || \
  8. command -v "${1}" 2>/dev/null
  9. }
  10. check_cmd() {
  11. which_cmd "${1}" >/dev/null 2>&1 && return 0
  12. return 1
  13. }
  14. setup_terminal() {
  15. TPUT_RESET=""
  16. TPUT_BLACK=""
  17. TPUT_RED=""
  18. TPUT_GREEN=""
  19. TPUT_YELLOW=""
  20. TPUT_BLUE=""
  21. TPUT_PURPLE=""
  22. TPUT_CYAN=""
  23. TPUT_WHITE=""
  24. TPUT_BGBLACK=""
  25. TPUT_BGRED=""
  26. TPUT_BGGREEN=""
  27. TPUT_BGYELLOW=""
  28. TPUT_BGBLUE=""
  29. TPUT_BGPURPLE=""
  30. TPUT_BGCYAN=""
  31. TPUT_BGWHITE=""
  32. TPUT_BOLD=""
  33. TPUT_DIM=""
  34. TPUT_UNDERLINED=""
  35. TPUT_BLINK=""
  36. TPUT_INVERTED=""
  37. TPUT_STANDOUT=""
  38. TPUT_BELL=""
  39. TPUT_CLEAR=""
  40. # Is stderr on the terminal? If not, then fail
  41. test -t 2 || return 1
  42. if check_cmd tput
  43. then
  44. if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
  45. then
  46. # Enable colors
  47. TPUT_RESET="$(tput sgr 0)"
  48. TPUT_BLACK="$(tput setaf 0)"
  49. TPUT_RED="$(tput setaf 1)"
  50. TPUT_GREEN="$(tput setaf 2)"
  51. TPUT_YELLOW="$(tput setaf 3)"
  52. TPUT_BLUE="$(tput setaf 4)"
  53. TPUT_PURPLE="$(tput setaf 5)"
  54. TPUT_CYAN="$(tput setaf 6)"
  55. TPUT_WHITE="$(tput setaf 7)"
  56. TPUT_BGBLACK="$(tput setab 0)"
  57. TPUT_BGRED="$(tput setab 1)"
  58. TPUT_BGGREEN="$(tput setab 2)"
  59. TPUT_BGYELLOW="$(tput setab 3)"
  60. TPUT_BGBLUE="$(tput setab 4)"
  61. TPUT_BGPURPLE="$(tput setab 5)"
  62. TPUT_BGCYAN="$(tput setab 6)"
  63. TPUT_BGWHITE="$(tput setab 7)"
  64. TPUT_BOLD="$(tput bold)"
  65. TPUT_DIM="$(tput dim)"
  66. TPUT_UNDERLINED="$(tput smul)"
  67. TPUT_BLINK="$(tput blink)"
  68. TPUT_INVERTED="$(tput rev)"
  69. TPUT_STANDOUT="$(tput smso)"
  70. TPUT_BELL="$(tput bel)"
  71. TPUT_CLEAR="$(tput clear)"
  72. fi
  73. fi
  74. return 0
  75. }
  76. setup_terminal || echo >/dev/null
  77. progress() {
  78. echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
  79. }
  80. run_ok() {
  81. printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
  82. }
  83. run_failed() {
  84. printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
  85. }
  86. ESCAPED_PRINT_METHOD=
  87. printf "%q " test >/dev/null 2>&1
  88. [ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
  89. escaped_print() {
  90. if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]
  91. then
  92. printf "%q " "${@}"
  93. else
  94. printf "%s" "${*}"
  95. fi
  96. return 0
  97. }
  98. run_logfile="/dev/null"
  99. run() {
  100. local user="${USER--}" dir="${PWD}" info info_console
  101. if [ "${UID}" = "0" ]
  102. then
  103. info="[root ${dir}]# "
  104. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
  105. else
  106. info="[${user} ${dir}]$ "
  107. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
  108. fi
  109. printf >> "${run_logfile}" "${info}"
  110. escaped_print >> "${run_logfile}" "${@}"
  111. printf >> "${run_logfile}" " ... "
  112. printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
  113. escaped_print >&2 "${@}"
  114. printf >&2 "${TPUT_RESET}\n"
  115. "${@}"
  116. local ret=$?
  117. if [ ${ret} -ne 0 ]
  118. then
  119. run_failed
  120. printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
  121. else
  122. run_ok
  123. printf >> "${run_logfile}" "OK\n"
  124. fi
  125. return ${ret}
  126. }
  127. # ---------------------------------------------------------------------------------------------------------------------
  128. fatal() {
  129. printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
  130. exit 1
  131. }
  132. # ---------------------------------------------------------------------------------------------------------------------
  133. if [ "$(uname -m)" != "x86_64" ]
  134. then
  135. fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
  136. fi
  137. if [ "$(uname -s)" != "Linux" ]
  138. then
  139. fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
  140. fi
  141. curl="$(which_cmd curl)"
  142. wget="$(which_cmd wget)"
  143. # ---------------------------------------------------------------------------------------------------------------------
  144. progress "Checking the latest version of static build..."
  145. BASE='https://raw.githubusercontent.com/firehol/binary-packages/master'
  146. LATEST=
  147. if [ ! -z "${curl}" -a -x "${curl}" ]
  148. then
  149. LATEST="$(run ${curl} "${BASE}/netdata-latest.gz.run")"
  150. elif [ ! -z "${wget}" -a -x "${wget}" ]
  151. then
  152. LATEST="$(run ${wget} -O - "${BASE}/netdata-latest.gz.run")"
  153. else
  154. fatal "curl or wget are needed for this script to work."
  155. fi
  156. if [ -z "${LATEST}" ]
  157. then
  158. fatal "Cannot find the latest static binary version of netdata."
  159. fi
  160. # ---------------------------------------------------------------------------------------------------------------------
  161. progress "Downloading static netdata binary: ${LATEST}"
  162. ret=1
  163. if [ ! -z "${curl}" -a -x "${curl}" ]
  164. then
  165. run ${curl} "${BASE}/${LATEST}" >"/tmp/${LATEST}"
  166. ret=$?
  167. elif [ ! -z "${wget}" -a -x "${wget}" ]
  168. then
  169. run ${wget} -O "/tmp/${LATEST}" "${BASE}/${LATEST}"
  170. ret=$?
  171. else
  172. fatal "curl or wget are needed for this script to work."
  173. fi
  174. if [ ${ret} -ne 0 -o ! -s "/tmp/${LATEST}" ]
  175. then
  176. fatal "Failed to download the latest static binary version of netdata."
  177. fi
  178. # ---------------------------------------------------------------------------------------------------------------------
  179. opts=
  180. inner_opts=
  181. while [ ! -z "${1}" ]
  182. do
  183. if [ "${1}" = "--dont-wait" -o "${1}" = "--non-interactive" -o "${1}" = "--accept" ]
  184. then
  185. opts="${opts} --accept"
  186. elif [ "${1}" = "--dont-start-it" ]
  187. then
  188. inner_opts="${inner_opts} ${1}"
  189. else
  190. echo >&2 "Unknown option '${1}'"
  191. exit 1
  192. fi
  193. shift
  194. done
  195. [ ! -z "${inner_opts}" ] && inner_opts="-- ${inner_opts}"
  196. # ---------------------------------------------------------------------------------------------------------------------
  197. progress "Installing netdata"
  198. sudo=
  199. [ "${UID}" != "0" ] && sudo="sudo"
  200. run ${sudo} sh "/tmp/${LATEST}" ${opts} ${inner_opts}
  201. if [ $? -eq 0 ]
  202. then
  203. rm "/tmp/${LATEST}"
  204. else
  205. echo >&2 "NOTE: did not remove: /tmp/${LATEST}"
  206. fi