1
#!/usr/bin/env bash
2
# SPDX-License-Identifier: GPL-3.0-or-later
3
-# shellcheck disable=SC1090,SC1091,SC1117,SC2002,SC2034,SC2044,SC2046,SC2086,SC2129,SC2162,SC2166,SC2181
3
+# shellcheck disable=SC2046,SC2086,SC2166
4
5
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
6
uniquepath() {
7
local path=""
8
- while read; do
8
+ while read -r; do
9
if [[ ! ${path} =~ (^|:)"${REPLY}"(:|$) ]]; then
10
- [ ! -z "${path}" ] && path="${path}:"
10
+ [ -n "${path}" ] && path="${path}:"
11
path="${path}${REPLY}"
12
fi
13
- done < <(echo "${PATH}" | tr ":" "\n")
13
+ done < <(echo "${PATH}" | tr ":" "\\n")
14
15
- [ ! -z "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
15
+ [ -n "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
16
}
17
uniquepath
18
19
-netdata_source_dir="$(pwd)"
20
-installer_dir="$(dirname "${0}")"
19
+PROGRAM="$0"
20
+NETDATA_SOURCE_DIR="$(pwd)"
21
+INSTALLER_DIR="$(dirname "${PROGRAM}")"
22
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}'."
23
+if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
24
+ echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
25
fi
26
27
# -----------------------------------------------------------------------------
28
# reload the user profile
29
30
+# shellcheck source=/dev/null
31
[ -f /etc/profile ] && . /etc/profile
32
33
# make sure /etc/profile does not change our current directory
32
-cd "${netdata_source_dir}" || exit 1
34
+cd "${NETDATA_SOURCE_DIR}" || exit 1
35
36
# -----------------------------------------------------------------------------
37
# load the required functions
38
37
-if [ -f "${installer_dir}/packaging/installer/functions.sh" ]; then
38
- source "${installer_dir}/packaging/installer/functions.sh" || exit 1
39
+if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
40
+ # shellcheck source=packaging/installer/functions.sh
41
+ source "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
42
else
40
- source "${netdata_source_dir}/packaging/installer/functions.sh" || exit 1
43
+ # shellcheck source=packaging/installer/functions.sh
44
+ source "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
45
fi
46
47
download() {
78
[ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
79
80
# keep a log of this command
77
-printf "\n# " >>netdata-installer.log
81
+# shellcheck disable=SC2129
82
+printf "\\n# " >>netdata-installer.log
83
date >>netdata-installer.log
84
printf 'CFLAGS="%s" ' "${CFLAGS}" >>netdata-installer.log
80
-printf "%q " "$0" "${@}" >>netdata-installer.log
81
-printf "\n" >>netdata-installer.log
85
+printf "%q " "${PROGRAM}" "${@}" >>netdata-installer.log
86
+printf "\\n" >>netdata-installer.log
87
83
-REINSTALL_PWD="${PWD}"
88
REINSTALL_COMMAND="$(
85
- printf "%q " "$0" "${@}"
86
- printf "\n"
89
+ printf "%q " "${PROGRAM}" "${@}"
90
+ printf "\\n"
91
)"
92
# remove options that shown not be inherited by netdata-updater.sh
93
REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}"
94
REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-start-it/}"
91
-[ "${REINSTALL_COMMAND:0:1}" != "." -a "${REINSTALL_COMMAND:0:1}" != "/" -a -f "./${0}" ] && REINSTALL_COMMAND="./${REINSTALL_COMMAND}"
92
-
93
-# shellcheck disable=SC2230
94
-setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)"
95
-
96
-ME="$0"
97
-DONOTSTART=0
98
-DONOTWAIT=0
99
-AUTOUPDATE=0
100
-NETDATA_PREFIX=
101
-LIBS_ARE_HERE=0
102
-NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
103
-RELEASE_CHANNEL="nightly"
104
-
105
-usage() {
106
- netdata_banner "installer command line options"
107
- cat <<USAGE
108
-
109
-${ME} <installer options>
110
-
111
-Valid <installer options> are:
112
-
113
- --install /PATH/TO/INSTALL
114
-
115
- If you give: --install /opt
116
- netdata will be installed in /opt/netdata
117
-
118
- --dont-start-it
119
-
120
- Do not (re)start netdata.
121
- Just install it.
122
-
123
- --dont-wait
124
-
125
- Do not wait for the user to press ENTER.
126
- Start immediately building it.
127
-
128
- --auto-update | -u
129
-
130
- Install netdata-updater to cron,
131
- to update netdata automatically once per day
132
-
133
- --stable-channel
134
-
135
- Auto-updater will update netdata only when new release is published
136
- in GitHub release pages. This results in less frequent updates.
137
- Default: Use packages from GCS (nightly release channel).
138
-
139
- --enable-plugin-freeipmi
140
- --disable-plugin-freeipmi
95
+if [ "${REINSTALL_COMMAND:0:1}" != "." ] && [ "${REINSTALL_COMMAND:0:1}" != "/" ] && [ -f "./${PROGRAM}" ]; then
96
+ REINSTALL_COMMAND="./${REINSTALL_COMMAND}"
97
+fi
98
142
- Enable/disable the FreeIPMI plugin.
143
- Default: enable it when libipmimonitoring is available.
99
+banner_nonroot_install() {
100
+ cat <<NONROOTNOPREFIX
101
145
- --enable-plugin-nfacct
146
- --disable-plugin-nfacct
102
+ ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
103
148
- Enable/disable the nfacct plugin.
149
- Default: enable it when libmnl and libnetfilter_acct are available.
104
+ You are attempting to install netdata as non-root, but you plan
105
+ to install it in system paths.
106
151
- --enable-plugin-xenstat
152
- --disable-plugin-xenstat
107
+ Please set an installation prefix, like this:
108
154
- Enable/disable the xenstat plugin.
155
- Default: enable it when libxenstat and libyajl are available.
109
+ $PROGRAM ${@} --install /tmp
110
157
- --enable-lto
158
- --disable-lto
111
+ or, run the installer as root:
112
160
- Enable/disable Link-Time-Optimization
161
- Default: enabled
113
+ sudo $PROGRAM ${@}
114
163
- --disable-x86-sse
115
+ We suggest to install it as root, or certain data collectors will
116
+ not be able to work. Netdata drops root privileges when running.
117
+ So, if you plan to keep it, install it as root to get the full
118
+ functionality.
119
165
- Disable SSE instructions
166
- Default: enabled
120
+NONROOTNOPREFIX
121
+}
122
168
- --zlib-is-really-here
169
- --libs-are-really-here
123
+banner_root_notify() {
124
+ cat <<NONROOT
125
171
- If you get errors about missing zlib,
172
- or libuuid but you know it is available,
173
- you have a broken pkg-config.
174
- Use this option to allow it continue
175
- without checking pkg-config.
126
+ ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
127
+ You are about to install netdata as a non-root user.
128
+ Netdata will work, but a few data collection modules that
129
+ require root access will fail.
130
177
- --disable-telemetry
131
+ If you installing netdata permanently on your system, run
132
+ the installer like this:
133
179
- Use this flag to opt-out from our anonymous telemetry progam.
134
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
135
181
- --disable-go
136
+NONROOT
137
+}
138
183
- Flag to disable installation of go.d.plugin
139
+usage() {
140
+ netdata_banner "installer command line options"
141
+ cat <<HEREDOC
142
+
143
+USAGE: ${PROGRAM} [options]
144
+ where options include:
145
+
146
+ --install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata
147
+ --dont-start-it Do not (re)start netdata after installation
148
+ --dont-wait Run installation in non-interactive mode
149
+ --auto-update or -u Install netdata-updater in cron to update netdata automatically once per day
150
+ --stable-channel Use packages from GitHub release pages instead of GCS (nightly updates).
151
+ This results in less frequent updates.
152
+ --disable-go Disable installation of go.d.plugin.
153
+ --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
154
+ --disable-plugin-freeipmi
155
+ --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
156
+ --disable-plugin-nfacct
157
+ --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available
158
+ --disable-plugin-xenstat Disable the xenstat plugin.
159
+ --enable-lto Enable Link-Time-Optimization. Default: enabled
160
+ --disable-lto
161
+ --disable-x86-sse Disable SSE instructions. By default SSE optimizations are enabled.
162
+ --zlib-is-really-here or
163
+ --libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might
164
+ have a broken pkg-config. Use this option to proceed without checking pkg-config.
165
+ --disable-telemetry Use this flag to opt-out from our anonymous telemetry progam.
166
167
Netdata will by default be compiled with gcc optimization -O2
168
If you need to pass different CFLAGS, use something like this:
169
188
- CFLAGS="<gcc options>" ${ME} <installer options>
170
+ CFLAGS="<gcc options>" ${PROGRAM} [options]
171
190
-For the installer to complete successfully, you will need
191
-these packages installed:
172
+For the installer to complete successfully, you will need these packages installed:
173
193
- gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
194
- uuid-dev (or libuuid-devel)
174
+ gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel) uuid-dev (or libuuid-devel)
175
176
For the plugins, you will at least need:
177
198
- curl, bash v4+, python v2 or v3, node.js
178
+ curl, bash v4+, python v2 or v3, node.js
179
200
-USAGE
180
+HEREDOC
181
}
182
203
-while [ ! -z "${1}" ]; do
204
- if [ "$1" = "--install" ]; then
205
- NETDATA_PREFIX="${2}/netdata"
206
- shift 2
207
- elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]; then
208
- LIBS_ARE_HERE=1
209
- shift 1
210
- elif [ "$1" = "--dont-start-it" ]; then
211
- DONOTSTART=1
212
- shift 1
213
- elif [ "$1" = "--dont-wait" ]; then
214
- DONOTWAIT=1
215
- shift 1
216
- elif [ "$1" = "--auto-update" -o "$1" = "-u" ]; then
217
- AUTOUPDATE=1
218
- shift 1
219
- elif [ "$1" = "--stable-channel" ]; then
220
- RELEASE_CHANNEL="stable"
221
- shift 1
222
- elif [ "$1" = "--enable-plugin-freeipmi" ]; then
223
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi"
224
- shift 1
225
- elif [ "$1" = "--disable-plugin-freeipmi" ]; then
226
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi"
227
- shift 1
228
- elif [ "$1" = "--enable-plugin-nfacct" ]; then
229
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct"
230
- shift 1
231
- elif [ "$1" = "--disable-plugin-nfacct" ]; then
232
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct"
233
- shift 1
234
- elif [ "$1" = "--enable-plugin-xenstat" ]; then
235
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat"
236
- shift 1
237
- elif [ "$1" = "--disable-plugin-xenstat" ]; then
238
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-xenstat/} --disable-plugin-xenstat"
239
- shift 1
240
- elif [ "$1" = "--enable-lto" ]; then
241
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto"
242
- shift 1
243
- elif [ "$1" = "--disable-lto" ]; then
244
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto"
245
- shift 1
246
- elif [ "$1" = "--disable-x86-sse" ]; then
247
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse"
248
- shift 1
249
- elif [ "$1" = "--disable-telemetry" ]; then
250
- NETDATA_DISABLE_TELEMETRY=1
251
- shift 1
252
- elif [ "$1" = "--disable-go" ]; then
253
- NETDATA_DISABLE_GO=1
254
- shift 1
255
- elif [ "$1" = "--help" -o "$1" = "-h" ]; then
256
- usage
257
- exit 1
258
- else
259
- echo >&2
260
- echo >&2 "ERROR:"
261
- echo >&2 "I cannot understand option '$1'."
262
- usage
263
- exit 1
264
- fi
183
+DONOTSTART=0
184
+DONOTWAIT=0
185
+AUTOUPDATE=0
186
+NETDATA_PREFIX=
187
+LIBS_ARE_HERE=0
188
+NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
189
+RELEASE_CHANNEL="nightly"
190
+while [ -n "${1}" ]; do
191
+ case "${1}" in
192
+ "--zlib-is-really-here") LIBS_ARE_HERE=1;;
193
+ "--libs-are-really-here") LIBS_ARE_HERE=1;;
194
+ "--dont-start-it") DONOTSTART=1;;
195
+ "--dont-wait") DONOTWAIT=1;;
196
+ "--auto-update"|"-u") AUTOUPDATE=1;;
197
+ "--stable-channel") RELEASE_CHANNEL="stable";;
198
+ "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi";;
199
+ "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi";;
200
+ "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct";;
201
+ "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct";;
202
+ "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat";;
203
+ "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-xenstat/} --disable-plugin-xenstat";;
204
+ "--enable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto";;
205
+ "--disable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto";;
206
+ "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse";;
207
+ "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1;;
208
+ "--disable-go") NETDATA_DISABLE_GO=1;;
209
+ "--install")
210
+ NETDATA_PREFIX="${2}/netdata"
211
+ shift 1
212
+ ;;
213
+ "--help"|"-h")
214
+ usage
215
+ exit 1
216
+ ;;
217
+ *)
218
+ run_failed "I cannot understand option '$1'."
219
+ usage
220
+ exit 1
221
+ ;;
222
+ esac
223
+ shift 1
224
done
225
226
# replace multiple spaces with a single space
227
NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS// / }"
228
229
+if [ "${UID}" -ne 0 ]; then
230
+ if [ -z "${NETDATA_PREFIX}" ]; then
231
+ netdata_banner "wrong command line options!"
232
+ banner_nonroot_install "${@}"
233
+ exit 1
234
+ else
235
+ banner_root_notify "${@}"
236
+ fi
237
+fi
238
+
239
netdata_banner "real-time performance monitoring, done right!"
240
cat <<BANNER1
241
264
265
BANNER3
266
298
-if [ "${UID}" -ne 0 ]; then
299
- if [ -z "${NETDATA_PREFIX}" ]; then
300
- netdata_banner "wrong command line options!"
301
- cat <<NONROOTNOPREFIX
302
-
303
- ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
304
-
305
- You are attempting to install netdata as non-root, but you plan
306
- to install it in system paths.
307
-
308
- Please set an installation prefix, like this:
309
-
310
- $0 ${@} --install /tmp
311
-
312
- or, run the installer as root:
313
-
314
- sudo $0 ${@}
315
-
316
- We suggest to install it as root, or certain data collectors will
317
- not be able to work. Netdata drops root privileges when running.
318
- So, if you plan to keep it, install it as root to get the full
319
- functionality.
320
-
321
-NONROOTNOPREFIX
322
- exit 1
323
-
324
- else
325
- cat <<NONROOT
326
-
327
- ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
328
- You are about to install netdata as a non-root user.
329
- Netdata will work, but a few data collection modules that
330
- require root access will fail.
331
-
332
- If you installing netdata permanently on your system, run
333
- the installer like this:
334
-
335
- ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
336
-
337
-NONROOT
338
- fi
339
-fi
340
-
267
have_autotools=
268
if [ "$(type autoreconf 2>/dev/null)" ]; then
269
autoconf_maj_min() {
307
fi
308
309
if [ ${DONOTWAIT} -eq 0 ]; then
384
- if [ ! -z "${NETDATA_PREFIX}" ]; then
385
- 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"
386
- [ $? -ne 0 ] && exit 1
310
+ if [ -n "${NETDATA_PREFIX}" ]; then
311
+ echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
312
else
388
- 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"
389
- [ $? -ne 0 ] && exit 1
313
+ echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
314
+ fi
315
+ read -ern1
316
+ if [ "$REPLY" != '' ]; then
317
+ exit 1
318
fi
319
+
320
fi
321
322
build_error() {
395
# -----------------------------------------------------------------------------
396
progress "Compile netdata"
397
469
-run make -j${SYSTEM_CPUS} || exit 1
398
+run make -j$(find_processors) || exit 1
399
400
# -----------------------------------------------------------------------------
401
progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
435
# -----------------------------------------------------------------------------
436
437
# shellcheck disable=SC2230
509
-md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
438
+md5sum="$(command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
439
440
deleted_stock_configs=0
441
if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
512
# -----------------------------------------------------------------------------
513
progress "Add user netdata to required user groups"
514
586
-homedir="${NETDATA_PREFIX}/var/lib/netdata"
587
-[ ! -z "${NETDATA_PREFIX}" ] && homedir="${NETDATA_PREFIX}"
588
-add_netdata_user_and_group "${homedir}" || run_failed "The installer does not run as root."
515
+NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
516
+NETDATA_ADDED_TO_GROUPS=""
517
+if [ "${UID}" -eq 0 ]; then
518
+ portable_add_group netdata || :
519
+ portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
520
+
521
+ for g in ${NETDATA_WANTED_GROUPS}; do
522
+ # shellcheck disable=SC2086
523
+ portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
524
+ done
525
+else
526
+ run_failed "The installer does not run as root."
527
+fi
528
529
# -----------------------------------------------------------------------------
530
progress "Install logrotate configuration for netdata"
560
NETDATA_USER="${USER}"
561
ROOT_USER="${NETDATA_USER}"
562
fi
624
-NETDATA_GROUP="$(id -g -n ${NETDATA_USER})"
563
+NETDATA_GROUP="$(id -g -n "${NETDATA_USER}")"
564
[ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
565
566
# the owners of the web files
567
NETDATA_WEB_USER="$(config_option "web" "web files owner" "${NETDATA_USER}")"
568
NETDATA_WEB_GROUP="${NETDATA_GROUP}"
630
-if [ "${UID}" = "0" -a "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
631
- NETDATA_WEB_GROUP="$(id -g -n ${NETDATA_WEB_USER})"
569
+if [ "${UID}" = "0" ] && [ "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
570
+ NETDATA_WEB_GROUP="$(id -g -n "${NETDATA_WEB_USER}")"
571
[ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
572
fi
573
NETDATA_WEB_GROUP="$(config_option "web" "web files group" "${NETDATA_WEB_GROUP}")"
672
673
# --- plugins ----
674
736
-if [ ${UID} -eq 0 ]; then
675
+if [ "${UID}" -eq 0 ]; then
676
# find the admin group
677
admin_group=
678
test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
680
test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
681
682
run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
744
- run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
683
+ run chown -R "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
684
run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
685
run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
686
run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
687
run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
688
689
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
751
- setcap_ret=1
752
- if ! iscontainer; then
753
- if [ ! -z "${setcap}" ]; then
754
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
755
- run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
756
- run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
757
- setcap_ret=$?
758
- fi
759
-
760
- if [ ${setcap_ret} -eq 0 ]; then
761
- # if we managed to setcap
762
- # but we fail to execute apps.plugin
763
- # trigger setuid to root
764
- "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
765
- setcap_ret=$?
690
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
691
+ capabilities=0
692
+ if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
693
+ run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
694
+ if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
695
+ # if we managed to setcap, but we fail to execute apps.plugin setuid to root
696
+ "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1 && capabilities=1 || capabilities=0
697
fi
698
fi
699
769
- if [ ${setcap_ret} -ne 0 ]; then
700
+ if [ $capabilities -eq 0 ]; then
701
# fix apps.plugin to be setuid to root
771
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
702
run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
703
fi
704
fi
705
706
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
777
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
707
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
708
run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
709
fi
710
781
- if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
782
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
783
- run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
784
- fi
711
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
712
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
713
+ run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
714
+ fi
715
716
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
717
run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
719
fi
720
721
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
792
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
722
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
723
run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
724
fi
725
726
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
797
- run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
727
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
728
run chmod 0550 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
729
fi
730
771
download "https://github.com/netdata/go.d.plugin/releases/download/$GO_PACKAGE_VERSION/$GO_PACKAGE_BASENAME" "${tmp}/$GO_PACKAGE_BASENAME"
772
773
download "https://github.com/netdata/go.d.plugin/releases/download/$GO_PACKAGE_VERSION/config.tar.gz" "${tmp}/config.tar.gz"
844
- grep "${GO_PACKAGE_BASENAME}\$" "${installer_dir}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2>/dev/null
845
- grep "config.tar.gz" "${installer_dir}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2>/dev/null
774
+ grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2>/dev/null
775
+ grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2>/dev/null
776
777
# Checksum validation
778
if ! (cd "${tmp}" && sha256sum -c "sha256sums.txt"); then
787
run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
788
789
run mv "${tmp}/$GO_PACKAGE_BASENAME" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
860
- if [ ${UID} -eq 0 ]; then
861
- run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
790
+ if [ "${UID}" -eq 0 ]; then
791
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
792
fi
793
run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
794
fi
796
}
797
install_go
798
869
-# --- fix #1292 bug ---
870
-
871
-[ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
872
-[ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
873
-
799
# -----------------------------------------------------------------------------
800
progress "Install netdata at system init"
801
805
# -----------------------------------------------------------------------------
806
# check if we can re-start netdata
807
808
+# TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
809
started=0
810
if [ ${DONOTSTART} -eq 1 ]; then
885
- generate_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
886
-
811
+ create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
812
else
888
- restart_netdata ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
889
- if [ $? -ne 0 ]; then
890
- echo >&2
891
- echo >&2 "SORRY! FAILED TO START NETDATA!"
892
- echo >&2
893
- exit 1
813
+ if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
814
+ fatal "Cannot start netdata!"
815
fi
816
817
started=1
897
- echo >&2 "OK. NetData Started!"
898
- echo >&2
899
-
900
- # -----------------------------------------------------------------------------
901
- # save a config file, if it is not already there
902
-
903
- download_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
818
+ run_ok "netdata started!"
819
+ create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
820
+fi
821
+if [ "${UID}" -eq 0 ]; then
822
+ run chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
823
fi
824
+run chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
825
826
if [ "$(uname)" = "Linux" ]; then
827
# -------------------------------------------------------------------------
861
}
862
863
if [ -f "/sys/kernel/mm/ksm/run" ]; then
944
- if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]; then
864
+ if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
865
ksm_is_available_but_disabled
866
fi
867
else
964
fi
965
progress "Installing new netdata-updater in cron"
966
1047
- rm ${installer_dir}/netdata-updater.sh || : #TODO(paulfantom): this workaround should be removed after v1.13.0-rc1. It just needs to be propagated
1048
-
967
rm -f "${crondir}/netdata-updater"
1050
- if [ -f "${installer_dir}/packaging/installer/netdata-updater.sh" ]; then
1051
- sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${installer_dir}/packaging/installer/netdata-updater.sh" > ${crondir}/netdata-updater || exit 1
1052
- #TODO(paulfantom): Following line is a workaround and should be removed after v1.13.0-rc1. It just needs time to be propagated.
1053
- sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${installer_dir}/packaging/installer/netdata-updater.sh" > ${installer_dir}/netdata-updater.sh || exit 1
968
+ if [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
969
+ sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
970
else
1055
- sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${netdata_source_dir}/packaging/installer/netdata-updater.sh" > ${crondir}/netdata-updater || exit 1
1056
- #TODO(paulfantom): Following line is a workaround and should be removed after v1.13.0-rc1. It just needs time to be propagated.
1057
- sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${netdata_source_dir}/packaging/installer/netdata-updater.sh" > ${installer_source_dir}/netdata-updater.sh || exit 1
971
+ sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
972
fi
973
974
chmod 0755 ${crondir}/netdata-updater
981
fi
982
983
# Save environment variables
1070
-cat <<EOF > ${NETDATA_USER_CONFIG_DIR}/.environment
984
+cat <<EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
985
# Created by installer
986
PATH="${PATH}"
987
CFLAGS="${CFLAGS}"
997
998
# Opt-out from telemetry program
999
if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
1086
- touch ${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics
1000
+ touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
1001
fi
1002
1003
# -----------------------------------------------------------------------------