Better updater (#4558)
Paweł Krupa committed
Nov 29, 2018 at 23:39 UTC
997a529769a6157f90aaf97d8807ccf968e291ef
5 files changed
+1209
-1362
.gitignore
+2
-1
@@ -45,7 +45,8 @@ freeipmi.plugin
45
cgroup-network
46
!cgroup-network/
47
48
-# netdata makeself archives
48
+# installation artifacts
49
+installer/.environment.sh
50
*.tar.*
51
*.run
52
installer/functions.sh
+545
-616
@@ -5,117 +5,113 @@
5
# make sure we have a UID
6
[ -z "${UID}" ] && UID="$(id -u)"
7
8
-
8
# -----------------------------------------------------------------------------
9
# checking the availability of commands
10
11
which_cmd() {
13
- # shellcheck disable=SC2230
14
- which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null
12
+ # shellcheck disable=SC2230
13
+ which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null
14
}
15
16
check_cmd() {
18
- which_cmd "${1}" >/dev/null 2>&1 && return 0
19
- return 1
17
+ which_cmd "${1}" >/dev/null 2>&1 && return 0
18
+ return 1
19
}
20
22
-
21
# -----------------------------------------------------------------------------
22
23
setup_terminal() {
26
- TPUT_RESET=""
27
- TPUT_BLACK=""
28
- TPUT_RED=""
29
- TPUT_GREEN=""
30
- TPUT_YELLOW=""
31
- TPUT_BLUE=""
32
- TPUT_PURPLE=""
33
- TPUT_CYAN=""
34
- TPUT_WHITE=""
35
- TPUT_BGBLACK=""
36
- TPUT_BGRED=""
37
- TPUT_BGGREEN=""
38
- TPUT_BGYELLOW=""
39
- TPUT_BGBLUE=""
40
- TPUT_BGPURPLE=""
41
- TPUT_BGCYAN=""
42
- TPUT_BGWHITE=""
43
- TPUT_BOLD=""
44
- TPUT_DIM=""
45
- TPUT_UNDERLINED=""
46
- TPUT_BLINK=""
47
- TPUT_INVERTED=""
48
- TPUT_STANDOUT=""
49
- TPUT_BELL=""
50
- TPUT_CLEAR=""
51
-
52
- # Is stderr on the terminal? If not, then fail
53
- test -t 2 || return 1
54
-
55
- if check_cmd tput
56
- then
57
- if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
58
- then
59
- # Enable colors
60
- TPUT_RESET="$(tput sgr 0)"
61
- TPUT_BLACK="$(tput setaf 0)"
62
- TPUT_RED="$(tput setaf 1)"
63
- TPUT_GREEN="$(tput setaf 2)"
64
- TPUT_YELLOW="$(tput setaf 3)"
65
- TPUT_BLUE="$(tput setaf 4)"
66
- TPUT_PURPLE="$(tput setaf 5)"
67
- TPUT_CYAN="$(tput setaf 6)"
68
- TPUT_WHITE="$(tput setaf 7)"
69
- TPUT_BGBLACK="$(tput setab 0)"
70
- TPUT_BGRED="$(tput setab 1)"
71
- TPUT_BGGREEN="$(tput setab 2)"
72
- TPUT_BGYELLOW="$(tput setab 3)"
73
- TPUT_BGBLUE="$(tput setab 4)"
74
- TPUT_BGPURPLE="$(tput setab 5)"
75
- TPUT_BGCYAN="$(tput setab 6)"
76
- TPUT_BGWHITE="$(tput setab 7)"
77
- TPUT_BOLD="$(tput bold)"
78
- TPUT_DIM="$(tput dim)"
79
- TPUT_UNDERLINED="$(tput smul)"
80
- TPUT_BLINK="$(tput blink)"
81
- TPUT_INVERTED="$(tput rev)"
82
- TPUT_STANDOUT="$(tput smso)"
83
- TPUT_BELL="$(tput bel)"
84
- TPUT_CLEAR="$(tput clear)"
85
- fi
86
- fi
87
-
88
- return 0
24
+ TPUT_RESET=""
25
+ TPUT_BLACK=""
26
+ TPUT_RED=""
27
+ TPUT_GREEN=""
28
+ TPUT_YELLOW=""
29
+ TPUT_BLUE=""
30
+ TPUT_PURPLE=""
31
+ TPUT_CYAN=""
32
+ TPUT_WHITE=""
33
+ TPUT_BGBLACK=""
34
+ TPUT_BGRED=""
35
+ TPUT_BGGREEN=""
36
+ TPUT_BGYELLOW=""
37
+ TPUT_BGBLUE=""
38
+ TPUT_BGPURPLE=""
39
+ TPUT_BGCYAN=""
40
+ TPUT_BGWHITE=""
41
+ TPUT_BOLD=""
42
+ TPUT_DIM=""
43
+ TPUT_UNDERLINED=""
44
+ TPUT_BLINK=""
45
+ TPUT_INVERTED=""
46
+ TPUT_STANDOUT=""
47
+ TPUT_BELL=""
48
+ TPUT_CLEAR=""
49
+
50
+ # Is stderr on the terminal? If not, then fail
51
+ test -t 2 || return 1
52
+
53
+ if check_cmd tput; then
54
+ if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
55
+ # Enable colors
56
+ TPUT_RESET="$(tput sgr 0)"
57
+ TPUT_BLACK="$(tput setaf 0)"
58
+ TPUT_RED="$(tput setaf 1)"
59
+ TPUT_GREEN="$(tput setaf 2)"
60
+ TPUT_YELLOW="$(tput setaf 3)"
61
+ TPUT_BLUE="$(tput setaf 4)"
62
+ TPUT_PURPLE="$(tput setaf 5)"
63
+ TPUT_CYAN="$(tput setaf 6)"
64
+ TPUT_WHITE="$(tput setaf 7)"
65
+ TPUT_BGBLACK="$(tput setab 0)"
66
+ TPUT_BGRED="$(tput setab 1)"
67
+ TPUT_BGGREEN="$(tput setab 2)"
68
+ TPUT_BGYELLOW="$(tput setab 3)"
69
+ TPUT_BGBLUE="$(tput setab 4)"
70
+ TPUT_BGPURPLE="$(tput setab 5)"
71
+ TPUT_BGCYAN="$(tput setab 6)"
72
+ TPUT_BGWHITE="$(tput setab 7)"
73
+ TPUT_BOLD="$(tput bold)"
74
+ TPUT_DIM="$(tput dim)"
75
+ TPUT_UNDERLINED="$(tput smul)"
76
+ TPUT_BLINK="$(tput blink)"
77
+ TPUT_INVERTED="$(tput rev)"
78
+ TPUT_STANDOUT="$(tput smso)"
79
+ TPUT_BELL="$(tput bel)"
80
+ TPUT_CLEAR="$(tput clear)"
81
+ fi
82
+ fi
83
+
84
+ return 0
85
}
86
setup_terminal || echo >/dev/null
87
88
progress() {
93
- echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
89
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
90
}
91
92
# -----------------------------------------------------------------------------
93
94
netdata_banner() {
99
- local l1=" ^" \
100
- l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
101
- l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
102
- l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
103
- sp=" " \
104
- netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
95
+ local l1=" ^" \
96
+ l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
97
+ l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
98
+ l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
99
+ sp=" " \
100
+ netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
101
106
- [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
107
- [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
102
+ [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$((${#netdata} - ${#msg}))}"
103
+ [ ${#msg} -gt $((${#l2} - 20)) ] && msg="${msg:0:$((${#l2} - 23))}..."
104
109
- start="$(( ${#l2} / 2 - 4 ))"
110
- [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
111
- end=$(( ${start} + ${#msg} + 4 ))
105
+ start="$((${#l2} / 2 - 4))"
106
+ [ $((start + ${#msg} + 4)) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
107
+ end=$((start + ${#msg} + 4))
108
113
- echo >&2
114
- echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
115
- echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
116
- echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
117
- echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
118
- echo >&2
109
+ echo >&2
110
+ echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
111
+ echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
112
+ echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
113
+ echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
114
+ echo >&2
115
}
116
117
# -----------------------------------------------------------------------------
@@ -125,22 +121,19 @@ service_cmd="$(which_cmd service)"
121
rcservice_cmd="$(which_cmd rc-service)"
122
systemctl_cmd="$(which_cmd systemctl)"
123
service() {
128
- local cmd="${1}" action="${2}"
129
-
130
- if [ ! -z "${systemctl_cmd}" ]
131
- then
132
- run "${systemctl_cmd}" "${action}" "${cmd}"
133
- return $?
134
- elif [ ! -z "${service_cmd}" ]
135
- then
136
- run "${service_cmd}" "${cmd}" "${action}"
137
- return $?
138
- elif [ ! -z "${rcservice_cmd}" ]
139
- then
140
- run "${rcservice_cmd}" "${cmd}" "${action}"
141
- return $?
142
- fi
143
- return 1
124
+ local cmd="${1}" action="${2}"
125
+
126
+ if [ ! -z "${systemctl_cmd}" ]; then
127
+ run "${systemctl_cmd}" "${action}" "${cmd}"
128
+ return $?
129
+ elif [ ! -z "${service_cmd}" ]; then
130
+ run "${service_cmd}" "${cmd}" "${action}"
131
+ return $?
132
+ elif [ ! -z "${rcservice_cmd}" ]; then
133
+ run "${rcservice_cmd}" "${cmd}" "${action}"
134
+ return $?
135
+ fi
136
+ return 1
137
}
138
139
# -----------------------------------------------------------------------------
@@ -148,632 +141,574 @@ service() {
141
142
pidof_cmd="$(which_cmd pidof)"
143
pidof() {
151
- if [ ! -z "${pidof_cmd}" ]
152
- then
153
- ${pidof_cmd} "${@}"
154
- return $?
155
- else
156
- ps -acxo pid,comm |\
157
- sed "s/^ *//g" |\
158
- grep netdata |\
159
- cut -d ' ' -f 1
160
- return $?
161
- fi
144
+ if [ ! -z "${pidof_cmd}" ]; then
145
+ ${pidof_cmd} "${@}"
146
+ return $?
147
+ else
148
+ ps -acxo pid,comm |
149
+ sed "s/^ *//g" |
150
+ grep netdata |
151
+ cut -d ' ' -f 1
152
+ return $?
153
+ fi
154
}
155
156
# -----------------------------------------------------------------------------
157
# portable delete recursively interactively
158
159
portable_deletedir_recursively_interactively() {
168
- if [ ! -z "$1" -a -d "$1" ]
169
- then
170
- if [ "$(uname -s)" = "Darwin" ]
171
- then
172
- echo >&2
173
- read >&2 -p "Press ENTER to recursively delete directory '$1' > "
174
- echo >&2 "Deleting directory '$1' ..."
175
- run rm -R "$1"
176
- else
177
- echo >&2
178
- echo >&2 "Deleting directory '$1' ..."
179
- run rm -I -R "$1"
180
- fi
181
- else
182
- echo "Directory '$1' does not exist."
183
- fi
160
+ if [ ! -z "$1" -a -d "$1" ]; then
161
+ if [ "$(uname -s)" = "Darwin" ]; then
162
+ echo >&2
163
+ read >&2 -p "Press ENTER to recursively delete directory '$1' > "
164
+ echo >&2 "Deleting directory '$1' ..."
165
+ run rm -R "$1"
166
+ else
167
+ echo >&2
168
+ echo >&2 "Deleting directory '$1' ..."
169
+ run rm -I -R "$1"
170
+ fi
171
+ else
172
+ echo "Directory '$1' does not exist."
173
+ fi
174
}
175
186
-
176
# -----------------------------------------------------------------------------
177
178
export SYSTEM_CPUS=1
179
portable_find_processors() {
191
- if [ -f "/proc/cpuinfo" ]
192
- then
193
- # linux
194
- SYSTEM_CPUS=$(grep -c ^processor /proc/cpuinfo)
195
- else
196
- # freebsd
197
- SYSTEM_CPUS=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
198
- fi
199
- [ -z "${SYSTEM_CPUS}" -o $(( SYSTEM_CPUS )) -lt 1 ] && SYSTEM_CPUS=1
180
+ if [ -f "/proc/cpuinfo" ]; then
181
+ # linux
182
+ SYSTEM_CPUS=$(grep -c ^processor /proc/cpuinfo)
183
+ else
184
+ # freebsd
185
+ SYSTEM_CPUS=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
186
+ fi
187
+ [ -z "${SYSTEM_CPUS}" -o $((SYSTEM_CPUS)) -lt 1 ] && SYSTEM_CPUS=1
188
}
189
portable_find_processors
190
191
# -----------------------------------------------------------------------------
192
193
run_ok() {
206
- printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
194
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
195
}
196
197
run_failed() {
210
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
198
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
199
}
200
201
ESCAPED_PRINT_METHOD=
202
printf "%q " test >/dev/null 2>&1
203
[ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
204
escaped_print() {
217
- if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]
218
- then
219
- printf "%q " "${@}"
220
- else
221
- printf "%s" "${*}"
222
- fi
223
- return 0
205
+ if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
206
+ printf "%q " "${@}"
207
+ else
208
+ printf "%s" "${*}"
209
+ fi
210
+ return 0
211
}
212
213
run_logfile="/dev/null"
214
run() {
228
- local user="${USER--}" dir="${PWD}" info info_console
215
+ local user="${USER--}" dir="${PWD}" info info_console
216
230
- if [ "${UID}" = "0" ]
231
- then
232
- info="[root ${dir}]# "
233
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
234
- else
235
- info="[${user} ${dir}]$ "
236
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
237
- fi
217
+ if [ "${UID}" = "0" ]; then
218
+ info="[root ${dir}]# "
219
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
220
+ else
221
+ info="[${user} ${dir}]$ "
222
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
223
+ fi
224
239
- printf >> "${run_logfile}" "${info}"
240
- escaped_print >> "${run_logfile}" "${@}"
241
- printf >> "${run_logfile}" " ... "
225
+ printf >>"${run_logfile}" "${info}"
226
+ escaped_print >>"${run_logfile}" "${@}"
227
+ printf >>"${run_logfile}" " ... "
228
243
- printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
244
- escaped_print >&2 "${@}"
245
- printf >&2 "${TPUT_RESET}\n"
229
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
230
+ escaped_print >&2 "${@}"
231
+ printf >&2 "${TPUT_RESET}\n"
232
247
- "${@}"
233
+ "${@}"
234
249
- local ret=$?
250
- if [ ${ret} -ne 0 ]
251
- then
252
- run_failed
253
- printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
254
- else
255
- run_ok
256
- printf >> "${run_logfile}" "OK\n"
257
- fi
235
+ local ret=$?
236
+ if [ ${ret} -ne 0 ]; then
237
+ run_failed
238
+ printf >>"${run_logfile}" "FAILED with exit code ${ret}\n"
239
+ else
240
+ run_ok
241
+ printf >>"${run_logfile}" "OK\n"
242
+ fi
243
259
- return ${ret}
244
+ return ${ret}
245
}
246
247
getent_cmd="$(which_cmd getent)"
248
portable_check_user_exists() {
264
- local username="${1}" found=
249
+ local username="${1}" found=
250
266
- if [ ! -z "${getent_cmd}" ]
267
- then
268
- "${getent_cmd}" passwd "${username}" >/dev/null 2>&1
269
- return $?
270
- fi
251
+ if [ ! -z "${getent_cmd}" ]; then
252
+ "${getent_cmd}" passwd "${username}" >/dev/null 2>&1
253
+ return $?
254
+ fi
255
272
- found="$(cut -d ':' -f 1 </etc/passwd | grep "^${username}$")"
273
- [ "${found}" = "${username}" ] && return 0
274
- return 1
256
+ found="$(cut -d ':' -f 1 </etc/passwd | grep "^${username}$")"
257
+ [ "${found}" = "${username}" ] && return 0
258
+ return 1
259
}
260
261
portable_check_group_exists() {
278
- local groupname="${1}" found=
262
+ local groupname="${1}" found=
263
280
- if [ ! -z "${getent_cmd}" ]
281
- then
282
- "${getent_cmd}" group "${groupname}" >/dev/null 2>&1
283
- return $?
284
- fi
264
+ if [ ! -z "${getent_cmd}" ]; then
265
+ "${getent_cmd}" group "${groupname}" >/dev/null 2>&1
266
+ return $?
267
+ fi
268
286
- found="$(cut -d ':' -f 1 </etc/group | grep "^${groupname}$")"
287
- [ "${found}" = "${groupname}" ] && return 0
288
- return 1
269
+ found="$(cut -d ':' -f 1 </etc/group | grep "^${groupname}$")"
270
+ [ "${found}" = "${groupname}" ] && return 0
271
+ return 1
272
}
273
274
portable_check_user_in_group() {
292
- local username="${1}" groupname="${2}" users=
275
+ local username="${1}" groupname="${2}" users=
276
294
- if [ ! -z "${getent_cmd}" ]
295
- then
296
- users="$(getent group "${groupname}" | cut -d ':' -f 4)"
297
- else
298
- users="$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)"
299
- fi
277
+ if [ ! -z "${getent_cmd}" ]; then
278
+ users="$(getent group "${groupname}" | cut -d ':' -f 4)"
279
+ else
280
+ users="$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)"
281
+ fi
282
301
- [[ ",${users}," =~ ,${username}, ]] && return 0
302
- return 1
283
+ [[ ",${users}," =~ ,${username}, ]] && return 0
284
+ return 1
285
}
286
287
portable_add_user() {
306
- local username="${1}" homedir="${2}"
288
+ local username="${1}" homedir="${2}"
289
308
- [ -z "${homedir}" ] && homedir="/tmp"
290
+ [ -z "${homedir}" ] && homedir="/tmp"
291
310
- portable_check_user_exists "${username}"
311
- [ $? -eq 0 ] && echo >&2 "User '${username}' already exists." && return 0
292
+ portable_check_user_exists "${username}"
293
+ [ $? -eq 0 ] && echo >&2 "User '${username}' already exists." && return 0
294
313
- echo >&2 "Adding ${username} user account with home ${homedir} ..."
295
+ echo >&2 "Adding ${username} user account with home ${homedir} ..."
296
315
- # shellcheck disable=SC2230
316
- local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
297
+ # shellcheck disable=SC2230
298
+ local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
299
318
- # Linux
319
- if check_cmd useradd
320
- then
321
- run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
322
- fi
300
+ # Linux
301
+ if check_cmd useradd; then
302
+ run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
303
+ fi
304
324
- # FreeBSD
325
- if check_cmd pw
326
- then
327
- run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
328
- fi
305
+ # FreeBSD
306
+ if check_cmd pw; then
307
+ run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
308
+ fi
309
330
- # BusyBox
331
- if check_cmd adduser
332
- then
333
- run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
334
- fi
310
+ # BusyBox
311
+ if check_cmd adduser; then
312
+ run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
313
+ fi
314
336
- echo >&2 "Failed to add ${username} user account !"
315
+ echo >&2 "Failed to add ${username} user account !"
316
338
- return 1
317
+ return 1
318
}
319
320
portable_add_group() {
342
- local groupname="${1}"
321
+ local groupname="${1}"
322
344
- portable_check_group_exists "${groupname}"
345
- [ $? -eq 0 ] && echo >&2 "Group '${groupname}' already exists." && return 0
323
+ portable_check_group_exists "${groupname}"
324
+ [ $? -eq 0 ] && echo >&2 "Group '${groupname}' already exists." && return 0
325
347
- echo >&2 "Adding ${groupname} user group ..."
326
+ echo >&2 "Adding ${groupname} user group ..."
327
349
- # Linux
350
- if check_cmd groupadd
351
- then
352
- run groupadd -r "${groupname}" && return 0
353
- fi
328
+ # Linux
329
+ if check_cmd groupadd; then
330
+ run groupadd -r "${groupname}" && return 0
331
+ fi
332
355
- # FreeBSD
356
- if check_cmd pw
357
- then
358
- run pw groupadd "${groupname}" && return 0
359
- fi
333
+ # FreeBSD
334
+ if check_cmd pw; then
335
+ run pw groupadd "${groupname}" && return 0
336
+ fi
337
361
- # BusyBox
362
- if check_cmd addgroup
363
- then
364
- run addgroup "${groupname}" && return 0
365
- fi
338
+ # BusyBox
339
+ if check_cmd addgroup; then
340
+ run addgroup "${groupname}" && return 0
341
+ fi
342
367
- echo >&2 "Failed to add ${groupname} user group !"
368
- return 1
343
+ echo >&2 "Failed to add ${groupname} user group !"
344
+ return 1
345
}
346
347
portable_add_user_to_group() {
372
- local groupname="${1}" username="${2}"
373
-
374
- portable_check_group_exists "${groupname}"
375
- [ $? -ne 0 ] && echo >&2 "Group '${groupname}' does not exist." && return 1
376
-
377
- # find the user is already in the group
378
- if portable_check_user_in_group "${username}" "${groupname}"
379
- then
380
- # username is already there
381
- echo >&2 "User '${username}' is already in group '${groupname}'."
382
- return 0
383
- else
384
- # username is not in group
385
- echo >&2 "Adding ${username} user to the ${groupname} group ..."
386
-
387
- # Linux
388
- if check_cmd usermod
389
- then
390
- run usermod -a -G "${groupname}" "${username}" && return 0
391
- fi
392
-
393
- # FreeBSD
394
- if check_cmd pw
395
- then
396
- run pw groupmod "${groupname}" -m "${username}" && return 0
397
- fi
398
-
399
- # BusyBox
400
- if check_cmd addgroup
401
- then
402
- run addgroup "${username}" "${groupname}" && return 0
403
- fi
404
-
405
- echo >&2 "Failed to add user ${username} to group ${groupname} !"
406
- return 1
407
- fi
348
+ local groupname="${1}" username="${2}"
349
+
350
+ portable_check_group_exists "${groupname}"
351
+ [ $? -ne 0 ] && echo >&2 "Group '${groupname}' does not exist." && return 1
352
+
353
+ # find the user is already in the group
354
+ if portable_check_user_in_group "${username}" "${groupname}"; then
355
+ # username is already there
356
+ echo >&2 "User '${username}' is already in group '${groupname}'."
357
+ return 0
358
+ else
359
+ # username is not in group
360
+ echo >&2 "Adding ${username} user to the ${groupname} group ..."
361
+
362
+ # Linux
363
+ if check_cmd usermod; then
364
+ run usermod -a -G "${groupname}" "${username}" && return 0
365
+ fi
366
+
367
+ # FreeBSD
368
+ if check_cmd pw; then
369
+ run pw groupmod "${groupname}" -m "${username}" && return 0
370
+ fi
371
+
372
+ # BusyBox
373
+ if check_cmd addgroup; then
374
+ run addgroup "${username}" "${groupname}" && return 0
375
+ fi
376
+
377
+ echo >&2 "Failed to add user ${username} to group ${groupname} !"
378
+ return 1
379
+ fi
380
}
381
382
iscontainer() {
411
- # man systemd-detect-virt
412
- local cmd=$(which_cmd systemd-detect-virt)
413
- if [ ! -z "${cmd}" -a -x "${cmd}" ]
414
- then
415
- "${cmd}" --container >/dev/null 2>&1 && return 0
416
- fi
383
+ # man systemd-detect-virt
384
+ local cmd=$(which_cmd systemd-detect-virt)
385
+ if [ ! -z "${cmd}" -a -x "${cmd}" ]; then
386
+ "${cmd}" --container >/dev/null 2>&1 && return 0
387
+ fi
388
418
- # /proc/1/sched exposes the host's pid of our init !
419
- # http://stackoverflow.com/a/37016302
420
- local pid=$( cat /proc/1/sched 2>/dev/null | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
421
- pid=$(( pid + 0 ))
422
- [ ${pid} -ne 1 ] && return 0
389
+ # /proc/1/sched exposes the host's pid of our init !
390
+ # http://stackoverflow.com/a/37016302
391
+ local pid=$(cat /proc/1/sched 2>/dev/null | head -n 1 | {
392
+ IFS='(),#:' read name pid th threads
393
+ echo $pid
394
+ })
395
+ pid=$((pid + 0))
396
+ [ ${pid} -ne 1 ] && return 0
397
424
- # lxc sets environment variable 'container'
425
- [ ! -z "${container}" ] && return 0
398
+ # lxc sets environment variable 'container'
399
+ [ ! -z "${container}" ] && return 0
400
427
- # docker creates /.dockerenv
428
- # http://stackoverflow.com/a/25518345
429
- [ -f "/.dockerenv" ] && return 0
401
+ # docker creates /.dockerenv
402
+ # http://stackoverflow.com/a/25518345
403
+ [ -f "/.dockerenv" ] && return 0
404
431
- # ubuntu and debian supply /bin/running-in-container
432
- # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
433
- if [ -x "/bin/running-in-container" ]
434
- then
435
- "/bin/running-in-container" >/dev/null 2>&1 && return 0
436
- fi
405
+ # ubuntu and debian supply /bin/running-in-container
406
+ # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
407
+ if [ -x "/bin/running-in-container" ]; then
408
+ "/bin/running-in-container" >/dev/null 2>&1 && return 0
409
+ fi
410
438
- return 1
411
+ return 1
412
}
413
414
issystemd() {
442
- local pids p myns ns systemctl
415
+ local pids p myns ns systemctl
416
444
- # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
445
- [ ! -d /lib/systemd/system -a ! -d /usr/lib/systemd/system ] && return 1
417
+ # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
418
+ [ ! -d /lib/systemd/system -a ! -d /usr/lib/systemd/system ] && return 1
419
447
- # if there is no systemctl command, it is not systemd
448
- # shellcheck disable=SC2230
449
- systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
450
- [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
420
+ # if there is no systemctl command, it is not systemd
421
+ # shellcheck disable=SC2230
422
+ systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
423
+ [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
424
452
- # if pid 1 is systemd, it is systemd
453
- [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
425
+ # if pid 1 is systemd, it is systemd
426
+ [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
427
455
- # if systemd is not running, it is not systemd
456
- pids=$(pidof systemd 2>/dev/null)
457
- [ -z "${pids}" ] && return 1
428
+ # if systemd is not running, it is not systemd
429
+ pids=$(pidof systemd 2>/dev/null)
430
+ [ -z "${pids}" ] && return 1
431
459
- # check if the running systemd processes are not in our namespace
460
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
461
- for p in ${pids}
462
- do
463
- ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
432
+ # check if the running systemd processes are not in our namespace
433
+ myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
434
+ for p in ${pids}; do
435
+ ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
436
465
- # if pid of systemd is in our namespace, it is systemd
466
- [ ! -z "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
467
- done
437
+ # if pid of systemd is in our namespace, it is systemd
438
+ [ ! -z "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
439
+ done
440
469
- # else, it is not systemd
470
- return 1
441
+ # else, it is not systemd
442
+ return 1
443
}
444
445
install_non_systemd_init() {
474
- [ "${UID}" != 0 ] && return 1
475
-
476
- local key="unknown"
477
- if [ -f /etc/os-release ]
478
- then
479
- source /etc/os-release || return 1
480
- key="${ID}-${VERSION_ID}"
481
-
482
- elif [ -f /etc/redhat-release ]
483
- then
484
- key=$(</etc/redhat-release)
485
- fi
486
-
487
- if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
488
- then
489
- if [[ "${key}" =~ ^(gentoo|alpine).* ]]
490
- then
491
- echo >&2 "Installing OpenRC init file..."
492
- run cp system/netdata-openrc /etc/init.d/netdata && \
493
- run chmod 755 /etc/init.d/netdata && \
494
- run rc-update add netdata default && \
495
- return 0
496
-
497
- elif [ "${key}" = "debian-7" \
498
- -o "${key}" = "ubuntu-12.04" \
499
- -o "${key}" = "ubuntu-14.04" \
500
- ]
501
- then
502
- echo >&2 "Installing LSB init file..."
503
- run cp system/netdata-lsb /etc/init.d/netdata && \
504
- run chmod 755 /etc/init.d/netdata && \
505
- run update-rc.d netdata defaults && \
506
- run update-rc.d netdata enable && \
507
- return 0
508
- elif [[ "${key}" =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]
509
- then
510
- echo >&2 "Installing init.d file..."
511
- run cp system/netdata-init-d /etc/init.d/netdata && \
512
- run chmod 755 /etc/init.d/netdata && \
513
- run chkconfig netdata on && \
514
- return 0
515
- else
516
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
517
- return 1
518
- fi
519
- elif [ -f /etc/init.d/netdata ]
520
- then
521
- echo >&2 "file '/etc/init.d/netdata' already exists."
522
- return 0
523
- else
524
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
525
- fi
526
-
527
- return 1
446
+ [ "${UID}" != 0 ] && return 1
447
+
448
+ local key="unknown"
449
+ if [ -f /etc/os-release ]; then
450
+ source /etc/os-release || return 1
451
+ key="${ID}-${VERSION_ID}"
452
+
453
+ elif [ -f /etc/redhat-release ]; then
454
+ key=$(</etc/redhat-release)
455
+ fi
456
+
457
+ if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]; then
458
+ if [[ ${key} =~ ^(gentoo|alpine).* ]]; then
459
+ echo >&2 "Installing OpenRC init file..."
460
+ run cp system/netdata-openrc /etc/init.d/netdata &&
461
+ run chmod 755 /etc/init.d/netdata &&
462
+ run rc-update add netdata default &&
463
+ return 0
464
+
465
+ elif [ "${key}" = "debian-7" \
466
+ -o "${key}" = "ubuntu-12.04" \
467
+ -o "${key}" = "ubuntu-14.04" \
468
+ ]; then
469
+ echo >&2 "Installing LSB init file..."
470
+ run cp system/netdata-lsb /etc/init.d/netdata &&
471
+ run chmod 755 /etc/init.d/netdata &&
472
+ run update-rc.d netdata defaults &&
473
+ run update-rc.d netdata enable &&
474
+ return 0
475
+ elif [[ ${key} =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]; then
476
+ echo >&2 "Installing init.d file..."
477
+ run cp system/netdata-init-d /etc/init.d/netdata &&
478
+ run chmod 755 /etc/init.d/netdata &&
479
+ run chkconfig netdata on &&
480
+ return 0
481
+ else
482
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
483
+ return 1
484
+ fi
485
+ elif [ -f /etc/init.d/netdata ]; then
486
+ echo >&2 "file '/etc/init.d/netdata' already exists."
487
+ return 0
488
+ else
489
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
490
+ fi
491
+
492
+ return 1
493
}
494
495
NETDATA_START_CMD="netdata"
496
NETDATA_STOP_CMD="killall netdata"
497
498
install_netdata_service() {
534
- local uname="$(uname 2>/dev/null)"
535
-
536
- if [ "${UID}" -eq 0 ]
537
- then
538
- if [ "${uname}" = "Darwin" ]
539
- then
540
-
541
- if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]
542
- then
543
- echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists."
544
- return 0
545
- else
546
- echo >&2 "Installing MacOS X plist file..."
547
- run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist && \
548
- run launchctl load /Library/LaunchDaemons/com.github.netdata.plist && \
549
- return 0
550
- fi
551
-
552
- elif [ "${uname}" = "FreeBSD" ]
553
- then
554
-
555
- run cp system/netdata-freebsd /etc/rc.d/netdata && \
556
- NETDATA_START_CMD="service netdata start" && \
557
- NETDATA_STOP_CMD="service netdata stop" && \
558
- return 0
559
-
560
- elif issystemd
561
- then
562
- # systemd is running on this system
563
- NETDATA_START_CMD="systemctl start netdata"
564
- NETDATA_STOP_CMD="systemctl stop netdata"
565
-
566
- SYSTEMD_DIRECTORY=""
567
-
568
- if [ -d "/lib/systemd/system" ]
569
- then
570
- SYSTEMD_DIRECTORY="/lib/systemd/system"
571
- elif [ -d "/usr/lib/systemd/system" ]
572
- then
573
- SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
574
- fi
575
-
576
- if [ "${SYSTEMD_DIRECTORY}x" != "x" ]
577
- then
578
- echo >&2 "Installing systemd service..."
579
- run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" && \
580
- run systemctl daemon-reload && \
581
- run systemctl enable netdata && \
582
- return 0
583
- else
584
- echo >&2 "no systemd directory; cannot install netdata.service"
585
- fi
586
- else
587
- install_non_systemd_init
588
- local ret=$?
589
-
590
- if [ ${ret} -eq 0 ]
591
- then
592
- if [ ! -z "${service_cmd}" ]
593
- then
594
- NETDATA_START_CMD="service netdata start"
595
- NETDATA_STOP_CMD="service netdata stop"
596
- elif [ ! -z "${rcservice_cmd}" ]
597
- then
598
- NETDATA_START_CMD="rc-service netdata start"
599
- NETDATA_STOP_CMD="rc-service netdata stop"
600
- fi
601
- fi
602
-
603
- return ${ret}
604
- fi
605
- fi
606
-
607
- return 1
499
+ local uname="$(uname 2>/dev/null)"
500
+
501
+ if [ "${UID}" -eq 0 ]; then
502
+ if [ "${uname}" = "Darwin" ]; then
503
+
504
+ if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]; then
505
+ echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists."
506
+ return 0
507
+ else
508
+ echo >&2 "Installing MacOS X plist file..."
509
+ run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist &&
510
+ run launchctl load /Library/LaunchDaemons/com.github.netdata.plist &&
511
+ return 0
512
+ fi
513
+
514
+ elif [ "${uname}" = "FreeBSD" ]; then
515
+
516
+ run cp system/netdata-freebsd /etc/rc.d/netdata &&
517
+ NETDATA_START_CMD="service netdata start" &&
518
+ NETDATA_STOP_CMD="service netdata stop" &&
519
+ return 0
520
+
521
+ elif issystemd; then
522
+ # systemd is running on this system
523
+ NETDATA_START_CMD="systemctl start netdata"
524
+ NETDATA_STOP_CMD="systemctl stop netdata"
525
+
526
+ SYSTEMD_DIRECTORY=""
527
+
528
+ if [ -d "/lib/systemd/system" ]; then
529
+ SYSTEMD_DIRECTORY="/lib/systemd/system"
530
+ elif [ -d "/usr/lib/systemd/system" ]; then
531
+ SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
532
+ fi
533
+
534
+ if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then
535
+ echo >&2 "Installing systemd service..."
536
+ run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" &&
537
+ run systemctl daemon-reload &&
538
+ run systemctl enable netdata &&
539
+ return 0
540
+ else
541
+ echo >&2 "no systemd directory; cannot install netdata.service"
542
+ fi
543
+ else
544
+ install_non_systemd_init
545
+ local ret=$?
546
+
547
+ if [ ${ret} -eq 0 ]; then
548
+ if [ ! -z "${service_cmd}" ]; then
549
+ NETDATA_START_CMD="service netdata start"
550
+ NETDATA_STOP_CMD="service netdata stop"
551
+ elif [ ! -z "${rcservice_cmd}" ]; then
552
+ NETDATA_START_CMD="rc-service netdata start"
553
+ NETDATA_STOP_CMD="rc-service netdata stop"
554
+ fi
555
+ fi
556
+
557
+ return ${ret}
558
+ fi
559
+ fi
560
+
561
+ return 1
562
}
563
610
-
564
# -----------------------------------------------------------------------------
565
# stop netdata
566
567
pidisnetdata() {
615
- if [ -d /proc/self ]
616
- then
617
- [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
618
- [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
619
- return 1
620
- fi
621
- return 0
568
+ if [ -d /proc/self ]; then
569
+ [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
570
+ [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
571
+ return 1
572
+ fi
573
+ return 0
574
}
575
576
stop_netdata_on_pid() {
625
- local pid="${1}" ret=0 count=0
577
+ local pid="${1}" ret=0 count=0
578
627
- pidisnetdata ${pid} || return 0
579
+ pidisnetdata ${pid} || return 0
580
629
- printf >&2 "Stopping netdata on pid ${pid} ..."
630
- while [ ! -z "$pid" -a ${ret} -eq 0 ]
631
- do
632
- if [ ${count} -gt 45 ]
633
- then
634
- echo >&2 "Cannot stop the running netdata on pid ${pid}."
635
- return 1
636
- fi
581
+ printf >&2 "Stopping netdata on pid ${pid} ..."
582
+ while [ ! -z "$pid" -a ${ret} -eq 0 ]; do
583
+ if [ ${count} -gt 45 ]; then
584
+ echo >&2 "Cannot stop the running netdata on pid ${pid}."
585
+ return 1
586
+ fi
587
638
- count=$(( count + 1 ))
588
+ count=$((count + 1))
589
640
- run kill ${pid} 2>/dev/null
641
- ret=$?
590
+ run kill ${pid} 2>/dev/null
591
+ ret=$?
592
643
- test ${ret} -eq 0 && printf >&2 "." && sleep 2
644
- done
593
+ test ${ret} -eq 0 && printf >&2 "." && sleep 2
594
+ done
595
646
- echo >&2
647
- if [ ${ret} -eq 0 ]
648
- then
649
- echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
650
- return 1
651
- fi
596
+ echo >&2
597
+ if [ ${ret} -eq 0 ]; then
598
+ echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
599
+ return 1
600
+ fi
601
653
- echo >&2 "netdata on pid ${pid} stopped."
654
- return 0
602
+ echo >&2 "netdata on pid ${pid} stopped."
603
+ return 0
604
}
605
606
netdata_pids() {
658
- local p myns ns
607
+ local p myns ns
608
660
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
609
+ myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
610
662
- # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
611
+ # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
612
664
- for p in \
665
- $(cat /var/run/netdata.pid 2>/dev/null) \
666
- $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
667
- $(pidof netdata 2>/dev/null)
668
- do
669
- ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
613
+ for p in \
614
+ $(cat /var/run/netdata.pid 2>/dev/null) \
615
+ $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
616
+ $(pidof netdata 2>/dev/null); do
617
+ ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
618
671
- if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
672
- then
673
- pidisnetdata ${p} && echo "${p}"
674
- fi
675
- done
619
+ if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]; then
620
+ pidisnetdata ${p} && echo "${p}"
621
+ fi
622
+ done
623
}
624
625
stop_all_netdata() {
679
- local p
680
- for p in $(netdata_pids)
681
- do
682
- stop_netdata_on_pid ${p}
683
- done
626
+ local p
627
+ for p in $(netdata_pids); do
628
+ stop_netdata_on_pid ${p}
629
+ done
630
}
631
632
# -----------------------------------------------------------------------------
633
# restart netdata
634
635
restart_netdata() {
690
- local netdata="${1}"
691
- shift
636
+ local netdata="${1}"
637
+ shift
638
693
- local started=0
639
+ local started=0
640
695
- progress "Start netdata"
641
+ progress "Start netdata"
642
697
- if [ "${UID}" -eq 0 ]
698
- then
699
- service netdata stop
700
- stop_all_netdata
701
- service netdata restart && started=1
643
+ if [ "${UID}" -eq 0 ]; then
644
+ service netdata stop
645
+ stop_all_netdata
646
+ service netdata restart && started=1
647
703
- if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]
704
- then
705
- echo >&2 "Ooops! it seems netdata is not started."
706
- started=0
707
- fi
648
+ if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]; then
649
+ echo >&2 "Ooops! it seems netdata is not started."
650
+ started=0
651
+ fi
652
709
- if [ ${started} -eq 0 ]
710
- then
711
- service netdata start && started=1
712
- fi
713
- fi
653
+ if [ ${started} -eq 0 ]; then
654
+ service netdata start && started=1
655
+ fi
656
+ fi
657
715
- if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]
716
- then
717
- echo >&2 "Hm... it seems netdata is still not started."
718
- started=0
719
- fi
658
+ if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]; then
659
+ echo >&2 "Hm... it seems netdata is still not started."
660
+ started=0
661
+ fi
662
721
- if [ ${started} -eq 0 ]
722
- then
723
- # still not started...
663
+ if [ ${started} -eq 0 ]; then
664
+ # still not started...
665
725
- run stop_all_netdata
726
- run "${netdata}" "${@}"
727
- return $?
728
- fi
666
+ run stop_all_netdata
667
+ run "${netdata}" "${@}"
668
+ return $?
669
+ fi
670
730
- return 0
671
+ return 0
672
}
673
674
# -----------------------------------------------------------------------------
675
# install netdata logrotate
676
677
install_netdata_logrotate() {
737
- if [ ${UID} -eq 0 ]
738
- then
739
- if [ -d /etc/logrotate.d ]
740
- then
741
- if [ ! -f /etc/logrotate.d/netdata ]
742
- then
743
- run cp system/netdata.logrotate /etc/logrotate.d/netdata
744
- fi
745
-
746
- if [ -f /etc/logrotate.d/netdata ]
747
- then
748
- run chmod 644 /etc/logrotate.d/netdata
749
- fi
750
-
751
- return 0
752
- fi
753
- fi
754
-
755
- return 1
678
+ if [ ${UID} -eq 0 ]; then
679
+ if [ -d /etc/logrotate.d ]; then
680
+ if [ ! -f /etc/logrotate.d/netdata ]; then
681
+ run cp system/netdata.logrotate /etc/logrotate.d/netdata
682
+ fi
683
+
684
+ if [ -f /etc/logrotate.d/netdata ]; then
685
+ run chmod 644 /etc/logrotate.d/netdata
686
+ fi
687
+
688
+ return 0
689
+ fi
690
+ fi
691
+
692
+ return 1
693
}
694
695
# -----------------------------------------------------------------------------
696
# download netdata.conf
697
698
fix_netdata_conf() {
762
- local owner="${1}"
699
+ local owner="${1}"
700
764
- if [ "${UID}" -eq 0 ]
765
- then
766
- run chown "${owner}" "${filename}"
767
- fi
768
- run chmod 0664 "${filename}"
701
+ if [ "${UID}" -eq 0 ]; then
702
+ run chown "${owner}" "${filename}"
703
+ fi
704
+ run chmod 0664 "${filename}"
705
}
706
707
generate_netdata_conf() {
772
- local owner="${1}" filename="${2}" url="${3}"
708
+ local owner="${1}" filename="${2}" url="${3}"
709
774
- if [ ! -s "${filename}" ]
775
- then
776
- cat >"${filename}" <<EOFCONF
710
+ if [ ! -s "${filename}" ]; then
711
+ cat >"${filename}" <<EOFCONF
712
# netdata can generate its own config.
713
# Get it with:
714
#
@@ -784,74 +719,68 @@ generate_netdata_conf() {
719
# curl -s -o ${filename} "${url}"
720
#
721
EOFCONF
787
- fix_netdata_conf "${owner}"
788
- fi
722
+ fix_netdata_conf "${owner}"
723
+ fi
724
}
725
726
download_netdata_conf() {
792
- local owner="${1}" filename="${2}" url="${3}"
727
+ local owner="${1}" filename="${2}" url="${3}"
728
794
- if [ ! -s "${filename}" ]
795
- then
796
- echo >&2
797
- echo >&2 "-------------------------------------------------------------------------------"
798
- echo >&2
799
- echo >&2 "Downloading default configuration from netdata..."
800
- sleep 5
729
+ if [ ! -s "${filename}" ]; then
730
+ echo >&2
731
+ echo >&2 "-------------------------------------------------------------------------------"
732
+ echo >&2
733
+ echo >&2 "Downloading default configuration from netdata..."
734
+ sleep 5
735
802
- # remove a possibly obsolete download
803
- [ -f "${filename}.new" ] && rm "${filename}.new"
736
+ # remove a possibly obsolete download
737
+ [ -f "${filename}.new" ] && rm "${filename}.new"
738
805
- # disable a proxy to get data from the local netdata
806
- export http_proxy=
807
- export https_proxy=
739
+ # disable a proxy to get data from the local netdata
740
+ export http_proxy=
741
+ export https_proxy=
742
809
- # try curl
810
- run curl -s -o "${filename}.new" "${url}"
811
- ret=$?
743
+ # try curl
744
+ run curl -s -o "${filename}.new" "${url}"
745
+ ret=$?
746
813
- if [ ${ret} -ne 0 -o ! -s "${filename}.new" ]
814
- then
815
- # try wget
816
- run wget -O "${filename}.new" "${url}"
817
- ret=$?
818
- fi
747
+ if [ ${ret} -ne 0 -o ! -s "${filename}.new" ]; then
748
+ # try wget
749
+ run wget -O "${filename}.new" "${url}"
750
+ ret=$?
751
+ fi
752
820
- if [ ${ret} -eq 0 -a -s "${filename}.new" ]
821
- then
822
- run mv "${filename}.new" "${filename}"
823
- run_ok "New configuration saved for you to edit at ${filename}"
824
- else
825
- [ -f "${filename}.new" ] && rm "${filename}.new"
826
- run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
753
+ if [ ${ret} -eq 0 -a -s "${filename}.new" ]; then
754
+ run mv "${filename}.new" "${filename}"
755
+ run_ok "New configuration saved for you to edit at ${filename}"
756
+ else
757
+ [ -f "${filename}.new" ] && rm "${filename}.new"
758
+ run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
759
828
- generate_netdata_conf "${owner}" "${filename}" "${url}"
829
- fi
760
+ generate_netdata_conf "${owner}" "${filename}" "${url}"
761
+ fi
762
831
- fix_netdata_conf "${owner}"
832
- fi
763
+ fix_netdata_conf "${owner}"
764
+ fi
765
}
766
835
-
767
# -----------------------------------------------------------------------------
768
# add netdata user and group
769
770
NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
771
NETDATA_ADDED_TO_GROUPS=""
772
add_netdata_user_and_group() {
842
- local homedir="${1}" g
773
+ local homedir="${1}" g
774
844
- if [ ${UID} -eq 0 ]
845
- then
846
- portable_add_group netdata || return 1
847
- portable_add_user netdata "${homedir}" || return 1
775
+ if [ ${UID} -eq 0 ]; then
776
+ portable_add_group netdata || return 1
777
+ portable_add_user netdata "${homedir}" || return 1
778
849
- for g in ${NETDATA_WANTED_GROUPS}
850
- do
851
- portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
852
- done
779
+ for g in ${NETDATA_WANTED_GROUPS}; do
780
+ portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
781
+ done
782
854
- [ ~netdata = / ] && cat <<USERMOD
783
+ [ ~netdata = / ] && cat <<USERMOD
784
785
The netdata user has its home directory set to /
786
You may want to change it, using this command:
@@ -859,8 +788,8 @@ You may want to change it, using this command:
788
# usermod -d "${homedir}" netdata
789
790
USERMOD
862
- return 0
863
- fi
791
+ return 0
792
+ fi
793
865
- return 1
794
+ return 1
795
}
installer/netdata-uninstaller.sh
new
+100
@@ -0,0 +1,100 @@
1
+#!/usr/bin/env bash
2
+#shellcheck disable=SC2181
3
+
4
+# this script will uninstall netdata
5
+
6
+# Variables needed by script:
7
+# - NETDATA_PREFIX
8
+# - NETDATA_ADDED_TO_GROUPS
9
+
10
+if [ "$1" != "--force" ]; then
11
+ echo >&2 "This script will REMOVE netdata from your system."
12
+ echo >&2 "Run it again with --force to do it."
13
+ exit 1
14
+fi
15
+
16
+#shellcheck source=/dev/null
17
+source installer/.environment.sh || exit 1
18
+#shellcheck source=/dev/null
19
+source installer/functions.sh || exit 1
20
+
21
+echo >&2 "Stopping a possibly running netdata..."
22
+for p in $(stop_all_netdata netdata); do run kill "$p"; done
23
+sleep 2
24
+
25
+if [ ! -z "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ]; then
26
+ # installation prefix was given
27
+
28
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}"
29
+
30
+else
31
+ # installation prefix was NOT given
32
+
33
+ if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]; then
34
+ echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
35
+ run rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
36
+ fi
37
+
38
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/etc/netdata"
39
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/share/netdata"
40
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/libexec/netdata"
41
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/lib/netdata"
42
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/cache/netdata"
43
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/log/netdata"
44
+fi
45
+
46
+if [ -f /etc/logrotate.d/netdata ]; then
47
+ echo "Deleting /etc/logrotate.d/netdata ..."
48
+ run rm -i /etc/logrotate.d/netdata
49
+fi
50
+
51
+if [ -f /etc/systemd/system/netdata.service ]; then
52
+ echo "Deleting /etc/systemd/system/netdata.service ..."
53
+ run rm -i /etc/systemd/system/netdata.service
54
+fi
55
+
56
+if [ -f /lib/systemd/system/netdata.service ]; then
57
+ echo "Deleting /lib/systemd/system/netdata.service ..."
58
+ run rm -i /lib/systemd/system/netdata.service
59
+fi
60
+
61
+if [ -f /etc/init.d/netdata ]; then
62
+ echo "Deleting /etc/init.d/netdata ..."
63
+ run rm -i /etc/init.d/netdata
64
+fi
65
+
66
+if [ -f /etc/periodic/daily/netdata-updater ]; then
67
+ echo "Deleting /etc/periodic/daily/netdata-updater ..."
68
+ run rm -i /etc/periodic/daily/netdata-updater
69
+fi
70
+
71
+if [ -f /etc/cron.daily/netdata-updater ]; then
72
+ echo "Deleting /etc/cron.daily/netdata-updater ..."
73
+ run rm -i /etc/cron.daily/netdata-updater
74
+fi
75
+
76
+portable_check_user_exists netdata
77
+if [ $? -eq 0 ]; then
78
+ echo
79
+ echo "You may also want to remove the user netdata"
80
+ echo "by running:"
81
+ echo " userdel netdata"
82
+fi
83
+
84
+portable_check_group_exists netdata >/dev/null
85
+if [ $? -eq 0 ]; then
86
+ echo
87
+ echo "You may also want to remove the group netdata"
88
+ echo "by running:"
89
+ echo " groupdel netdata"
90
+fi
91
+
92
+for g in ${NETDATA_ADDED_TO_GROUPS}; do
93
+ portable_check_group_exists "$g" >/dev/null
94
+ if [ $? -eq 0 ]; then
95
+ echo
96
+ echo "You may also want to remove the netdata user from the $g group"
97
+ echo "by running:"
98
+ echo " gpasswd -d netdata $g"
99
+ fi
100
+done
installer/netdata-updater.sh
new
+122
@@ -0,0 +1,122 @@
1
+#!/usr/bin/env bash
2
+
3
+# this script will uninstall netdata
4
+
5
+# Variables needed by script:
6
+# - PATH
7
+# - CFLAGS
8
+# - NETDATA_CONFIGURE_OPTIONS
9
+# - REINSTALL_PWD
10
+# - REINSTALL_COMMAND
11
+
12
+force=0
13
+[ "${1}" = "-f" ] && force=1
14
+
15
+# make sure we cd to the working directory
16
+REINSTALL_PWD="THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT"
17
+cd "${REINSTALL_PWD}" || exit 1
18
+
19
+#shellcheck source=/dev/null
20
+source installer/.environment.sh || exit 1
21
+
22
+UID="$(id -u)"
23
+if [ "${INSTALL_UID}" != "${UID}" ]
24
+ then
25
+ echo >&2 "This script should be run as user with uid ${INSTALL_UID} but it now runs with uid ${UID}"
26
+ exit 1
27
+fi
28
+
29
+# make sure there is .git here
30
+[ ${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
31
+
32
+# signal netdata to start saving its database
33
+# this is handy if your database is big
34
+pids=$(pidof netdata)
35
+do_not_start=
36
+if [ ! -z "${pids}" ]; then
37
+ #shellcheck disable=SC2086
38
+ kill -USR1 ${pids}
39
+else
40
+ # netdata is currently not running, so do not start it after updating
41
+ do_not_start="--dont-start-it"
42
+fi
43
+
44
+tmp=
45
+if [ -t 2 ]; then
46
+ # we are running on a terminal
47
+ # open fd 3 and send it to stderr
48
+ exec 3>&2
49
+else
50
+ # we are headless
51
+ # create a temporary file for the log
52
+ tmp=$(mktemp /tmp/netdata-updater.log.XXXXXX)
53
+ # open fd 3 and send it to tmp
54
+ exec 3>"${tmp}"
55
+fi
56
+
57
+info() {
58
+ echo >&3 "$(date) : INFO: " "${@}"
59
+}
60
+
61
+emptyline() {
62
+ echo >&3
63
+}
64
+
65
+error() {
66
+ echo >&3 "$(date) : ERROR: " "${@}"
67
+}
68
+
69
+# this is what we will do if it fails (head-less only)
70
+failed() {
71
+ error "FAILED TO UPDATE NETDATA : ${1}"
72
+
73
+ if [ ! -z "${tmp}" ]; then
74
+ cat >&2 "${tmp}"
75
+ rm "${tmp}"
76
+ fi
77
+ exit 1
78
+}
79
+
80
+get_latest_commit_id() {
81
+ git rev-parse HEAD 2>&3
82
+}
83
+
84
+update() {
85
+ [ -z "${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
86
+
87
+ emptyline
88
+
89
+ if [ -d .git ]; then
90
+ info "Updating netdata source from github..."
91
+
92
+ last_commit="$(get_latest_commit_id)"
93
+ if [ ${force} -eq 0 ] && [ -z "${last_commit}" ]; then
94
+ failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
95
+ fi
96
+
97
+ info "Stashing local git changes. You can use $(git stash pop) to reapply your changes."
98
+ git stash >&3
99
+ git fetch --all >&3
100
+ git fetch --tags >&3
101
+ git checkout origin/master >&3
102
+ git reset --hard origin/master >&3
103
+
104
+ new_commit="$(get_latest_commit_id)"
105
+ if [ ${force} -eq 0 ]; then
106
+ [ -z "${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
107
+ [ "${new_commit}" = "${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
108
+ fi
109
+ elif [ ${force} -eq 0 ]; then
110
+ failed "CANNOT FIND GIT STRUCTURES IN $(pwd) (use -f for force re-install)"
111
+ fi
112
+
113
+ emptyline
114
+ info "Re-installing netdata..."
115
+ ${REINSTALL_COMMAND} --dont-wait ${do_not_start} >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
116
+
117
+ [ ! -z "${tmp}" ] && rm "${tmp}" && tmp=
118
+ return 0
119
+}
120
+
121
+# the installer updates this script - so we run and exit in a single line
122
+update && exit 0
netdata-installer.sh
+440
-745
@@ -4,29 +4,25 @@
4
5
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
6
uniquepath() {
7
- local path=""
8
- while read
9
- do
10
- if [[ ! "${path}" =~ (^|:)"${REPLY}"(:|$) ]]
11
- then
12
- [ ! -z "${path}" ] && path="${path}:"
13
- path="${path}${REPLY}"
14
- fi
15
- done < <( echo "${PATH}" | tr ":" "\n" )
16
-
17
- [ ! -z "${path}" ] && [[ "${PATH}" =~ /bin ]] && [[ "${PATH}" =~ /sbin ]] && export PATH="${path}"
7
+ local path=""
8
+ while read; do
9
+ if [[ ! ${path} =~ (^|:)"${REPLY}"(:|$) ]]; then
10
+ [ ! -z "${path}" ] && path="${path}:"
11
+ path="${path}${REPLY}"
12
+ fi
13
+ done < <(echo "${PATH}" | tr ":" "\n")
14
+
15
+ [ ! -z "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
16
}
17
uniquepath
18
19
netdata_source_dir="$(pwd)"
20
installer_dir="$(dirname "${0}")"
21
24
-if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]
25
- then
26
- echo >&2 "Warning: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'."
22
+if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]; then
23
+ echo >&2 "Warning: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'."
24
fi
25
29
-
26
# -----------------------------------------------------------------------------
27
# reload the user profile
28
@@ -35,28 +31,24 @@ fi
31
# make sure /etc/profile does not change our current directory
32
cd "${netdata_source_dir}" || exit 1
33
38
-
34
# -----------------------------------------------------------------------------
35
# load the required functions
36
42
-if [ -f "${installer_dir}/installer/functions.sh" ]
43
- then
44
- source "${installer_dir}/installer/functions.sh" || exit 1
37
+if [ -f "${installer_dir}/installer/functions.sh" ]; then
38
+ source "${installer_dir}/installer/functions.sh" || exit 1
39
else
46
- source "${netdata_source_dir}/installer/functions.sh" || exit 1
40
+ source "${netdata_source_dir}/installer/functions.sh" || exit 1
41
fi
42
43
# make sure we save all commands we run
44
run_logfile="netdata-installer.log"
45
52
-
46
# -----------------------------------------------------------------------------
47
# fix PKG_CHECK_MODULES error
48
56
-if [ -d /usr/share/aclocal ]
57
-then
58
- ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
59
- export ACLOCAL_PATH
49
+if [ -d /usr/share/aclocal ]; then
50
+ ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
51
+ export ACLOCAL_PATH
52
fi
53
54
export LC_ALL=C
@@ -72,12 +64,15 @@ CFLAGS="${CFLAGS--O2}"
64
# keep a log of this command
65
printf "\n# " >>netdata-installer.log
66
date >>netdata-installer.log
75
-printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
67
+printf 'CFLAGS="%s" ' "${CFLAGS}" >>netdata-installer.log
68
printf "%q " "$0" "${@}" >>netdata-installer.log
69
printf "\n" >>netdata-installer.log
70
71
REINSTALL_PWD="${PWD}"
80
-REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
72
+REINSTALL_COMMAND="$(
73
+ printf "%q " "$0" "${@}"
74
+ printf "\n"
75
+)"
76
# remove options that shown not be inherited by netdata-updater.sh
77
REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}"
78
REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-start-it/}"
@@ -95,8 +90,8 @@ LIBS_ARE_HERE=0
90
NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
91
92
usage() {
98
- netdata_banner "installer command line options"
99
- cat <<USAGE
93
+ netdata_banner "installer command line options"
94
+ cat <<USAGE
95
96
${ME} <installer options>
97
@@ -173,67 +168,53 @@ For the plugins, you will at least need:
168
USAGE
169
}
170
176
-while [ ! -z "${1}" ]
177
-do
178
- if [ "$1" = "--install" ]
179
- then
180
- NETDATA_PREFIX="${2}/netdata"
181
- shift 2
182
- elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
183
- then
184
- LIBS_ARE_HERE=1
185
- shift 1
186
- elif [ "$1" = "--dont-start-it" ]
187
- then
188
- DONOTSTART=1
189
- shift 1
190
- elif [ "$1" = "--dont-wait" ]
191
- then
192
- DONOTWAIT=1
193
- shift 1
194
- elif [ "$1" = "--auto-update" -o "$1" = "-u" ]
195
- then
196
- AUTOUPDATE=1
197
- shift 1
198
- elif [ "$1" = "--enable-plugin-freeipmi" ]
199
- then
200
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi"
201
- shift 1
202
- elif [ "$1" = "--disable-plugin-freeipmi" ]
203
- then
204
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi"
205
- shift 1
206
- elif [ "$1" = "--enable-plugin-nfacct" ]
207
- then
208
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct"
209
- shift 1
210
- elif [ "$1" = "--disable-plugin-nfacct" ]
211
- then
212
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct"
213
- shift 1
214
- elif [ "$1" = "--enable-lto" ]
215
- then
216
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto"
217
- shift 1
218
- elif [ "$1" = "--disable-lto" ]
219
- then
220
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto"
221
- shift 1
222
- elif [ "$1" = "--disable-x86-sse" ]
223
- then
224
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse"
225
- shift 1
226
- elif [ "$1" = "--help" -o "$1" = "-h" ]
227
- then
228
- usage
229
- exit 1
230
- else
231
- echo >&2
232
- echo >&2 "ERROR:"
233
- echo >&2 "I cannot understand option '$1'."
234
- usage
235
- exit 1
236
- fi
171
+while [ ! -z "${1}" ]; do
172
+ if [ "$1" = "--install" ]; then
173
+ NETDATA_PREFIX="${2}/netdata"
174
+ shift 2
175
+ elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]; then
176
+ LIBS_ARE_HERE=1
177
+ shift 1
178
+ elif [ "$1" = "--dont-start-it" ]; then
179
+ DONOTSTART=1
180
+ shift 1
181
+ elif [ "$1" = "--dont-wait" ]; then
182
+ DONOTWAIT=1
183
+ shift 1
184
+ elif [ "$1" = "--auto-update" -o "$1" = "-u" ]; then
185
+ AUTOUPDATE=1
186
+ shift 1
187
+ elif [ "$1" = "--enable-plugin-freeipmi" ]; then
188
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi"
189
+ shift 1
190
+ elif [ "$1" = "--disable-plugin-freeipmi" ]; then
191
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi"
192
+ shift 1
193
+ elif [ "$1" = "--enable-plugin-nfacct" ]; then
194
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct"
195
+ shift 1
196
+ elif [ "$1" = "--disable-plugin-nfacct" ]; then
197
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct"
198
+ shift 1
199
+ elif [ "$1" = "--enable-lto" ]; then
200
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto"
201
+ shift 1
202
+ elif [ "$1" = "--disable-lto" ]; then
203
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto"
204
+ shift 1
205
+ elif [ "$1" = "--disable-x86-sse" ]; then
206
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse"
207
+ shift 1
208
+ elif [ "$1" = "--help" -o "$1" = "-h" ]; then
209
+ usage
210
+ exit 1
211
+ else
212
+ echo >&2
213
+ echo >&2 "ERROR:"
214
+ echo >&2 "I cannot understand option '$1'."
215
+ usage
216
+ exit 1
217
+ fi
218
done
219
220
# replace multiple spaces with a single space
@@ -267,13 +248,11 @@ cat <<BANNER3
248
249
BANNER3
250
270
-if [ "${UID}" -ne 0 ]
271
- then
272
- if [ -z "${NETDATA_PREFIX}" ]
273
- then
274
- netdata_banner "wrong command line options!"
275
- cat <<NONROOTNOPREFIX
276
-
251
+if [ "${UID}" -ne 0 ]; then
252
+ if [ -z "${NETDATA_PREFIX}" ]; then
253
+ netdata_banner "wrong command line options!"
254
+ cat <<NONROOTNOPREFIX
255
+
256
${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
257
258
You are attempting to install netdata as non-root, but you plan
@@ -293,11 +272,11 @@ if [ "${UID}" -ne 0 ]
272
functionality.
273
274
NONROOTNOPREFIX
296
- exit 1
297
-
298
- else
299
- cat <<NONROOT
275
+ exit 1
276
277
+ else
278
+ cat <<NONROOT
279
+
280
${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
281
You are about to install netdata as a non-root user.
282
Netdata will work, but a few data collection modules that
@@ -309,44 +288,39 @@ NONROOTNOPREFIX
288
${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
289
290
NONROOT
312
- fi
291
+ fi
292
fi
293
294
have_autotools=
316
-if [ "$(type autoreconf 2> /dev/null)" ]
317
-then
318
- autoconf_maj_min() {
319
- local maj min IFS=.-
320
-
321
- maj=$1
322
- min=$2
323
-
324
- set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
325
- eval $maj=\$1 $min=\$2
326
- }
327
- autoconf_maj_min AMAJ AMIN
328
-
329
- if [ "$AMAJ" -gt 2 ]
330
- then
331
- have_autotools=Y
332
- elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
333
- then
334
- have_autotools=Y
335
- else
336
- echo "Found autotools $AMAJ.$AMIN"
337
- fi
295
+if [ "$(type autoreconf 2>/dev/null)" ]; then
296
+ autoconf_maj_min() {
297
+ local maj min IFS=.-
298
+
299
+ maj=$1
300
+ min=$2
301
+
302
+ set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
303
+ eval $maj=\$1 $min=\$2
304
+ }
305
+ autoconf_maj_min AMAJ AMIN
306
+
307
+ if [ "$AMAJ" -gt 2 ]; then
308
+ have_autotools=Y
309
+ elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]; then
310
+ have_autotools=Y
311
+ else
312
+ echo "Found autotools $AMAJ.$AMIN"
313
+ fi
314
else
339
- echo "No autotools found"
315
+ echo "No autotools found"
316
fi
317
342
-if [ ! "$have_autotools" ]
343
-then
344
- if [ -f configure ]
345
- then
346
- echo "Will skip autoreconf step"
347
- else
348
- netdata_banner "autotools v2.60 required"
349
- cat <<"EOF"
318
+if [ ! "$have_autotools" ]; then
319
+ if [ -f configure ]; then
320
+ echo "Will skip autoreconf step"
321
+ else
322
+ netdata_banner "autotools v2.60 required"
323
+ cat <<"EOF"
324
325
-------------------------------------------------------------------------------
326
autotools 2.60 or later is required
@@ -355,25 +329,23 @@ Sorry, you do not seem to have autotools 2.60 or later, which is
329
required to build from the git sources of netdata.
330
331
EOF
358
- exit 1
359
- fi
332
+ exit 1
333
+ fi
334
fi
335
362
-if [ ${DONOTWAIT} -eq 0 ]
363
- then
364
- if [ ! -z "${NETDATA_PREFIX}" ]
365
- then
366
- eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to \'\001${TPUT_CYAN}\002${NETDATA_PREFIX}\001${TPUT_YELLOW}\002\'\001${TPUT_RESET}\002 > ' -e -r REPLY"
367
- [ $? -ne 0 ] && exit 1
368
- else
369
- eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to your system\001${TPUT_RESET}\002 > ' -e -r REPLY"
370
- [ $? -ne 0 ] && exit 1
371
- fi
336
+if [ ${DONOTWAIT} -eq 0 ]; then
337
+ if [ ! -z "${NETDATA_PREFIX}" ]; then
338
+ eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to \'\001${TPUT_CYAN}\002${NETDATA_PREFIX}\001${TPUT_YELLOW}\002\'\001${TPUT_RESET}\002 > ' -e -r REPLY"
339
+ [ $? -ne 0 ] && exit 1
340
+ else
341
+ eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to your system\001${TPUT_RESET}\002 > ' -e -r REPLY"
342
+ [ $? -ne 0 ] && exit 1
343
+ fi
344
fi
345
346
build_error() {
375
- netdata_banner "sorry, it failed to build..."
376
- cat <<EOF
347
+ netdata_banner "sorry, it failed to build..."
348
+ cat <<EOF
349
350
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
351
@@ -403,41 +375,38 @@ If you still cannot get it to build, ask for help at github:
375
376
377
EOF
406
- trap - EXIT
407
- exit 1
378
+ trap - EXIT
379
+ exit 1
380
}
381
410
-if [ ${LIBS_ARE_HERE} -eq 1 ]
411
- then
412
- shift
413
- echo >&2 "ok, assuming libs are really installed."
414
- export ZLIB_CFLAGS=" "
415
- export ZLIB_LIBS="-lz"
416
- export UUID_CFLAGS=" "
417
- export UUID_LIBS="-luuid"
382
+if [ ${LIBS_ARE_HERE} -eq 1 ]; then
383
+ shift
384
+ echo >&2 "ok, assuming libs are really installed."
385
+ export ZLIB_CFLAGS=" "
386
+ export ZLIB_LIBS="-lz"
387
+ export UUID_CFLAGS=" "
388
+ export UUID_LIBS="-luuid"
389
fi
390
391
trap build_error EXIT
392
422
-
393
# -----------------------------------------------------------------------------
394
echo >&2
395
progress "Run autotools to configure the build environment"
396
427
-if [ "$have_autotools" ]
428
-then
429
- run autoreconf -ivf || exit 1
397
+if [ "$have_autotools" ]; then
398
+ run autoreconf -ivf || exit 1
399
fi
400
401
run ./configure \
433
- --prefix="${NETDATA_PREFIX}/usr" \
434
- --sysconfdir="${NETDATA_PREFIX}/etc" \
435
- --localstatedir="${NETDATA_PREFIX}/var" \
436
- --with-zlib \
437
- --with-math \
438
- --with-user=netdata \
439
- ${NETDATA_CONFIGURE_OPTIONS} \
440
- CFLAGS="${CFLAGS}" || exit 1
402
+ --prefix="${NETDATA_PREFIX}/usr" \
403
+ --sysconfdir="${NETDATA_PREFIX}/etc" \
404
+ --localstatedir="${NETDATA_PREFIX}/var" \
405
+ --with-zlib \
406
+ --with-math \
407
+ --with-user=netdata \
408
+ ${NETDATA_CONFIGURE_OPTIONS} \
409
+ CFLAGS="${CFLAGS}" || exit 1
410
411
# remove the build_error hook
412
trap - EXIT
@@ -447,55 +416,44 @@ progress "Cleanup compilation directory"
416
417
[ -f src/netdata ] && run make clean
418
450
-
419
# -----------------------------------------------------------------------------
420
progress "Compile netdata"
421
422
run make -j${SYSTEM_CPUS} || exit 1
423
456
-
424
# -----------------------------------------------------------------------------
425
progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
426
427
# migrate existing configuration files
428
# for node.d and charts.d
462
-if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
463
- then
464
- # the configuration directory exists
465
-
466
- if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
467
- then
468
- run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
469
- fi
470
-
471
- # move the charts.d config files
472
- for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
473
- do
474
- for y in "" ".old" ".orig"
475
- do
476
- if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
477
- then
478
- run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
479
- fi
480
- done
481
- done
482
-
483
- if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
484
- then
485
- run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
486
- fi
487
-
488
- # move the node.d config files
489
- for x in named sma_webbox snmp
490
- do
491
- for y in "" ".old" ".orig"
492
- do
493
- if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
494
- then
495
- run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
496
- fi
497
- done
498
- done
429
+if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
430
+ # the configuration directory exists
431
+
432
+ if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]; then
433
+ run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
434
+ fi
435
+
436
+ # move the charts.d config files
437
+ for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat; do
438
+ for y in "" ".old" ".orig"; do
439
+ if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
440
+ run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
441
+ fi
442
+ done
443
+ done
444
+
445
+ if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]; then
446
+ run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
447
+ fi
448
+
449
+ # move the node.d config files
450
+ for x in named sma_webbox snmp; do
451
+ for y in "" ".old" ".orig"; do
452
+ if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]; then
453
+ run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
454
+ fi
455
+ done
456
+ done
457
fi
458
459
# -----------------------------------------------------------------------------
@@ -504,72 +462,63 @@ fi
462
md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
463
464
deleted_stock_configs=0
507
-if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]
508
-then
509
-
510
- progress "Backup existing netdata configuration before installing it"
511
-
512
- if [ "${BASH_VERSINFO[0]}" -ge "4" ]
513
- then
514
- declare -A configs_signatures=()
515
- if [ -f "configs.signatures" ]
516
- then
517
- source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
518
- fi
519
- fi
520
-
521
- config_signature_matches() {
522
- local md5="${1}" file="${2}"
523
-
524
- if [ "${BASH_VERSINFO[0]}" -ge "4" ]
525
- then
526
- [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
527
- return 1
528
- fi
529
-
530
- if [ -f "configs.signatures" ]
531
- then
532
- grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
533
- return $?
534
- fi
535
-
536
- return 1
537
- }
538
-
539
- # clean up stock config files from the user configuration directory
540
- for x in $(find -L "${NETDATA_PREFIX}/etc/netdata" -type f)
541
- do
542
- if [ -f "${x}" ]
543
- then
544
- # find it relative filename
545
- f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}"
546
-
547
- # find the stock filename
548
- t="${f/.conf.installer_backup.*/.conf}"
549
- t="${t/.conf.old/.conf}"
550
- t="${t/.conf.orig/.conf}"
551
-
552
- if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
553
- then
554
- # we don't have md5sum - keep it
555
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
556
- else
557
- # find its checksum
558
- md5="$(${md5sum} <"${x}" | cut -d ' ' -f 1)"
559
-
560
- if config_signature_matches "${md5}" "${t}"
561
- then
562
- # it is a stock version - remove it
563
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
564
- run rm -f "${x}"
565
- deleted_stock_configs=$(( deleted_stock_configs + 1 ))
566
- else
567
- # edited by user - keep it
568
- echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of '${t}'${TPUT_RESET}. Keeping it."
569
- fi
570
- fi
571
- fi
572
- done
465
+if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
466
+
467
+ progress "Backup existing netdata configuration before installing it"
468
+
469
+ if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
470
+ declare -A configs_signatures=()
471
+ if [ -f "configs.signatures" ]; then
472
+ source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
473
+ fi
474
+ fi
475
+
476
+ config_signature_matches() {
477
+ local md5="${1}" file="${2}"
478
+
479
+ if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
480
+ [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
481
+ return 1
482
+ fi
483
+
484
+ if [ -f "configs.signatures" ]; then
485
+ grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
486
+ return $?
487
+ fi
488
+
489
+ return 1
490
+ }
491
+
492
+ # clean up stock config files from the user configuration directory
493
+ for x in $(find -L "${NETDATA_PREFIX}/etc/netdata" -type f); do
494
+ if [ -f "${x}" ]; then
495
+ # find it relative filename
496
+ f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}"
497
+
498
+ # find the stock filename
499
+ t="${f/.conf.installer_backup.*/.conf}"
500
+ t="${t/.conf.old/.conf}"
501
+ t="${t/.conf.orig/.conf}"
502
+
503
+ if [ -z "${md5sum}" -o ! -x "${md5sum}" ]; then
504
+ # we don't have md5sum - keep it
505
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
506
+ else
507
+ # find its checksum
508
+ md5="$(${md5sum} <"${x}" | cut -d ' ' -f 1)"
509
+
510
+ if config_signature_matches "${md5}" "${t}"; then
511
+ # it is a stock version - remove it
512
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
513
+ run rm -f "${x}"
514
+ deleted_stock_configs=$((deleted_stock_configs + 1))
515
+ else
516
+ # edited by user - keep it
517
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of '${t}'${TPUT_RESET}. Keeping it."
518
+ fi
519
+ fi
520
+ fi
521
+ done
522
fi
523
touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
524
@@ -578,13 +527,11 @@ progress "Install netdata"
527
528
run make install || exit 1
529
581
-
530
# -----------------------------------------------------------------------------
531
progress "Fix generated files permissions"
532
533
run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
534
587
-
535
# -----------------------------------------------------------------------------
536
progress "Add user netdata to required user groups"
537
@@ -592,68 +539,63 @@ homedir="${NETDATA_PREFIX}/var/lib/netdata"
539
[ ! -z "${NETDATA_PREFIX}" ] && homedir="${NETDATA_PREFIX}"
540
add_netdata_user_and_group "${homedir}" || run_failed "The installer does not run as root."
541
595
-
542
# -----------------------------------------------------------------------------
543
progress "Install logrotate configuration for netdata"
544
545
install_netdata_logrotate
546
601
-
547
# -----------------------------------------------------------------------------
548
progress "Read installation options from netdata.conf"
549
550
# create an empty config if it does not exist
606
-[ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
607
- touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
551
+[ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
552
+ touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
553
554
# function to extract values from the config file
555
config_option() {
611
- local section="${1}" key="${2}" value="${3}"
612
-
613
- if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
614
- then
615
- "${NETDATA_PREFIX}/usr/sbin/netdata" \
616
- -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
617
- -W get "${section}" "${key}" "${value}" || \
618
- echo "${value}"
619
- else
620
- echo "${value}"
621
- fi
556
+ local section="${1}" key="${2}" value="${3}"
557
+
558
+ if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
559
+ "${NETDATA_PREFIX}/usr/sbin/netdata" \
560
+ -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
561
+ -W get "${section}" "${key}" "${value}" ||
562
+ echo "${value}"
563
+ else
564
+ echo "${value}"
565
+ fi
566
}
567
568
# the user netdata will run as
625
-if [ "${UID}" = "0" ]
626
- then
627
- NETDATA_USER="$( config_option "global" "run as user" "netdata" )"
628
- ROOT_USER="root"
569
+if [ "${UID}" = "0" ]; then
570
+ NETDATA_USER="$(config_option "global" "run as user" "netdata")"
571
+ ROOT_USER="root"
572
else
630
- NETDATA_USER="${USER}"
631
- ROOT_USER="${NETDATA_USER}"
573
+ NETDATA_USER="${USER}"
574
+ ROOT_USER="${NETDATA_USER}"
575
fi
576
NETDATA_GROUP="$(id -g -n ${NETDATA_USER})"
577
[ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
578
579
# the owners of the web files
637
-NETDATA_WEB_USER="$( config_option "web" "web files owner" "${NETDATA_USER}" )"
580
+NETDATA_WEB_USER="$(config_option "web" "web files owner" "${NETDATA_USER}")"
581
NETDATA_WEB_GROUP="${NETDATA_GROUP}"
639
-if [ "${UID}" = "0" -a "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]
640
-then
641
- NETDATA_WEB_GROUP="$(id -g -n ${NETDATA_WEB_USER})"
642
- [ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
582
+if [ "${UID}" = "0" -a "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
583
+ NETDATA_WEB_GROUP="$(id -g -n ${NETDATA_WEB_USER})"
584
+ [ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
585
fi
644
-NETDATA_WEB_GROUP="$( config_option "web" "web files group" "${NETDATA_WEB_GROUP}" )"
586
+NETDATA_WEB_GROUP="$(config_option "web" "web files group" "${NETDATA_WEB_GROUP}")"
587
588
# port
589
defport=19999
648
-NETDATA_PORT="$( config_option "web" "default port" ${defport} )"
590
+NETDATA_PORT="$(config_option "web" "default port" ${defport})"
591
592
# directories
651
-NETDATA_LIB_DIR="$( config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
652
-NETDATA_CACHE_DIR="$( config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
653
-NETDATA_WEB_DIR="$( config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
654
-NETDATA_LOG_DIR="$( config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
655
-NETDATA_USER_CONFIG_DIR="$( config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
656
-NETDATA_STOCK_CONFIG_DIR="$( config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d" )"
593
+NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
594
+NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
595
+NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
596
+NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
597
+NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
598
+NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
599
NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
600
601
cat <<OPTIONSEOF
@@ -682,21 +624,18 @@ OPTIONSEOF
624
# -----------------------------------------------------------------------------
625
progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
626
685
-if [ ! -d "${NETDATA_RUN_DIR}" ]
686
- then
687
- # this is needed if NETDATA_PREFIX is not empty
688
- run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
627
+if [ ! -d "${NETDATA_RUN_DIR}" ]; then
628
+ # this is needed if NETDATA_PREFIX is not empty
629
+ run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
630
fi
631
632
# --- conf dir ----
633
693
-for x in "python.d" "charts.d" "node.d" "health.d" "statsd.d"
694
-do
695
- if [ ! -d "${NETDATA_USER_CONFIG_DIR}/${x}" ]
696
- then
697
- echo >&2 "Creating directory '${NETDATA_USER_CONFIG_DIR}/${x}'"
698
- run mkdir -p "${NETDATA_USER_CONFIG_DIR}/${x}" || exit 1
699
- fi
634
+for x in "python.d" "charts.d" "node.d" "health.d" "statsd.d"; do
635
+ if [ ! -d "${NETDATA_USER_CONFIG_DIR}/${x}" ]; then
636
+ echo >&2 "Creating directory '${NETDATA_USER_CONFIG_DIR}/${x}'"
637
+ run mkdir -p "${NETDATA_USER_CONFIG_DIR}/${x}" || exit 1
638
+ fi
639
done
640
run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}"
641
run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
@@ -709,13 +648,11 @@ run chmod 755 "${NETDATA_USER_CONFIG_DIR}/edit-config"
648
649
helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
650
[ ${deleted_stock_configs} -eq 0 ] && helplink=""
712
-for link in "orig" "${helplink}"
713
-do
714
- if [ ! -z "${link}" ]
715
- then
716
- [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
717
- run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
718
- fi
651
+for link in "orig" "${helplink}"; do
652
+ if [ ! -z "${link}" ]; then
653
+ [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
654
+ run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
655
+ fi
656
done
657
run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
658
run find "${NETDATA_STOCK_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
@@ -723,10 +660,9 @@ run find "${NETDATA_STOCK_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
660
661
# --- web dir ----
662
726
-if [ ! -d "${NETDATA_WEB_DIR}" ]
727
- then
728
- echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
729
- run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
663
+if [ ! -d "${NETDATA_WEB_DIR}" ]; then
664
+ echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
665
+ run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
666
fi
667
run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
668
run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
@@ -734,144 +670,127 @@ run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
670
671
# --- data dirs ----
672
737
-for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
738
-do
739
- if [ ! -d "${x}" ]
740
- then
741
- echo >&2 "Creating directory '${x}'"
742
- run mkdir -p "${x}" || exit 1
743
- fi
744
-
745
- run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
746
- #run find "${x}" -type f -exec chmod 0660 {} \;
747
- #run find "${x}" -type d -exec chmod 0770 {} \;
673
+for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
674
+ if [ ! -d "${x}" ]; then
675
+ echo >&2 "Creating directory '${x}'"
676
+ run mkdir -p "${x}" || exit 1
677
+ fi
678
+
679
+ run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
680
+ #run find "${x}" -type f -exec chmod 0660 {} \;
681
+ #run find "${x}" -type d -exec chmod 0770 {} \;
682
done
683
684
run chmod 755 "${NETDATA_LOG_DIR}"
685
686
# --- plugins ----
687
754
-if [ ${UID} -eq 0 ]
755
- then
756
- # find the admin group
757
- admin_group=
758
- test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
759
- test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
760
- test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
761
-
762
- run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
763
- run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
764
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
765
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
766
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
767
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
768
-
769
- if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]
770
- then
771
- setcap_ret=1
772
- if ! iscontainer
773
- then
774
- if [ ! -z "${setcap}" ]
775
- then
776
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
777
- run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
778
- run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
779
- setcap_ret=$?
780
- fi
781
-
782
- if [ ${setcap_ret} -eq 0 ]
783
- then
784
- # if we managed to setcap
785
- # but we fail to execute apps.plugin
786
- # trigger setuid to root
787
- "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
788
- setcap_ret=$?
789
- fi
790
- fi
791
-
792
- if [ ${setcap_ret} -ne 0 ]
793
- then
794
- # fix apps.plugin to be setuid to root
795
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
796
- run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
797
- fi
798
- fi
799
-
800
- if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]
801
- then
802
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
803
- run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
804
- fi
805
-
806
- if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]
807
- then
808
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
809
- run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
810
- fi
811
-
812
- if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]
813
- then
814
- run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
815
- run chmod 0550 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
816
- fi
688
+if [ ${UID} -eq 0 ]; then
689
+ # find the admin group
690
+ admin_group=
691
+ test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
692
+ test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
693
+ test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
694
+
695
+ run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
696
+ run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
697
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
698
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
699
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
700
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
701
+
702
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
703
+ setcap_ret=1
704
+ if ! iscontainer; then
705
+ if [ ! -z "${setcap}" ]; then
706
+ run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
707
+ run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
708
+ run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
709
+ setcap_ret=$?
710
+ fi
711
+
712
+ if [ ${setcap_ret} -eq 0 ]; then
713
+ # if we managed to setcap
714
+ # but we fail to execute apps.plugin
715
+ # trigger setuid to root
716
+ "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
717
+ setcap_ret=$?
718
+ fi
719
+ fi
720
+
721
+ if [ ${setcap_ret} -ne 0 ]; then
722
+ # fix apps.plugin to be setuid to root
723
+ run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
724
+ run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
725
+ fi
726
+ fi
727
+
728
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
729
+ run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
730
+ run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
731
+ fi
732
+
733
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
734
+ run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
735
+ run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
736
+ fi
737
+
738
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
739
+ run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
740
+ run chmod 0550 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
741
+ fi
742
743
else
819
- # non-privileged user installation
820
- run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
821
- run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
822
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
823
- run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
744
+ # non-privileged user installation
745
+ run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
746
+ run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
747
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
748
+ run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
749
fi
750
751
# --- fix #1292 bug ---
752
828
-[ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
753
+[ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
754
[ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
755
831
-
832
-
756
# -----------------------------------------------------------------------------
757
progress "Install netdata at system init"
758
759
NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
760
install_netdata_service || run_failed "Cannot install netdata init service."
761
839
-
762
# -----------------------------------------------------------------------------
763
# check if we can re-start netdata
764
765
started=0
844
-if [ ${DONOTSTART} -eq 1 ]
845
- then
846
- generate_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
766
+if [ ${DONOTSTART} -eq 1 ]; then
767
+ generate_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
768
769
else
849
- restart_netdata ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
850
- if [ $? -ne 0 ]
851
- then
852
- echo >&2
853
- echo >&2 "SORRY! FAILED TO START NETDATA!"
854
- echo >&2
855
- exit 1
856
- fi
857
-
858
- started=1
859
- echo >&2 "OK. NetData Started!"
860
- echo >&2
861
-
862
- # -----------------------------------------------------------------------------
863
- # save a config file, if it is not already there
864
-
865
- download_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
770
+ restart_netdata ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
771
+ if [ $? -ne 0 ]; then
772
+ echo >&2
773
+ echo >&2 "SORRY! FAILED TO START NETDATA!"
774
+ echo >&2
775
+ exit 1
776
+ fi
777
+
778
+ started=1
779
+ echo >&2 "OK. NetData Started!"
780
+ echo >&2
781
+
782
+ # -----------------------------------------------------------------------------
783
+ # save a config file, if it is not already there
784
+
785
+ download_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
786
fi
787
868
-if [ "$(uname)" = "Linux" ]
869
-then
870
- # -------------------------------------------------------------------------
871
- progress "Check KSM (kernel memory deduper)"
788
+if [ "$(uname)" = "Linux" ]; then
789
+ # -------------------------------------------------------------------------
790
+ progress "Check KSM (kernel memory deduper)"
791
873
- ksm_is_available_but_disabled() {
874
- cat <<KSM1
792
+ ksm_is_available_but_disabled() {
793
+ cat <<KSM1
794
795
${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
796
@@ -886,10 +805,10 @@ To enable it run:
805
If you enable it, you will save 40-60% of netdata memory.
806
807
KSM1
889
- }
808
+ }
809
891
- ksm_is_not_available() {
892
- cat <<KSM2
810
+ ksm_is_not_available() {
811
+ cat <<KSM2
812
813
${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
814
@@ -901,26 +820,22 @@ To enable it, you need a kernel built with CONFIG_KSM=y
820
If you can have it, you will save 40-60% of netdata memory.
821
822
KSM2
904
- }
905
-
906
- if [ -f "/sys/kernel/mm/ksm/run" ]
907
- then
908
- if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
909
- then
910
- ksm_is_available_but_disabled
911
- fi
912
- else
913
- ksm_is_not_available
914
- fi
915
-fi
823
+ }
824
825
+ if [ -f "/sys/kernel/mm/ksm/run" ]; then
826
+ if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]; then
827
+ ksm_is_available_but_disabled
828
+ fi
829
+ else
830
+ ksm_is_not_available
831
+ fi
832
+fi
833
834
# -----------------------------------------------------------------------------
835
progress "Check version.txt"
836
921
-if [ ! -s webserver/gui/version.txt ]
922
- then
923
- cat <<VERMSG
837
+if [ ! -s webserver/gui/version.txt ]; then
838
+ cat <<VERMSG
839
840
${TPUT_BOLD}Version update check warning${TPUT_RESET}
841
@@ -935,14 +850,12 @@ https://github.com/netdata/netdata/tree/master/installer#installation
850
VERMSG
851
fi
852
938
-if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]
939
-then
940
- # -----------------------------------------------------------------------------
941
- progress "Check apps.plugin"
853
+if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
854
+ # -----------------------------------------------------------------------------
855
+ progress "Check apps.plugin"
856
943
- if [ "${UID}" -ne 0 ]
944
- then
945
- cat <<SETUID_WARNING
857
+ if [ "${UID}" -ne 0 ]; then
858
+ cat <<SETUID_WARNING
859
860
${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
861
@@ -966,120 +879,13 @@ running processes. It cannot be instructed from the netdata daemon to perform
879
any task, so it is pretty safe to do this.
880
881
SETUID_WARNING
969
- fi
882
+ fi
883
fi
884
885
# -----------------------------------------------------------------------------
973
-progress "Generate netdata-uninstaller.sh"
974
-
975
-cat >netdata-uninstaller.sh <<UNINSTALL
976
-#!/usr/bin/env bash
977
-
978
-# this script will uninstall netdata
979
-
980
-if [ "\$1" != "--force" ]
981
- then
982
- echo >&2 "This script will REMOVE netdata from your system."
983
- echo >&2 "Run it again with --force to do it."
984
- exit 1
985
-fi
986
-
987
-source installer/functions.sh || exit 1
988
-
989
-echo >&2 "Stopping a possibly running netdata..."
990
-for p in \$(pidof netdata); do run kill \$p; done
991
-sleep 2
992
-
993
-if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
994
- then
995
- # installation prefix was given
996
-
997
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}"
998
-
999
-else
1000
- # installation prefix was NOT given
1001
-
1002
- if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1003
- then
1004
- echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1005
- run rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1006
- fi
1007
-
1008
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/etc/netdata"
1009
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/share/netdata"
1010
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/libexec/netdata"
1011
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/lib/netdata"
1012
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/cache/netdata"
1013
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/log/netdata"
1014
-fi
1015
-
1016
-if [ -f /etc/logrotate.d/netdata ]
1017
- then
1018
- echo "Deleting /etc/logrotate.d/netdata ..."
1019
- run rm -i /etc/logrotate.d/netdata
1020
-fi
1021
-
1022
-if [ -f /etc/systemd/system/netdata.service ]
1023
- then
1024
- echo "Deleting /etc/systemd/system/netdata.service ..."
1025
- run rm -i /etc/systemd/system/netdata.service
1026
-fi
1027
-
1028
-if [ -f /lib/systemd/system/netdata.service ]
1029
- then
1030
- echo "Deleting /lib/systemd/system/netdata.service ..."
1031
- run rm -i /lib/systemd/system/netdata.service
1032
-fi
1033
-
1034
-if [ -f /etc/init.d/netdata ]
1035
- then
1036
- echo "Deleting /etc/init.d/netdata ..."
1037
- run rm -i /etc/init.d/netdata
1038
-fi
1039
-
1040
-if [ -f /etc/periodic/daily/netdata-updater ]
1041
- then
1042
- echo "Deleting /etc/periodic/daily/netdata-updater ..."
1043
- run rm -i /etc/periodic/daily/netdata-updater
1044
-fi
1045
-
1046
-if [ -f /etc/cron.daily/netdata-updater ]
1047
- then
1048
- echo "Deleting /etc/cron.daily/netdata-updater ..."
1049
- run rm -i /etc/cron.daily/netdata-updater
1050
-fi
1051
-
1052
-portable_check_user_exists netdata
1053
-if [ \$? -eq 0 ]
1054
- then
1055
- echo
1056
- echo "You may also want to remove the user netdata"
1057
- echo "by running:"
1058
- echo " userdel netdata"
1059
-fi
886
+progress "Create netdata-uninstaller.sh"
887
1061
-portable_check_group_exists netdata > /dev/null
1062
-if [ \$? -eq 0 ]
1063
- then
1064
- echo
1065
- echo "You may also want to remove the group netdata"
1066
- echo "by running:"
1067
- echo " groupdel netdata"
1068
-fi
1069
-
1070
-for g in ${NETDATA_ADDED_TO_GROUPS}
1071
-do
1072
- portable_check_group_exists \$g > /dev/null
1073
- if [ \$? -eq 0 ]
1074
- then
1075
- echo
1076
- echo "You may also want to remove the netdata user from the \$g group"
1077
- echo "by running:"
1078
- echo " gpasswd -d netdata \$g"
1079
- fi
1080
-done
1081
-
1082
-UNINSTALL
888
+cp ./installer/netdata-uninstaller.sh netdata-uninstaller.sh
889
chmod 750 netdata-uninstaller.sh
890
891
# -----------------------------------------------------------------------------
@@ -1102,184 +908,73 @@ To start netdata run:
908
909
910
END
1105
-echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
1106
-
1107
-if [ -d .git ]
1108
- then
1109
- cat >netdata-updater.sh.new <<REINSTALL
1110
-#!/usr/bin/env bash
1111
-
1112
-force=0
1113
-[ "\${1}" = "-f" ] && force=1
1114
-
1115
-export PATH="\${PATH}:${PATH}"
1116
-export CFLAGS="${CFLAGS}"
1117
-export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
1118
-
1119
-# make sure we have a UID
1120
-[ -z "\${UID}" ] && UID="\$(id -u)"
1121
-INSTALL_UID="${UID}"
1122
-if [ "\${INSTALL_UID}" != "\${UID}" ]
1123
- then
1124
-echo >&2 "You are running this script as user with uid \${UID}. We recommend to run this script as root (user with uid 0)"
1125
- exit 1
1126
-fi
1127
-
1128
-# make sure we cd to the working directory
1129
-cd "${REINSTALL_PWD}" || exit 1
1130
-
1131
-# make sure there is .git here
1132
-[ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1133
-
1134
-# signal netdata to start saving its database
1135
-# this is handy if your database is big
1136
-pids=\$(pidof netdata)
1137
-do_not_start=
1138
-if [ ! -z "\${pids}" ]
1139
- then
1140
- kill -USR1 \${pids}
911
+echo >&2 "Uninstall script is located at: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
912
+
913
+if [ -d .git ]; then
914
+ cp ./installer/netdata-updater.sh netdata-updater.sh
915
+ sed -i "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${REINSTALL_PWD}|" netdata-updater.sh
916
+ chmod 755 netdata-updater.sh
917
+ echo >&2 "Update script is located at: ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
918
+ echo >&2
919
+ echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
920
+ echo >&2 "only if it fails (it does not print anything when it can update netdata).${TPUT_RESET}"
921
+ if [ "${UID}" -eq "0" ]; then
922
+ crondir=
923
+ [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
924
+ [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
925
+
926
+ if [ ! -z "${crondir}" ]; then
927
+ if [ -f "${crondir}/netdata-updater.sh" -a ! -f "${crondir}/netdata-updater" ]; then
928
+ # remove .sh from the filename under cron
929
+ progress "Fixing netdata-updater filename at cron"
930
+ mv -f "${crondir}/netdata-updater.sh" "${crondir}/netdata-updater"
931
+ fi
932
+
933
+ if [ ! -f "${crondir}/netdata-updater" ]; then
934
+ if [ "${AUTOUPDATE}" = "1" ]; then
935
+ progress "Installing netdata-updater at cron"
936
+ run ln -fs "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater"
937
+ else
938
+ echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
939
+ echo >&2
940
+ echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}sudo ln -fs ${PWD}/netdata-updater.sh ${crondir}/netdata-updater${TPUT_RESET}"
941
+ fi
942
+ else
943
+ progress "Refreshing netdata-updater at cron"
944
+ run rm "${crondir}/netdata-updater"
945
+ run ln -fs "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater"
946
+ fi
947
+ else
948
+ [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Cannot figure out the cron directory to install netdata-updater."
949
+ fi
950
+ else
951
+ [ "${AUTOUPDATE}" = "1" ] && echo >&2 "You need to run the installer as root for auto-updating via cron."
952
+ fi
953
else
1142
- # netdata is currently not running, so do not start it after updating
1143
- do_not_start="--dont-start-it"
954
+ [ -f "netdata-updater.sh" ] && rm "netdata-updater.sh"
955
+ [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Your installation method does not support daily auto-updating via cron."
956
fi
957
1146
-tmp=
1147
-if [ -t 2 ]
1148
- then
1149
- # we are running on a terminal
1150
- # open fd 3 and send it to stderr
1151
- exec 3>&2
1152
-else
1153
- # we are headless
1154
- # create a temporary file for the log
1155
- tmp=\$(mktemp /tmp/netdata-updater.log.XXXXXX)
1156
- # open fd 3 and send it to tmp
1157
- exec 3>\${tmp}
1158
-fi
1159
-
1160
-info() {
1161
- echo >&3 "\$(date) : INFO: " "\${@}"
1162
-}
1163
-
1164
-emptyline() {
1165
- echo >&3
1166
-}
1167
-
1168
-error() {
1169
- echo >&3 "\$(date) : ERROR: " "\${@}"
1170
-}
1171
-
1172
-# this is what we will do if it fails (head-less only)
1173
-failed() {
1174
- error "FAILED TO UPDATE NETDATA : \${1}"
1175
-
1176
- if [ ! -z "\${tmp}" ]
1177
- then
1178
- cat >&2 "\${tmp}"
1179
- rm "\${tmp}"
1180
- fi
1181
- exit 1
1182
-}
1183
-
1184
-get_latest_commit_id() {
1185
- git rev-parse HEAD 2>&3
1186
-}
1187
-
1188
-update() {
1189
- [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1190
-
1191
- emptyline
1192
-
1193
- if [ -d .git ]
1194
- then
1195
- info "Updating netdata source from github..."
1196
-
1197
- last_commit="\$(get_latest_commit_id)"
1198
- [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1199
-
1200
- git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1201
-
1202
- new_commit="\$(get_latest_commit_id)"
1203
- if [ \${force} -eq 0 ]
1204
- then
1205
- [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1206
- [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1207
- fi
1208
- elif [ \${force} -eq 0 ]
1209
- then
1210
- failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1211
- fi
1212
-
1213
- emptyline
1214
- info "Re-installing netdata..."
1215
- ${REINSTALL_COMMAND} --dont-wait \${do_not_start} >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1216
-
1217
- [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1218
- return 0
1219
-}
1220
-
1221
-# the installer updates this script - so we run and exit in a single line
1222
-update && exit 0
1223
-###############################################################################
1224
-###############################################################################
1225
-REINSTALL
1226
- chmod 755 netdata-updater.sh.new
1227
- mv -f netdata-updater.sh.new netdata-updater.sh
1228
- echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
1229
- echo >&2
1230
- echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
1231
- echo >&2 "only if it fails (it does not print anything when it can update netdata).${TPUT_RESET}"
1232
- if [ "${UID}" -eq "0" ]
1233
- then
1234
- crondir=
1235
- [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
1236
- [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
1237
-
1238
- if [ ! -z "${crondir}" ]
1239
- then
1240
- if [ -f "${crondir}/netdata-updater.sh" -a ! -f "${crondir}/netdata-updater" ]
1241
- then
1242
- # remove .sh from the filename under cron
1243
- progress "Fixing netdata-updater filename at cron"
1244
- mv -f "${crondir}/netdata-updater.sh" "${crondir}/netdata-updater"
1245
- fi
1246
-
1247
- if [ ! -f "${crondir}/netdata-updater" ]
1248
- then
1249
- if [ "${AUTOUPDATE}" = "1" ]
1250
- then
1251
- progress "Installing netdata-updater at cron"
1252
- run ln -fs "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater"
1253
- else
1254
- echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1255
- echo >&2
1256
- echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}sudo ln -fs ${PWD}/netdata-updater.sh ${crondir}/netdata-updater${TPUT_RESET}"
1257
- fi
1258
- else
1259
- progress "Refreshing netdata-updater at cron"
1260
- run rm "${crondir}/netdata-updater"
1261
- run ln -fs "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater"
1262
- fi
1263
- else
1264
- [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Cannot figure out the cron directory to install netdata-updater."
1265
- fi
1266
- else
1267
- [ "${AUTOUPDATE}" = "1" ] && echo >&2 "You need to run the installer as root for auto-updating via cron."
1268
- fi
1269
-else
1270
- [ -f "netdata-updater.sh" ] && rm "netdata-updater.sh"
1271
- [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Your installation method does not support daily auto-updating via cron."
1272
-fi
958
+# Save environment variables
959
+cat <<EOF > installer/.environment.sh
960
+PATH="${PATH}"
961
+CFLAGS="${CFLAGS}"
962
+NETDATA_PREFIX="${NETDATA_PREFIX}"
963
+NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
964
+NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
965
+INSTALL_UID="${UID}"
966
+REINSTALL_PWD="${REINSTALL_PWD}"
967
+REINSTALL_COMMAND="${REINSTALL_COMMAND}"
968
+EOF
969
970
# -----------------------------------------------------------------------------
971
echo >&2
972
progress "We are done!"
973
1278
-if [ ${started} -eq 1 ]
1279
- then
1280
- netdata_banner "is installed and running now!"
974
+if [ ${started} -eq 1 ]; then
975
+ netdata_banner "is installed and running now!"
976
else
1282
- netdata_banner "is installed now!"
977
+ netdata_banner "is installed now!"
978
fi
979
980
echo >&2 " enjoy real-time performance and health monitoring..."