summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-02-12 23:29:44 +0200
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-02-12 23:29:44 +0200
commitc97eaeb9dfad7190e03c0ca264ea6ae76f404edd (patch)
tree9afd36e936a4d9e52ca642e82a1dfe8e06e2cb3b
parente099b5abf7534d92367e9751bcd7630dba8f086a (diff)
compatibility fixes at the installer
-rw-r--r--installer/functions.sh91
-rwxr-xr-xnetdata-installer.sh92
2 files changed, 102 insertions, 81 deletions
diff --git a/installer/functions.sh b/installer/functions.sh
index 5c81f88b5f..02b061d819 100644
--- a/installer/functions.sh
+++ b/installer/functions.sh
@@ -20,43 +20,45 @@ setup_terminal() {
# Is stderr on the terminal? If not, then fail
test -t 2 || return 1
- if [ ! -z "$TPUT_CMD" ]
+ if check_cmd tput
then
- if [ $[$($TPUT_CMD colors 2>/dev/null)] -ge 8 ]
+ if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
then
# Enable colors
- COLOR_RESET="\e[0m"
- COLOR_BLACK="\e[30m"
- COLOR_RED="\e[31m"
- COLOR_GREEN="\e[32m"
- COLOR_YELLOW="\e[33m"
- COLOR_BLUE="\e[34m"
- COLOR_PURPLE="\e[35m"
- COLOR_CYAN="\e[36m"
- COLOR_WHITE="\e[37m"
- COLOR_BGBLACK="\e[40m"
- COLOR_BGRED="\e[41m"
- COLOR_BGGREEN="\e[42m"
- COLOR_BGYELLOW="\e[43m"
- COLOR_BGBLUE="\e[44m"
- COLOR_BGPURPLE="\e[45m"
- COLOR_BGCYAN="\e[46m"
- COLOR_BGWHITE="\e[47m"
- COLOR_BOLD="\e[1m"
- COLOR_DIM="\e[2m"
- COLOR_UNDERLINED="\e[4m"
- COLOR_BLINK="\e[5m"
- COLOR_INVERTED="\e[7m"
+ TPUT_RESET="$(tput sgr 0)"
+ TPUT_BLACK="$(tput setaf 0)"
+ TPUT_RED="$(tput setaf 1)"
+ TPUT_GREEN="$(tput setaf 2)"
+ TPUT_YELLOW="$(tput setaf 3)"
+ TPUT_BLUE="$(tput setaf 4)"
+ TPUT_PURPLE="$(tput setaf 5)"
+ TPUT_CYAN="$(tput setaf 6)"
+ TPUT_WHITE="$(tput setaf 7)"
+ TPUT_BGBLACK="$(tput setab 0)"
+ TPUT_BGRED="$(tput setab 1)"
+ TPUT_BGGREEN="$(tput setab 2)"
+ TPUT_BGYELLOW="$(tput setab 3)"
+ TPUT_BGBLUE="$(tput setab 4)"
+ TPUT_BGPURPLE="$(tput setab 5)"
+ TPUT_BGCYAN="$(tput setab 6)"
+ TPUT_BGWHITE="$(tput setab 7)"
+ TPUT_BOLD="$(tput bold)"
+ TPUT_DIM="$(tput dim)"
+ TPUT_UNDERLINED="$(tput smul)"
+ TPUT_BLINK="$(tput blink)"
+ TPUT_INVERTED="$(tput rev)"
+ TPUT_STANDOUT="$(tput smso)"
+ TPUT_BELL="$(tput bel)"
+ TPUT_CLEAR="$(tput clear)"
fi
fi
return 0
}
-TPUT_CMD="$(which_cmd tput)"
setup_terminal
progress() {
- printf >&2 " --- ${COLOR_DIM}${COLOR_BOLD}${*}${COLOR_RESET} --- \n"
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
}
# -----------------------------------------------------------------------------
@@ -67,7 +69,7 @@ netdata_banner() {
l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
sp=" " \
- netdata="netdata" start end msg="${*}" chartcolor="${COLOR_DIM}"
+ netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
[ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
[ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
@@ -77,10 +79,10 @@ netdata_banner() {
end=$(( ${start} + ${#msg} + 4 ))
echo >&2
- echo >&2 -e "${chartcolor}${l1}${COLOR_RESET}"
- echo >&2 -e "${chartcolor}${l2:0:start}${sp:0:2}${COLOR_RESET}${COLOR_BOLD}${COLOR_GREEN}${netdata}${COLOR_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${COLOR_RESET}"
- echo >&2 -e "${chartcolor}${l3:0:start}${sp:0:2}${COLOR_RESET}${COLOR_BOLD}${COLOR_CYAN}${msg}${COLOR_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${COLOR_RESET}"
- echo >&2 -e "${chartcolor}${l4}${COLOR_RESET}"
+ echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
+ 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}"
+ 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}"
+ echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
echo >&2
}
@@ -106,6 +108,14 @@ service() {
# -----------------------------------------------------------------------------
+run_ok() {
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
+}
+
+run_failed() {
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
+}
+
run_logfile="/dev/null"
run() {
local user="${USER}" dir="$(basename "${PWD}")" info info_console
@@ -113,29 +123,29 @@ run() {
if [ "${UID}" = "0" ]
then
info="[root ${dir}]# "
- info_console="[${COLOR_DIM}${dir}${COLOR_RESET}]# "
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
else
info="[${user} ${dir}]$ "
- info_console="[${COLOR_DIM}${dir}${COLOR_RESET}]$ "
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
fi
printf >> "${run_logfile}" "${info}"
printf >> "${run_logfile}" "%q " "${@}"
printf >> "${run_logfile}" " ... "
- printf >&2 "${info_console}${COLOR_BOLD}${COLOR_YELLOW}"
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
printf >&2 "%q " "${@}"
- printf >&2 "${COLOR_RESET}\n"
+ printf >&2 "${TPUT_RESET}\n"
"${@}"
local ret=$?
if [ ${ret} -ne 0 ]
then
- printf >&2 "${COLOR_BGRED}${COLOR_WHITE}${COLOR_BOLD} FAILED ${COLOR_RESET}\n\n"
+ run_failed
printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
else
- printf >&2 "${COLOR_BGGREEN}${COLOR_WHITE}${COLOR_BOLD} OK ${COLOR_RESET}\n\n"
+ run_ok
printf >> "${run_logfile}" "OK\n"
fi
@@ -146,7 +156,7 @@ portable_add_user() {
local username="${1}"
getent passwd "${username}" > /dev/null 2>&1
- [ $? -eq 0 ] && return 0
+ [ $? -eq 0 ] && echo >&2 "User '${username}' already exists." && return 0
echo >&2 "Adding ${username} user account ..."
@@ -179,7 +189,7 @@ portable_add_group() {
local groupname="${1}"
getent group "${groupname}" > /dev/null 2>&1
- [ $? -eq 0 ] && return 0
+ [ $? -eq 0 ] && echo >&2 "Group '${groupname}' already exists." && return 0
echo >&2 "Adding ${groupname} user group ..."
@@ -209,13 +219,14 @@ portable_add_user_to_group() {
local groupname="${1}" username="${2}"
getent group "${groupname}" > /dev/null 2>&1
- [ $? -ne 0 ] && return 1
+ [ $? -ne 0 ] && echo >&2 "Group '${groupname}' does not exist." && return 1
# find the user is already in the group
local users=$(getent group "${groupname}" | cut -d ':' -f 4)
if [[ ",${users}," =~ ,${username}, ]]
then
# username is already there
+ echo >&2 "User '${username}' is already in group '${groupname}'."
return 0
else
# username is not in group
diff --git a/netdata-installer.sh b/netdata-installer.sh
index f8a7deea7f..584e2e67b2 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -202,25 +202,32 @@ do
done
netdata_banner "real-time performance monitoring, done right!"
-cat <<BANNER
+cat <<BANNER1
You are about to build and install netdata to your system.
It will be installed at these locations:
- - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
- - config files at ${NETDATA_PREFIX}/etc/netdata
- - web files at ${NETDATA_PREFIX}/usr/share/netdata
- - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
- - cache files at ${NETDATA_PREFIX}/var/cache/netdata
- - db files at ${NETDATA_PREFIX}/var/lib/netdata
- - log files at ${NETDATA_PREFIX}/var/log/netdata
- - pid file at ${NETDATA_PREFIX}/var/run
+ - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
+ - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
+ - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
+ - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
+ - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
+ - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
+ - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
+BANNER1
+
+[ "${UID}" -eq 0 ] && cat <<BANNER2
+ - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
+ - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
+BANNER2
+
+cat <<BANNER3
This installer allows you to change the installation path.
Press Control-C and run the same command with --help for help.
-BANNER
+BANNER3
if [ "${UID}" -ne 0 ]
then
@@ -229,7 +236,7 @@ if [ "${UID}" -ne 0 ]
netdata_banner "wrong command line options!"
cat <<NONROOTNOPREFIX
- Sorry! This will fail!
+ ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
You are attempting to install netdata as non-root, but you plan
to install it in system paths.
@@ -253,7 +260,7 @@ NONROOTNOPREFIX
else
cat <<NONROOT
- IMPORTANT:
+ ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
You are about to install netdata as a non-root user.
Netdata will work, but a few data collection modules that
require root access will fail.
@@ -261,7 +268,7 @@ NONROOTNOPREFIX
If you installing netdata permanently on your system, run
the installer like this:
- sudo $0 ${@}
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
NONROOT
fi
@@ -327,9 +334,9 @@ if [ ${DONOTWAIT} -eq 0 ]
then
if [ ! -z "${NETDATA_PREFIX}" ]
then
- eval "read >&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to \'\001${COLOR_CYAN}\002${NETDATA_PREFIX}\001${COLOR_YELLOW}\002\'\001${COLOR_RESET}\002 > ' -e -r REPLY"
+ 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"
else
- eval "read >&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to your system\001${COLOR_RESET}\002 > ' -e -r REPLY"
+ 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"
fi
fi
@@ -480,7 +487,8 @@ do
if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
then
# we don't have md5sum - keep it
- cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
+ run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
else
# find it relative filename
f="${x/*\/etc\/netdata\//}"
@@ -499,15 +507,15 @@ do
if [ "${configs_signatures[${md5}]}" = "${f}" ]
then
# it is a stock version - don't keep it
- echo >&2 "File '${x}' is stock version."
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
else
# edited by user - keep it
- echo >&2 "File '${x}' has been edited by user."
- cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
+ run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
fi
else
- echo >&2 "File '${x}' cannot be check for custom edits."
- cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+ echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
+ run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
fi
fi
@@ -525,14 +533,14 @@ run make install || exit 1
# -----------------------------------------------------------------------------
-progress "Restore netdata configuration files"
+progress "Restore user edited netdata configuration files"
for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
do
if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
then
- cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
- rm -f "${x}.installer_backup.${installer_backup_suffix}"
+ run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \
+ run rm -f "${x}.installer_backup.${installer_backup_suffix}"
fi
done
@@ -560,9 +568,11 @@ if [ ${UID} -eq 0 ]
portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
+ run_ok
+else
+ run_failed "The installer does not run as root."
fi
-
# -----------------------------------------------------------------------------
progress "Install logrotate configuration for netdata"
@@ -858,7 +868,7 @@ stop_all_netdata() {
myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
- echo >&2 "Stopping a (possibly) running netdata..."
+ # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
$(cat /var/run/netdata.pid 2>/dev/null) \
@@ -974,15 +984,15 @@ progress "Check KSM (kernel memory deduper)"
ksm_is_available_but_disabled() {
cat <<KSM1
-Memory de-duplication instructions
+${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
You have kernel memory de-duper (called Kernel Same-page Merging,
or KSM) available, but it is not currently enabled.
To enable it run:
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}echo 1 >/sys/kernel/mm/ksm/run${COLOR_RESET}")
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${COLOR_RESET}")
+ ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
+ ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
If you enable it, you will save 40-60% of netdata memory.
@@ -992,7 +1002,7 @@ KSM1
ksm_is_not_available() {
cat <<KSM2
-Memory de-duplication not present in your kernel
+${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
It seems you do not have kernel memory de-duper (called Kernel Same-page
Merging, or KSM) available.
@@ -1021,7 +1031,7 @@ if [ ! -s web/version.txt ]
then
cat <<VERMSG
-Version update check warning
+${TPUT_BOLD}Version update check warning${TPUT_RESET}
The way you downloaded netdata, we cannot find its version. This means the
Update check on the dashboard, will not work.
@@ -1041,7 +1051,7 @@ if [ "${UID}" -ne 0 ]
then
cat <<SETUID_WARNING
-apps.plugin needs privileges
+${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
Since you have installed netdata as a normal user, to have apps.plugin collect
all the needed data, you have to give it the access rights it needs, by running
@@ -1049,14 +1059,14 @@ either of the following sets of commands:
To run apps.plugin with escalated capabilities:
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
or, to run apps.plugin as root:
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
+ ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
apps.plugin is performing a hard-coded function of data collection for all
running processes. It cannot be instructed from the netdata daemon to perform
@@ -1213,15 +1223,15 @@ http://this.machine.ip:${NETDATA_PORT}/
To stop netdata, just kill it, with:
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}killall netdata${COLOR_RESET}")
+ ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET}
To start it, just run it:
- $(printf "${COLOR_YELLOW}${COLOR_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${COLOR_RESET}")
+ ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
END
-echo >&2 -e "Uninstall script generated: ${COLOR_YELLOW}${COLOR_BOLD}./netdata-uninstaller.sh${COLOR_RESET}"
+echo >&2 "Uninstall script generated: ${TPUT_YELLOW}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
if [ -d .git ]
then
@@ -1337,7 +1347,7 @@ update && exit 0
REINSTALL
chmod 755 netdata-updater.sh.new
mv -f netdata-updater.sh.new netdata-updater.sh
- echo >&2 -e "Update script generated : ${COLOR_YELLOW}${COLOR_BOLD}./netdata-updater.sh${COLOR_RESET}"
+ echo >&2 "Update script generated : ${TPUT_YELLOW}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
elif [ -f "netdata-updater.sh" ]
then
rm "netdata-updater.sh"