diff options
Diffstat (limited to 'packaging/installer/functions.sh')
-rw-r--r-- | packaging/installer/functions.sh | 272 |
1 files changed, 145 insertions, 127 deletions
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index dd3158d6..9060930c 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -192,6 +192,133 @@ netdata_banner() { } # ----------------------------------------------------------------------------- +# Feature management and configuration commands + +enable_feature() { + NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed -e "s/-DENABLE_${1}=Off[[:space:]]*//g" -e "s/-DENABLE_${1}=On[[:space:]]*//g")" + if [ "${2}" -eq 1 ]; then + NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=On/")" + else + NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=Off/")" + fi +} + +check_for_module() { + if [ -z "${pkgconf}" ]; then + pkgconf="$(command -v pkgconf 2>/dev/null)" + [ -z "${pkgconf}" ] && pkgconf="$(command -v pkg-config 2>/dev/null)" + [ -z "${pkgconf}" ] && fatal "Unable to find a usable pkgconf/pkg-config command, cannot build Netdata." I0013 + fi + + "${pkgconf}" "${1}" + return "${?}" +} + +check_for_feature() { + feature_name="${1}" + feature_state="${2}" + shift 2 + feature_modules="${*}" + + if [ -z "${feature_state}" ]; then + # shellcheck disable=SC2086 + if check_for_module ${feature_modules}; then + enable_feature "${feature_name}" 1 + else + enable_feature "${feature_name}" 0 + fi + else + enable_feature "${feature_name}" "${feature_state}" + fi +} + +prepare_cmake_options() { + NETDATA_CMAKE_OPTIONS="-S ./ -B ${NETDATA_BUILD_DIR} ${CMAKE_OPTS} ${NETDATA_PREFIX+-DCMAKE_INSTALL_PREFIX="${NETDATA_PREFIX}"} ${NETDATA_USER:+-DNETDATA_USER=${NETDATA_USER}} ${NETDATA_CMAKE_OPTIONS} " + + NEED_OLD_CXX=0 + + if [ "${FORCE_LEGACY_CXX:-0}" -eq 1 ]; then + NEED_OLD_CXX=1 + else + if command -v gcc >/dev/null 2>&1; then + if [ "$(gcc --version | head -n 1 | sed 's/(.*) //' | cut -f 2 -d ' ' | cut -f 1 -d '.')" -lt 5 ]; then + NEED_OLD_CXX=1 + fi + fi + + if command -v clang >/dev/null 2>&1; then + if [ "$(clang --version | head -n 1 | cut -f 3 -d ' ' | cut -f 1 -d '.')" -lt 4 ]; then + NEED_OLD_CXX=1 + fi + fi + fi + + if [ "${NEED_OLD_CXX}" -eq 1 ]; then + NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DUSE_CXX_11=On" + fi + + if [ "${ENABLE_GO:-1}" -eq 1 ]; then + enable_feature PLUGIN_GO 1 + else + enable_feature PLUGIN_GO 0 + fi + + if [ "${USE_SYSTEM_PROTOBUF:-0}" -eq 1 ]; then + enable_feature BUNDLED_PROTOBUF 0 + else + enable_feature BUNDLED_PROTOBUF 1 + fi + + if [ -z "${ENABLE_SYSTEMD_JOURNAL}" ]; then + if check_for_module libsystemd; then + if check_for_module libelogind; then + ENABLE_SYSTEMD_JOURNAL=0 + else + ENABLE_SYSTEMD_JOURNAL=1 + fi + else + ENABLE_SYSTEMD_JOURNAL=0 + fi + fi + + enable_feature PLUGIN_SYSTEMD_JOURNAL "${ENABLE_SYSTEMD_JOURNAL}" + + if command -v cups-config >/dev/null 2>&1 || check_for_module libcups || check_for_module cups; then + ENABLE_CUPS=1 + else + ENABLE_CUPS=0 + fi + + enable_feature PLUGIN_CUPS "${ENABLE_CUPS}" + + IS_LINUX=0 + [ "$(uname -s)" = "Linux" ] && IS_LINUX=1 + enable_feature PLUGIN_DEBUGFS "${IS_LINUX}" + enable_feature PLUGIN_PERF "${IS_LINUX}" + enable_feature PLUGIN_SLABINFO "${IS_LINUX}" + enable_feature PLUGIN_CGROUP_NETWORK "${IS_LINUX}" + enable_feature PLUGIN_LOCAL_LISTENERS "${IS_LINUX}" + enable_feature PLUGIN_NETWORK_VIEWER "${IS_LINUX}" + enable_feature PLUGIN_EBPF "${ENABLE_EBPF:-0}" + enable_feature PLUGIN_LOGS_MANAGEMENT "${ENABLE_LOGS_MANAGEMENT:-0}" + enable_feature LOGS_MANAGEMENT_TESTS "${ENABLE_LOGS_MANAGEMENT_TESTS:-0}" + + enable_feature ACLK "${ENABLE_CLOUD:-1}" + enable_feature CLOUD "${ENABLE_CLOUD:-1}" + enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C:-0}" + enable_feature DBENGINE "${ENABLE_DBENGINE:-1}" + enable_feature H2O "${ENABLE_H2O:-1}" + enable_feature ML "${NETDATA_ENABLE_ML:-1}" + enable_feature PLUGIN_APPS "${ENABLE_APPS:-1}" + + check_for_feature EXPORTER_PROMETHEUS_REMOTE_WRITE "${EXPORTER_PROMETHEUS}" snappy + check_for_feature EXPORTER_MONGODB "${EXPORTER_MONGODB}" libmongoc-1.0 + check_for_feature PLUGIN_FREEIPMI "${ENABLE_FREEIPMI}" libipmimonitoring + check_for_feature PLUGIN_NFACCT "${ENABLE_NFACCT}" libnetfilter_acct libnml + check_for_feature PLUGIN_XENSTAT "${ENABLE_XENSTAT}" xenstat xenlight +} + +# ----------------------------------------------------------------------------- # portable service command service_cmd="$(command -v service 2> /dev/null || true)" @@ -463,45 +590,6 @@ get_systemd_service_dir() { fi } -install_non_systemd_init() { - [ "${UID}" != 0 ] && return 1 - key="$(get_os_key)" - - 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/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/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/initd/init.d/netdata /etc/init.d/netdata && - run chmod 755 /etc/init.d/netdata && - run chkconfig netdata on && - return 0 - else - warning "Could not determine what type of init script to install on this system." - return 1 - fi - elif [ -f /etc/init.d/netdata ]; then - echo >&2 "file '/etc/init.d/netdata' already exists." - return 0 - else - warning "Could not determine what type of init script to install on this system." - fi - - return 1 -} - run_install_service_script() { if [ -z "${tmpdir}" ]; then tmpdir="${TMPDIR:-/tmp}" @@ -565,90 +653,7 @@ install_netdata_service() { if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then run_install_service_script && return 0 else - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - NETDATA_STOP_CMD="netdatacli shutdown-agent" - - NETDATA_START_CMD="netdata" - NETDATA_INSTALLER_START_CMD="" - - uname="$(uname 2> /dev/null)" - - if [ "${uname}" = "Darwin" ]; then - if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]; then - echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists." - return 0 - else - echo >&2 "Installing MacOS X plist file..." - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - 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" - return 0 - fi - - elif [ "${uname}" = "FreeBSD" ]; then - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - 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=$? - - echo >&2 "Note: To explicitly enable netdata automatic start, set 'netdata_enable' to 'YES' in /etc/rc.conf" - echo >&2 "" - - return "${myret}" - - elif issystemd; then - # systemd is running on this system - NETDATA_START_CMD="systemctl start netdata" - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - NETDATA_STOP_CMD="systemctl stop netdata" - NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}" - - SYSTEMD_DIRECTORY="$(get_systemd_service_dir)" - - if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then - ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="run systemctl enable netdata" - IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2> /dev/null || echo "Netdata not there")" - if [ "${IS_NETDATA_ENABLED}" = "disabled" ]; then - echo >&2 "Netdata was there and disabled, make sure we don't re-enable it ourselves" - ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="true" - fi - - echo >&2 "Installing systemd service..." - run cp system/systemd/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" && - run systemctl daemon-reload && - ${ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED} && - return 0 - else - warning "Could not find a systemd service directory, unable to install Netdata systemd service." - fi - else - install_non_systemd_init - ret=$? - - if [ ${ret} -eq 0 ]; then - if [ -n "${service_cmd}" ]; then - NETDATA_START_CMD="service netdata start" - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - NETDATA_STOP_CMD="service netdata stop" - elif [ -n "${rcservice_cmd}" ]; then - NETDATA_START_CMD="rc-service netdata start" - # This is used by netdata-installer.sh - # shellcheck disable=SC2034 - NETDATA_STOP_CMD="rc-service netdata stop" - fi - NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}" - fi - - return ${ret} - fi + warning "Could not find service install script, not installing Netdata as a system service." fi fi @@ -928,6 +933,11 @@ portable_add_user() { echo >&2 "User '${username}' already exists." return 0 fi + elif command -v dscl > /dev/null 2>&1; then + if dscl . read /Users/"${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." @@ -946,7 +956,13 @@ portable_add_user() { elif command -v adduser 1> /dev/null 2>&1; then run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0 elif command -v sysadminctl 1> /dev/null 2>&1; then - run sysadminctl -addUser "${username}" && return 0 + gid=$(dscl . read /Groups/"${username}" 2>/dev/null | grep PrimaryGroupID | grep -Eo "[0-9]+") + if run sysadminctl -addUser "${username}" -shell /usr/bin/false -home /var/empty -GID "$gid"; then + # FIXME: I think the proper solution is to create a role account: + # -roleAccount + name starting with _ and UID in 200-400 range. + run dscl . create /Users/"${username}" IsHidden 1 + return 0 + fi fi warning "Failed to add ${username} user account!" @@ -1061,9 +1077,11 @@ install_netdata_updater() { cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1 fi - if issystemd && [ -n "$(get_systemd_service_dir)" ]; then - 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" + # these files are installed by cmake + libsysdir="${NETDATA_PREFIX}/usr/lib/netdata/system/systemd/" + if [ -d "${libsysdir}" ] && issystemd && [ -n "$(get_systemd_service_dir)" ]; then + cat "${libsysdir}/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer" + cat "${libsysdir}/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 |