summaryrefslogtreecommitdiffstats
path: root/kickstart-static64.sh
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-05-28 00:30:51 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-05-28 00:30:51 +0300
commit103997178bdcff19430b629b0448e4965d16aa14 (patch)
treeca424dfd11afd65e7c5b79afe933d3814a9b6558 /kickstart-static64.sh
parentbc84f865275d056861bc657b682eea9bc3dbb45c (diff)
minor improvements to installation scripts
Diffstat (limited to 'kickstart-static64.sh')
-rwxr-xr-xkickstart-static64.sh168
1 files changed, 153 insertions, 15 deletions
diff --git a/kickstart-static64.sh b/kickstart-static64.sh
index 981c261286..3da2530aed 100755
--- a/kickstart-static64.sh
+++ b/kickstart-static64.sh
@@ -1,45 +1,183 @@
#!/usr/bin/env sh
+umask 022
+
+# ---------------------------------------------------------------------------------------------------------------------
+# library functions copied from installer/functions.sh
+
+which_cmd() {
+ which "${1}" 2>/dev/null || \
+ command -v "${1}" 2>/dev/null
+}
+
+check_cmd() {
+ which_cmd "${1}" >/dev/null 2>&1 && return 0
+ return 1
+}
+
+setup_terminal() {
+ TPUT_RESET=""
+ TPUT_BLACK=""
+ TPUT_RED=""
+ TPUT_GREEN=""
+ TPUT_YELLOW=""
+ TPUT_BLUE=""
+ TPUT_PURPLE=""
+ TPUT_CYAN=""
+ TPUT_WHITE=""
+ TPUT_BGBLACK=""
+ TPUT_BGRED=""
+ TPUT_BGGREEN=""
+ TPUT_BGYELLOW=""
+ TPUT_BGBLUE=""
+ TPUT_BGPURPLE=""
+ TPUT_BGCYAN=""
+ TPUT_BGWHITE=""
+ TPUT_BOLD=""
+ TPUT_DIM=""
+ TPUT_UNDERLINED=""
+ TPUT_BLINK=""
+ TPUT_INVERTED=""
+ TPUT_STANDOUT=""
+ TPUT_BELL=""
+ TPUT_CLEAR=""
+
+ # Is stderr on the terminal? If not, then fail
+ test -t 2 || return 1
+
+ if check_cmd tput
+ then
+ if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
+ then
+ # Enable colors
+ TPUT_RESET="$(tput sgr 0)"
+ TPUT_BLACK="$(tput setaf 0)"
+ TPUT_RED="$(tput setaf 1)"
+ TPUT_GREEN="$(tput setaf 2)"
+ TPUT_YELLOW="$(tput setaf 3)"
+ TPUT_BLUE="$(tput setaf 4)"
+ TPUT_PURPLE="$(tput setaf 5)"
+ TPUT_CYAN="$(tput setaf 6)"
+ TPUT_WHITE="$(tput setaf 7)"
+ TPUT_BGBLACK="$(tput setab 0)"
+ TPUT_BGRED="$(tput setab 1)"
+ TPUT_BGGREEN="$(tput setab 2)"
+ TPUT_BGYELLOW="$(tput setab 3)"
+ TPUT_BGBLUE="$(tput setab 4)"
+ TPUT_BGPURPLE="$(tput setab 5)"
+ TPUT_BGCYAN="$(tput setab 6)"
+ TPUT_BGWHITE="$(tput setab 7)"
+ TPUT_BOLD="$(tput bold)"
+ TPUT_DIM="$(tput dim)"
+ TPUT_UNDERLINED="$(tput smul)"
+ TPUT_BLINK="$(tput blink)"
+ TPUT_INVERTED="$(tput rev)"
+ TPUT_STANDOUT="$(tput smso)"
+ TPUT_BELL="$(tput bel)"
+ TPUT_CLEAR="$(tput clear)"
+ fi
+ fi
+
+ return 0
+}
+setup_terminal || echo >/dev/null
+
+progress() {
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
+}
+
+run_ok() {
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
+}
+
+run_failed() {
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
+}
+
+run_logfile="/dev/null"
+run() {
+ local user="${USER:-}" dir="${PWD}" info info_console
+
+ if [ "${UID}" = "0" ]
+ then
+ info="[root ${dir}]# "
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
+ else
+ info="[${user} ${dir}]$ "
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
+ fi
+
+ printf >> "${run_logfile}" "${info}"
+ printf >> "${run_logfile}" "%q " "${@}"
+ printf >> "${run_logfile}" " ... "
+
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
+ printf >&2 "%q " "${@}"
+ printf >&2 "${TPUT_RESET}\n"
+
+ "${@}"
+
+ local ret=$?
+ if [ ${ret} -ne 0 ]
+ then
+ run_failed
+ printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
+ else
+ run_ok
+ printf >> "${run_logfile}" "OK\n"
+ fi
+
+ return ${ret}
+}
+
+
+# ---------------------------------------------------------------------------------------------------------------------
+
+fatal() {
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
+ exit 1
+}
+
+# ---------------------------------------------------------------------------------------------------------------------
+
if [ "$(uname -m)" != "x86_64" ]
then
- echo >&2 "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
- exit 1
+ fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
fi
if [ "$(uname -s)" != "Linux" ]
then
- echo >&2 "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
- exit 1
+ fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
fi
+# ---------------------------------------------------------------------------------------------------------------------
+
BASE='https://raw.githubusercontent.com/firehol/binary-packages/master'
-echo >&2 "Checking the latest version of static build..."
-LATEST="$(curl -Ss "${BASE}/netdata-latest.gz.run")"
+progress "Checking the latest version of static build..."
+LATEST="$(run curl -Ss "${BASE}/netdata-latest.gz.run")"
if [ -z "${LATEST}" ]
then
- echo >&2 "Cannot find the latest static binary version of netdata."
- exit 1
+ fatal "Cannot find the latest static binary version of netdata."
fi
-echo >&2 "Downloading static netdata binary: ${LATEST}"
-curl "${BASE}/${LATEST}" >"/tmp/${LATEST}"
+progress "Downloading static netdata binary: ${LATEST}"
+run curl "${BASE}/${LATEST}" >"/tmp/${LATEST}"
if [ $? -ne 0 ]
then
- echo >&2 "Failed to download the latest static binary version of netdata."
- exit 1
+ fatal "Failed to download the latest static binary version of netdata."
fi
-echo >&2 "Executing the downloaded self-extracting archive"
+progress "Executing the downloaded self-extracting archive"
sudo=
[ "${UID}" != "0" ] && sudo="sudo"
-${sudo} sh "/tmp/${LATEST}"
+run ${sudo} sh "/tmp/${LATEST}"
if [ $? -eq 0 ]
then
rm "/tmp/${LATEST}"
else
- echo >&2 "Did not remove: /tmp/${LATEST}"
+ echo >&2 "NOTE: did not remove: /tmp/${LATEST}"
fi