minor improvements to installation scripts
Costa Tsaousis (ktsaou) committed
May 28, 2017 at 00:30 UTC
103997178bdcff19430b629b0448e4965d16aa14
3 files changed
+155
-17
installer/functions.sh
+1
-1
@@ -81,7 +81,7 @@ setup_terminal() {
81
82
return 0
83
}
84
-setup_terminal
84
+setup_terminal || echo >/dev/null
85
86
progress() {
87
echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
kickstart-static64.sh
+153
-15
@@ -1,45 +1,183 @@
1
#!/usr/bin/env sh
2
3
+umask 022
4
+
5
+# ---------------------------------------------------------------------------------------------------------------------
6
+# library functions copied from installer/functions.sh
7
+
8
+which_cmd() {
9
+ which "${1}" 2>/dev/null || \
10
+ command -v "${1}" 2>/dev/null
11
+}
12
+
13
+check_cmd() {
14
+ which_cmd "${1}" >/dev/null 2>&1 && return 0
15
+ return 1
16
+}
17
+
18
+setup_terminal() {
19
+ TPUT_RESET=""
20
+ TPUT_BLACK=""
21
+ TPUT_RED=""
22
+ TPUT_GREEN=""
23
+ TPUT_YELLOW=""
24
+ TPUT_BLUE=""
25
+ TPUT_PURPLE=""
26
+ TPUT_CYAN=""
27
+ TPUT_WHITE=""
28
+ TPUT_BGBLACK=""
29
+ TPUT_BGRED=""
30
+ TPUT_BGGREEN=""
31
+ TPUT_BGYELLOW=""
32
+ TPUT_BGBLUE=""
33
+ TPUT_BGPURPLE=""
34
+ TPUT_BGCYAN=""
35
+ TPUT_BGWHITE=""
36
+ TPUT_BOLD=""
37
+ TPUT_DIM=""
38
+ TPUT_UNDERLINED=""
39
+ TPUT_BLINK=""
40
+ TPUT_INVERTED=""
41
+ TPUT_STANDOUT=""
42
+ TPUT_BELL=""
43
+ TPUT_CLEAR=""
44
+
45
+ # Is stderr on the terminal? If not, then fail
46
+ test -t 2 || return 1
47
+
48
+ if check_cmd tput
49
+ then
50
+ if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
51
+ then
52
+ # Enable colors
53
+ TPUT_RESET="$(tput sgr 0)"
54
+ TPUT_BLACK="$(tput setaf 0)"
55
+ TPUT_RED="$(tput setaf 1)"
56
+ TPUT_GREEN="$(tput setaf 2)"
57
+ TPUT_YELLOW="$(tput setaf 3)"
58
+ TPUT_BLUE="$(tput setaf 4)"
59
+ TPUT_PURPLE="$(tput setaf 5)"
60
+ TPUT_CYAN="$(tput setaf 6)"
61
+ TPUT_WHITE="$(tput setaf 7)"
62
+ TPUT_BGBLACK="$(tput setab 0)"
63
+ TPUT_BGRED="$(tput setab 1)"
64
+ TPUT_BGGREEN="$(tput setab 2)"
65
+ TPUT_BGYELLOW="$(tput setab 3)"
66
+ TPUT_BGBLUE="$(tput setab 4)"
67
+ TPUT_BGPURPLE="$(tput setab 5)"
68
+ TPUT_BGCYAN="$(tput setab 6)"
69
+ TPUT_BGWHITE="$(tput setab 7)"
70
+ TPUT_BOLD="$(tput bold)"
71
+ TPUT_DIM="$(tput dim)"
72
+ TPUT_UNDERLINED="$(tput smul)"
73
+ TPUT_BLINK="$(tput blink)"
74
+ TPUT_INVERTED="$(tput rev)"
75
+ TPUT_STANDOUT="$(tput smso)"
76
+ TPUT_BELL="$(tput bel)"
77
+ TPUT_CLEAR="$(tput clear)"
78
+ fi
79
+ fi
80
+
81
+ return 0
82
+}
83
+setup_terminal || echo >/dev/null
84
+
85
+progress() {
86
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
87
+}
88
+
89
+run_ok() {
90
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
91
+}
92
+
93
+run_failed() {
94
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
95
+}
96
+
97
+run_logfile="/dev/null"
98
+run() {
99
+ local user="${USER:-}" dir="${PWD}" info info_console
100
+
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
+
110
+ printf >> "${run_logfile}" "${info}"
111
+ printf >> "${run_logfile}" "%q " "${@}"
112
+ printf >> "${run_logfile}" " ... "
113
+
114
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
115
+ printf >&2 "%q " "${@}"
116
+ printf >&2 "${TPUT_RESET}\n"
117
+
118
+ "${@}"
119
+
120
+ local ret=$?
121
+ if [ ${ret} -ne 0 ]
122
+ then
123
+ run_failed
124
+ printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
125
+ else
126
+ run_ok
127
+ printf >> "${run_logfile}" "OK\n"
128
+ fi
129
+
130
+ return ${ret}
131
+}
132
+
133
+
134
+# ---------------------------------------------------------------------------------------------------------------------
135
+
136
+fatal() {
137
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
138
+ exit 1
139
+}
140
+
141
+# ---------------------------------------------------------------------------------------------------------------------
142
+
143
if [ "$(uname -m)" != "x86_64" ]
144
then
5
- echo >&2 "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
6
- exit 1
145
+ fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
146
fi
147
148
if [ "$(uname -s)" != "Linux" ]
149
then
11
- echo >&2 "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
12
- exit 1
150
+ fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
151
fi
152
153
+# ---------------------------------------------------------------------------------------------------------------------
154
+
155
BASE='https://raw.githubusercontent.com/firehol/binary-packages/master'
156
17
-echo >&2 "Checking the latest version of static build..."
18
-LATEST="$(curl -Ss "${BASE}/netdata-latest.gz.run")"
157
+progress "Checking the latest version of static build..."
158
+LATEST="$(run curl -Ss "${BASE}/netdata-latest.gz.run")"
159
160
if [ -z "${LATEST}" ]
161
then
22
- echo >&2 "Cannot find the latest static binary version of netdata."
23
- exit 1
162
+ fatal "Cannot find the latest static binary version of netdata."
163
fi
164
26
-echo >&2 "Downloading static netdata binary: ${LATEST}"
27
-curl "${BASE}/${LATEST}" >"/tmp/${LATEST}"
165
+progress "Downloading static netdata binary: ${LATEST}"
166
+run curl "${BASE}/${LATEST}" >"/tmp/${LATEST}"
167
if [ $? -ne 0 ]
168
then
30
- echo >&2 "Failed to download the latest static binary version of netdata."
31
- exit 1
169
+ fatal "Failed to download the latest static binary version of netdata."
170
fi
171
34
-echo >&2 "Executing the downloaded self-extracting archive"
172
+progress "Executing the downloaded self-extracting archive"
173
174
sudo=
175
[ "${UID}" != "0" ] && sudo="sudo"
38
-${sudo} sh "/tmp/${LATEST}"
176
+run ${sudo} sh "/tmp/${LATEST}"
177
178
if [ $? -eq 0 ]
179
then
180
rm "/tmp/${LATEST}"
181
else
44
- echo >&2 "Did not remove: /tmp/${LATEST}"
182
+ echo >&2 "NOTE: did not remove: /tmp/${LATEST}"
183
fi
kickstart.sh
+1
-1
@@ -99,7 +99,7 @@ setup_terminal() {
99
100
return 0
101
}
102
-setup_terminal
102
+setup_terminal || echo >/dev/null
103
104
progress() {
105
echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "