summaryrefslogtreecommitdiffstats
path: root/packaging/installer/functions.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
commita836a244a3d2bdd4da1ee2641e3e957850668cea (patch)
treecb87c75b3677fab7144f868435243f864048a1e6 /packaging/installer/functions.sh
parentAdding upstream version 1.38.1. (diff)
downloadnetdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.tar.xz
netdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.zip
Adding upstream version 1.39.0.upstream/1.39.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/installer/functions.sh')
-rw-r--r--packaging/installer/functions.sh108
1 files changed, 51 insertions, 57 deletions
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh
index ebb4aab75..b12a9a585 100644
--- a/packaging/installer/functions.sh
+++ b/packaging/installer/functions.sh
@@ -95,10 +95,19 @@ progress() {
echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
}
+check_for_curl() {
+ if [ -z "${curl}" ]; then
+ curl="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
+ fi
+}
+
get() {
url="${1}"
- if command -v curl > /dev/null 2>&1; then
- curl -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"
+
+ check_for_curl
+
+ if [ -n "${curl}" ]; then
+ "${curl}" -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"
elif command -v wget > /dev/null 2>&1; then
wget -T 15 -O - "${url}"
else
@@ -112,8 +121,10 @@ download_file() {
name="${3}"
opt="${4}"
- if command -v curl > /dev/null 2>&1; then
- run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"
+ check_for_curl
+
+ if [ -n "${curl}" ]; then
+ run "${curl}" -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"
elif command -v wget > /dev/null 2>&1; then
run wget -T 15 -O "${dest}" "${url}"
else
@@ -400,7 +411,7 @@ get_group(){
if command -v getent > /dev/null 2>&1; then
getent group "${1:-""}"
else
- cat /etc/group | grep "^${1}:"
+ grep "^${1}:" /etc/group
fi
}
@@ -459,21 +470,21 @@ install_non_systemd_init() {
if [ -d /etc/init.d ] && [ ! -f /etc/init.d/netdata ]; then
if expr "${key}" : "^(gentoo|alpine).*"; then
echo >&2 "Installing OpenRC init file..."
- run cp system/netdata-openrc /etc/init.d/netdata &&
+ run cp system/openrc/init.d/netdata /etc/init.d/netdata &&
run chmod 755 /etc/init.d/netdata &&
run rc-update add netdata default &&
return 0
elif expr "${key}" : "^devuan*" || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
echo >&2 "Installing LSB init file..."
- run cp system/netdata-lsb /etc/init.d/netdata &&
+ run cp system/lsb/init.d/netdata /etc/init.d/netdata &&
run chmod 755 /etc/init.d/netdata &&
run update-rc.d netdata defaults &&
run update-rc.d netdata enable &&
return 0
elif expr "${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
echo >&2 "Installing init.d file..."
- run cp system/netdata-init-d /etc/init.d/netdata &&
+ run cp system/initd/init.d/netdata /etc/init.d/netdata &&
run chmod 755 /etc/init.d/netdata &&
run chkconfig netdata on &&
return 0
@@ -571,7 +582,7 @@ install_netdata_service() {
echo >&2 "Installing MacOS X plist file..."
# This is used by netdata-installer.sh
# shellcheck disable=SC2034
- run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist &&
+ run cp system/launchd/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist &&
run launchctl load /Library/LaunchDaemons/com.github.netdata.plist &&
NETDATA_START_CMD="launchctl start com.github.netdata" &&
NETDATA_STOP_CMD="launchctl stop com.github.netdata"
@@ -581,7 +592,7 @@ install_netdata_service() {
elif [ "${uname}" = "FreeBSD" ]; then
# This is used by netdata-installer.sh
# shellcheck disable=SC2034
- run cp system/netdata-freebsd /etc/rc.d/netdata && NETDATA_START_CMD="service netdata start" &&
+ run cp system/freebsd/rc.d/netdata /etc/rc.d/netdata && NETDATA_START_CMD="service netdata start" &&
NETDATA_STOP_CMD="service netdata stop" &&
NETDATA_INSTALLER_START_CMD="service netdata onestart" &&
myret=$?
@@ -589,7 +600,7 @@ install_netdata_service() {
echo >&2 "Note: To explicitly enable netdata automatic start, set 'netdata_enable' to 'YES' in /etc/rc.conf"
echo >&2 ""
- return ${myret}
+ return "${myret}"
elif issystemd; then
# systemd is running on this system
@@ -610,7 +621,7 @@ install_netdata_service() {
fi
echo >&2 "Installing systemd service..."
- run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" &&
+ run cp system/systemd/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" &&
run systemctl daemon-reload &&
${ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED} &&
return 0
@@ -834,10 +845,12 @@ restart_netdata() {
# install netdata logrotate
install_netdata_logrotate() {
+ src="${NETDATA_PREFIX}/usr/lib/netdata/system/logrotate/netdata"
+
if [ "${UID}" -eq 0 ]; then
if [ -d /etc/logrotate.d ]; then
if [ ! -f /etc/logrotate.d/netdata ]; then
- run cp system/netdata.logrotate /etc/logrotate.d/netdata
+ run cp "${src}" /etc/logrotate.d/netdata
fi
if [ -f /etc/logrotate.d/netdata ]; then
@@ -873,8 +886,10 @@ create_netdata_conf() {
export http_proxy=
export https_proxy=
- if command -v curl 1> /dev/null 2>&1; then
- run curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
+ check_for_curl
+
+ if [ -n "${curl}" ]; then
+ run "${curl}" -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
elif command -v wget 1> /dev/null 2>&1; then
run wget -T 15 -O - "${url}" > "${path}.new"
fi
@@ -903,32 +918,29 @@ portable_add_user() {
[ -z "${homedir}" ] && homedir="/tmp"
# Check if user exists
- if cut -d ':' -f 1 < /etc/passwd | grep "^${username}$" 1> /dev/null 2>&1; then
- echo >&2 "User '${username}' already exists."
- return 0
+ if command -v getent > /dev/null 2>&1; then
+ if getent passwd "${username}" > /dev/null 2>&1; then
+ echo >&2 "User '${username}' already exists."
+ return 0
+ fi
+ else
+ if cut -d ':' -f 1 < /etc/passwd | grep "^${username}$" 1> /dev/null 2>&1; then
+ echo >&2 "User '${username}' already exists."
+ return 0
+ fi
fi
echo >&2 "Adding ${username} user account with home ${homedir} ..."
nologin="$(command -v nologin || echo '/bin/false')"
- # Linux
if command -v useradd 1> /dev/null 2>&1; then
run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
- fi
-
- # FreeBSD
- if command -v pw 1> /dev/null 2>&1; then
+ elif command -v pw 1> /dev/null 2>&1; then
run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
- fi
-
- # BusyBox
- if command -v adduser 1> /dev/null 2>&1; then
+ elif command -v adduser 1> /dev/null 2>&1; then
run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
- fi
-
- # mac OS
- if command -v sysadminctl 1> /dev/null 2>&1; then
+ elif command -v sysadminctl 1> /dev/null 2>&1; then
run sysadminctl -addUser "${username}" && return 0
fi
@@ -951,20 +963,11 @@ portable_add_group() {
# Linux
if command -v groupadd 1> /dev/null 2>&1; then
run groupadd -r "${groupname}" && return 0
- fi
-
- # FreeBSD
- if command -v pw 1> /dev/null 2>&1; then
+ elif command -v pw 1> /dev/null 2>&1; then
run pw groupadd "${groupname}" && return 0
- fi
-
- # BusyBox
- if command -v addgroup 1> /dev/null 2>&1; then
+ elif command -v addgroup 1> /dev/null 2>&1; then
run addgroup "${groupname}" && return 0
- fi
-
- # mac OS
- if command -v dseditgroup 1> /dev/null 2>&1; then
+ elif command -v dseditgroup 1> /dev/null 2>&1; then
dseditgroup -o create "${groupname}" && return 0
fi
@@ -995,20 +998,11 @@ portable_add_user_to_group() {
# Linux
if command -v usermod 1> /dev/null 2>&1; then
run usermod -a -G "${groupname}" "${username}" && return 0
- fi
-
- # FreeBSD
- if command -v pw 1> /dev/null 2>&1; then
+ elif command -v pw 1> /dev/null 2>&1; then
run pw groupmod "${groupname}" -m "${username}" && return 0
- fi
-
- # BusyBox
- if command -v addgroup 1> /dev/null 2>&1; then
+ elif command -v addgroup 1> /dev/null 2>&1; then
run addgroup "${username}" "${groupname}" && return 0
- fi
-
- # mac OS
- if command -v dseditgroup 1> /dev/null 2>&1; then
+ elif command -v dseditgroup 1> /dev/null 2>&1; then
dseditgroup -u "${username}" "${groupname}" && return 0
fi
@@ -1063,8 +1057,8 @@ install_netdata_updater() {
fi
if issystemd && [ -n "$(get_systemd_service_dir)" ]; then
- cat "${NETDATA_SOURCE_DIR}/system/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer"
- cat "${NETDATA_SOURCE_DIR}/system/netdata-updater.service" > "$(get_systemd_service_dir)/netdata-updater.service"
+ cat "${NETDATA_SOURCE_DIR}/system/systemd/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer"
+ cat "${NETDATA_SOURCE_DIR}/system/systemd/netdata-updater.service" > "$(get_systemd_service_dir)/netdata-updater.service"
fi
sed -i -e "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1