kickstart.sh is now non-Linux friendly (it throughs errors instead of executing commands it cannot run)
Costa Tsaousis (ktsaou) committed
May 27, 2017 at 17:02 UTC
153b22ec0832664b538d45b72fa404d4a2c00779
1 file changed
+140
-58
kickstart.sh
+140
-58
@@ -1,4 +1,4 @@
1
-#!/usr/bin/env bash
1
+#!/usr/bin/env sh
2
#
3
# Run me with:
4
#
@@ -149,47 +149,57 @@ run() {
149
return ${ret}
150
}
151
152
+
153
# ---------------------------------------------------------------------------------------------------------------------
154
+# collect system information
155
+
156
+set -e
157
+export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
158
159
curl="$(which_cmd curl)"
160
wget="$(which_cmd wget)"
161
bash="$(which_cmd bash)"
162
158
-if [ -z "${BASH_VERSION}" -o -z "${bash}" ]
163
+if [ -z "${BASH_VERSION}" ]
164
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
165
+ # we don't run under bash
166
+ if [ ! -z "${bash}" -a -x "${bash}" ]
167
+ then
168
+ BASH_MAJOR_VERSION=$(${bash} -c 'echo "${BASH_VERSINFO[0]}"')
169
+ fi
170
+else
171
+ # we run under bash
172
+ BASH_MAJOR_VERSION="${BASH_VERSINFO[0]}"
173
fi
174
166
-if [ "${BASH_VERSINFO[0]}" -lt "4" ]
175
+HAS_BASH4=1
176
+if [ -z "${BASH_MAJOR_VERSION}" ]
177
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
178
+ echo >&2 "No BASH is available on this system"
179
+ HAS_BASH4=0
180
+elif [ $((BASH_MAJOR_VERSION)) -lt 4 ]
181
+then
182
+ echo >&2 "No BASH v4+ is available on this system (installed bash is v${BASH_MAJOR_VERSION}"
183
+ HAS_BASH4=0
184
fi
185
174
-# ---------------------------------------------------------------------------------------------------------------------
175
-# this is where the action starts
186
+SYSTEM="$(uname -s)"
187
+OS="$(uname -o)"
188
+MACHINE="$(uname -m)"
189
177
-set -e
190
+cat <<EOF
191
+System : ${SYSTEM}
192
+Operating System : ${OS}
193
+Machine : ${MACHINE}
194
+BASH major version: ${BASH_MAJOR_VERSION}
195
+EOF
196
179
-tmp="$(mktemp /tmp/netdata-kickstart-XXXXXX)"
197
+sudo=""
198
+[ "${UID}" -ne "0" ] && sudo="sudo"
199
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
200
+
201
+# ---------------------------------------------------------------------------------------------------------------------
202
+# install required system packages
203
204
KICKSTART_OPTIONS="netdata"
205
if [ "${1}" = "all" ]
@@ -198,49 +208,121 @@ then
208
shift 1
209
fi
210
201
-ask=0
202
-if [ -s "${tmp}" ]
211
+if [ "${OS}" = "GNU/Linux" -o "${SYSTEM}" = "Linux" ]
212
then
204
- progress "Running downloaded script to detect required packages..."
205
- run "${bash}" "${tmp}" ${KICKSTART_OPTIONS} || ask=1
206
- rm "${tmp}"
213
+ if [ "${HAS_BASH4}" = "1" ]
214
+ then
215
+ tmp="$(mktemp /tmp/netdata-kickstart-XXXXXX)"
216
+
217
+ progress "Downloading script to detect required packages..."
218
+ if [ ! -z "${curl}" ]
219
+ then
220
+ run ${curl} 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh' >"${tmp}"
221
+ elif [ ! -z "${wget}" ]
222
+ then
223
+ run "${wget}" -O - 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh' >"${tmp}"
224
+ else
225
+ run_failed "I need curl or wget to proceed, but neither is available on this system."
226
+ rm "${tmp}"
227
+ exit 1
228
+ fi
229
+
230
+ ask=0
231
+ if [ -s "${tmp}" ]
232
+ then
233
+ progress "Running downloaded script to detect required packages..."
234
+ run ${sudo} "${bash}" "${tmp}" ${KICKSTART_OPTIONS} || ask=1
235
+ rm "${tmp}"
236
+ else
237
+ run_failed "Downloaded script is empty..."
238
+ rm "${tmp}"
239
+ exit 1
240
+ fi
241
+
242
+ if [ "${ask}" = "1" ]
243
+ then
244
+ echo >&2 "It failed to install all the required packages, but I can try to install netdata."
245
+ read -p "Press ENTER to continue to netdata installation > "
246
+ progress "OK, let's give it a try..."
247
+ fi
248
+ else
249
+ echo >&2 "WARNING"
250
+ echo >&2 "Cannot detect the packages to be installed in this system, without BASH v4+."
251
+ echo >&2 "We can only attempt to install netdata..."
252
+ echo >&2
253
+ fi
254
else
208
- run_failed "Downloaded script is empty..."
209
- rm "${tmp}"
210
- exit 1
255
+ echo >&2 "WARNING"
256
+ echo >&2 "Cannot detect the packages to be installed on a ${SYSTEM} - ${OS} system."
257
+ echo >&2 "We can only attempt to install netdata..."
258
+ echo >&2
259
fi
260
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's give it a try..."
218
-fi
261
220
-SOURCE_DST="/usr/src"
221
-sudo=""
222
-[ "${UID}" -ne "0" ] && sudo="sudo"
262
+# ---------------------------------------------------------------------------------------------------------------------
263
+# download netdata source
264
224
-[ ! -d "${SOURCE_DST}" ] && run ${sudo} mkdir -p "${SOURCE_DST}"
265
+git="$(which_cmd git)"
266
+echo >&2 "git: ${git}"
267
226
-if [ ! -d "${SOURCE_DST}/netdata.git" ]
268
+NETDATA_SOURCE_DIR=
269
+if [ ! -z "${git}" -a -x "${git}" ]
270
then
228
- progress "Downloading netdata source code..."
229
- run ${sudo} git clone https://github.com/firehol/netdata.git "${SOURCE_DST}/netdata.git"
230
- cd "${SOURCE_DST}/netdata.git"
271
+ SOURCE_DST="/usr/src"
272
+
273
+ [ ! -d "${SOURCE_DST}" ] && run ${sudo} mkdir -p "${SOURCE_DST}"
274
+
275
+ if [ ! -d "${SOURCE_DST}/netdata.git" ]
276
+ then
277
+ progress "Downloading netdata source code..."
278
+ run ${sudo} ${git} clone https://github.com/firehol/netdata.git "${SOURCE_DST}/netdata.git"
279
+ cd "${SOURCE_DST}/netdata.git"
280
+ else
281
+ progress "Updating netdata source code..."
282
+ cd "${SOURCE_DST}/netdata.git"
283
+ run ${sudo} ${git} fetch --all
284
+ run ${sudo} ${git} reset --hard origin/master
285
+ fi
286
+ NETDATA_SOURCE_DIR="${SOURCE_DST}/netdata.git"
287
else
232
- progress "Updating netdata source code..."
233
- cd "${SOURCE_DST}/netdata.git"
234
- run ${sudo} git fetch --all
235
- run ${sudo} git reset --hard origin/master
288
+ echo >&2 "ERROR"
289
+ echo >&2 "Cannot find the command 'git' to download the netdata source code."
290
+ echo >&2
291
+ exit 1
292
fi
293
238
-progress "Running netdata installer..."
294
240
-if [ -x netdata-updater.sh ]
295
+# ---------------------------------------------------------------------------------------------------------------------
296
+# install netdata from source
297
+
298
+if [ ! -z "${NETDATA_SOURCE_DIR}" -a -d "${NETDATA_SOURCE_DIR}" ]
299
then
242
- run ${sudo} ./netdata-updater.sh -f || run ${sudo} ./netdata-installer.sh -u "${@}"
300
+ cd "${NETDATA_SOURCE_DIR}"
301
+
302
+ install=0
303
+ if [ -x netdata-updater.sh ]
304
+ then
305
+ # attempt to run the updater, to respect any compilation settings already in place
306
+ progress "Re-installing netdata..."
307
+ run ${sudo} ./netdata-updater.sh -f || install=1
308
+ else
309
+ install=1
310
+ fi
311
+
312
+ if [ "${install}" = "1" ]
313
+ then
314
+ if [ -x netdata-installer.sh ]
315
+ then
316
+ progress "Installing netdata..."
317
+ run ${sudo} ./netdata-installer.sh -u "${@}"
318
+ else
319
+ echo >&2 "ERROR"
320
+ echo >&2 "Cannot install netdata from source (the source directory does not include netdata-installer.sh)."
321
+ exit 1
322
+ fi
323
+ fi
324
else
244
- run ${sudo} ./netdata-installer.sh -u "${@}"
325
+ echo >&2 "ERROR"
326
+ echo >&2 "Cannot install netdata from source, on this system (cannot download the source code)."
327
+ exit 1
328
fi
246
-