added kickstart.sh script
Costa Tsaousis (ktsaou) committed
May 27, 2017 at 01:23 UTC
1ca85e63850ea7ea3a627451e60185d1f8692b97
1 file changed
+248
kickstart.sh
new
+248
@@ -0,0 +1,248 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Run me with:
4
+#
5
+# bash <(curl -Ss https://my-netdata.io/kickstart.sh)
6
+#
7
+# or (to install all netdata dependencies):
8
+#
9
+# bash <(curl -Ss https://my-netdata.io/kickstart.sh) all
10
+#
11
+#
12
+# This script will:
13
+#
14
+# 1. install all netdata compilation dependencies
15
+# using the package manager of the system
16
+#
17
+# 2. download netdata source code in /usr/src/netdata.git
18
+#
19
+# 3. install netdata
20
+
21
+umask 022
22
+
23
+
24
+# ---------------------------------------------------------------------------------------------------------------------
25
+# library functions copied from installer/functions.sh
26
+
27
+which_cmd() {
28
+ which "${1}" 2>/dev/null || \
29
+ command -v "${1}" 2>/dev/null
30
+}
31
+
32
+check_cmd() {
33
+ which_cmd "${1}" >/dev/null 2>&1 && return 0
34
+ return 1
35
+}
36
+
37
+setup_terminal() {
38
+ TPUT_RESET=""
39
+ TPUT_BLACK=""
40
+ TPUT_RED=""
41
+ TPUT_GREEN=""
42
+ TPUT_YELLOW=""
43
+ TPUT_BLUE=""
44
+ TPUT_PURPLE=""
45
+ TPUT_CYAN=""
46
+ TPUT_WHITE=""
47
+ TPUT_BGBLACK=""
48
+ TPUT_BGRED=""
49
+ TPUT_BGGREEN=""
50
+ TPUT_BGYELLOW=""
51
+ TPUT_BGBLUE=""
52
+ TPUT_BGPURPLE=""
53
+ TPUT_BGCYAN=""
54
+ TPUT_BGWHITE=""
55
+ TPUT_BOLD=""
56
+ TPUT_DIM=""
57
+ TPUT_UNDERLINED=""
58
+ TPUT_BLINK=""
59
+ TPUT_INVERTED=""
60
+ TPUT_STANDOUT=""
61
+ TPUT_BELL=""
62
+ TPUT_CLEAR=""
63
+
64
+ # Is stderr on the terminal? If not, then fail
65
+ test -t 2 || return 1
66
+
67
+ if check_cmd tput
68
+ then
69
+ if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
70
+ then
71
+ # Enable colors
72
+ TPUT_RESET="$(tput sgr 0)"
73
+ TPUT_BLACK="$(tput setaf 0)"
74
+ TPUT_RED="$(tput setaf 1)"
75
+ TPUT_GREEN="$(tput setaf 2)"
76
+ TPUT_YELLOW="$(tput setaf 3)"
77
+ TPUT_BLUE="$(tput setaf 4)"
78
+ TPUT_PURPLE="$(tput setaf 5)"
79
+ TPUT_CYAN="$(tput setaf 6)"
80
+ TPUT_WHITE="$(tput setaf 7)"
81
+ TPUT_BGBLACK="$(tput setab 0)"
82
+ TPUT_BGRED="$(tput setab 1)"
83
+ TPUT_BGGREEN="$(tput setab 2)"
84
+ TPUT_BGYELLOW="$(tput setab 3)"
85
+ TPUT_BGBLUE="$(tput setab 4)"
86
+ TPUT_BGPURPLE="$(tput setab 5)"
87
+ TPUT_BGCYAN="$(tput setab 6)"
88
+ TPUT_BGWHITE="$(tput setab 7)"
89
+ TPUT_BOLD="$(tput bold)"
90
+ TPUT_DIM="$(tput dim)"
91
+ TPUT_UNDERLINED="$(tput smul)"
92
+ TPUT_BLINK="$(tput blink)"
93
+ TPUT_INVERTED="$(tput rev)"
94
+ TPUT_STANDOUT="$(tput smso)"
95
+ TPUT_BELL="$(tput bel)"
96
+ TPUT_CLEAR="$(tput clear)"
97
+ fi
98
+ fi
99
+
100
+ return 0
101
+}
102
+setup_terminal
103
+
104
+progress() {
105
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
106
+}
107
+
108
+run_ok() {
109
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
110
+}
111
+
112
+run_failed() {
113
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
114
+}
115
+
116
+run_logfile="/dev/null"
117
+run() {
118
+ local user="${USER:-}" dir="${PWD}" info info_console
119
+
120
+ if [ "${UID}" = "0" ]
121
+ then
122
+ info="[root ${dir}]# "
123
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
124
+ else
125
+ info="[${user} ${dir}]$ "
126
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
127
+ fi
128
+
129
+ printf >> "${run_logfile}" "${info}"
130
+ printf >> "${run_logfile}" "%q " "${@}"
131
+ printf >> "${run_logfile}" " ... "
132
+
133
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
134
+ printf >&2 "%q " "${@}"
135
+ printf >&2 "${TPUT_RESET}\n"
136
+
137
+ "${@}"
138
+
139
+ local ret=$?
140
+ if [ ${ret} -ne 0 ]
141
+ then
142
+ run_failed
143
+ printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
144
+ else
145
+ run_ok
146
+ printf >> "${run_logfile}" "OK\n"
147
+ fi
148
+
149
+ return ${ret}
150
+}
151
+
152
+# ---------------------------------------------------------------------------------------------------------------------
153
+
154
+curl="$(which_cmd curl)"
155
+wget="$(which_cmd wget)"
156
+bash="$(which_cmd bash)"
157
+
158
+if [ -z "${BASH_VERSION}" -o -z "${bash}" ]
159
+then
160
+ run_failed "This script needs BASH version 4+."
161
+ echo >&2 "You can still install netdata on any 64bit machine."
162
+ echo >&2 "Check this: https://github.com/firehol/binary-packages"
163
+ exit 1
164
+fi
165
+
166
+if [ "${BASH_VERSINFO[0]}" -lt "4" ]
167
+then
168
+ run_failed "This script needs BASH version 4+, but you have BASH version ${BASH_VERSION}"
169
+ echo >&2 "You can still install netdata on any 64bit machine."
170
+ echo >&2 "Check this: https://github.com/firehol/binary-packages"
171
+ exit 1
172
+fi
173
+
174
+# ---------------------------------------------------------------------------------------------------------------------
175
+# this is where the action starts
176
+
177
+set -e
178
+
179
+tmp="$(mktemp /tmp/netdata-kickstart-XXXXXX)"
180
+
181
+progress "Downloading script to detect required packages..."
182
+if [ ! -z "${curl}" ]
183
+then
184
+ run ${curl} 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh' >"${tmp}"
185
+elif [ ! -z "${wget}" ]
186
+then
187
+ run "${wget}" -O - 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh' >"${tmp}"
188
+else
189
+ run_failed "I need curl or wget to proceed, but neither is available on this system."
190
+ rm "${tmp}"
191
+ exit 1
192
+fi
193
+
194
+KICKSTART_OPTIONS="netdata"
195
+if [ "${1}" = "all" ]
196
+then
197
+ KICKSTART_OPTIONS="netdata-all"
198
+ shift 1
199
+fi
200
+
201
+ask=0
202
+if [ -s "${tmp}" ]
203
+then
204
+ progress "Running downloaded script to detect required packages..."
205
+ run "${bash}" "${tmp}" ${KICKSTART_OPTIONS} || ask=1
206
+ rm "${tmp}"
207
+else
208
+ run_failed "Downloaded script is empty..."
209
+ rm "${tmp}"
210
+ exit 1
211
+fi
212
+
213
+if [ "${ask}" = "1" ]
214
+then
215
+ echo >&2 "It failed to install all the required packages, but I can try to install netdata."
216
+ read -p "Press ENTER to continue to netdata installation > "
217
+ progress "OK, let me give it a try..."
218
+else
219
+ progress "OK, downloading netdata..."
220
+fi
221
+
222
+SOURCE_DST="/usr/src"
223
+sudo=""
224
+[ "${UID}" -ne "0" ] && sudo="sudo"
225
+
226
+[ ! -d "${SOURCE_DST}" ] && run ${sudo} mkdir -p "${SOURCE_DST}"
227
+
228
+if [ ! -d "${SOURCE_DST}/netdata.git" ]
229
+then
230
+ progress "Downloading netdata source code..."
231
+ run ${sudo} git clone https://github.com/firehol/netdata.git "${SOURCE_DST}/netdata.git"
232
+ cd "${SOURCE_DST}/netdata.git"
233
+else
234
+ progress "Updating netdata source code..."
235
+ cd "${SOURCE_DST}/netdata.git"
236
+ run ${sudo} git fetch --all
237
+ run ${sudo} git reset --hard origin/master
238
+fi
239
+
240
+progress "Running netdata installer..."
241
+
242
+#if [ -f netdata-updater.sh ]
243
+#then
244
+# run ${sudo} ./netdata-updater.sh || run ${sudo} ./netdata-installer.sh -u "${@}"
245
+#else
246
+ run ${sudo} ./netdata-installer.sh -u "${@}"
247
+#fi
248
+