fi
chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
fi
- echo >&2 "OK. It is now installed and ready."
+ cat >&2 <<"DONE1"
+
+
+ .-. .-. .-. .-. .-. netdata
+ '-' '-' '-' '-' ' is installed on this system now!
+
+ enjoy real-time, performance and health monitoring...
+
+DONE1
exit 0
fi
${NETDATA_PREFIX}/usr/sbin/netdata
-Enjoy!
-
END
echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
-cat >netdata-updater.sh.new <<REINSTALL
+if [ -d .git ]
+ then
+ cat >netdata-updater.sh.new <<REINSTALL
#!/usr/bin/env bash
+force=0
+[ "\${1}" = "-f" ] && force=1
+
export PATH="\${PATH}:${PATH}"
export CFLAGS="${CFLAGS}"
-LAST_UID="${UID}"
-if [ "\${LAST_UID}" != "\${UID}" ]
+INSTALL_UID="${UID}"
+if [ "\${INSTALL_UID}" != "\${UID}" ]
then
- echo >&2 "This script should be run as user with uid \${LAST_UID} but it now runs with uid \${UID}"
+ echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
exit 1
fi
# make sure we cd to the working directory
cd "${REINSTALL_PWD}" || exit 1
+# make sure there is .git here
+[ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
+
# signal netdata to start saving its database
# this is handy if your database is big
pids=\$(pidof netdata)
[ ! -z "\${pids}" ] && kill -USR1 \${pids}
+tmp=
+if [ -t 2 ]
+ then
+ # we are running on a terminal
+ # open fd 3 and send it to stderr
+ exec 3>&2
+else
+ # we are headless
+ # create a temporary file for the log
+ tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
+ # open fd 3 and send it to tmp
+ exec 3>\${tmp}
+fi
+
+info() {
+ echo >&3 "\$(date) : INFO: " "\${@}"
+}
+
+emptyline() {
+ echo >&3
+}
+
+error() {
+ echo >&3 "\$(date) : ERROR: " "\${@}"
+}
+
# this is what we will do if it fails (head-less only)
failed() {
- echo >&2 "\$(date) : FAILED TO UPDATE NETDATA : \${1}"
- cat >&2 "\${tmp}"
- rm "\${tmp}"
- exit 1
+ error "FAILED TO UPDATE NETDATA : \${1}"
+
+ if [ ! -z "\${tmp}" ]
+ then
+ cat >&2 "\${tmp}"
+ rm "\${tmp}"
+ fi
+ exit 1
}
get_latest_commit_id() {
- git log | grep ^commit | head -n 1 | cut -d ' ' -f 2
+ git log -1 2>&3 |\\
+ grep ^commit 2>&3 |\\
+ head -n 1 2>&3 |\\
+ cut -d ' ' -f 2 2>&3
}
-last_commit="\$(get_latest_commit_id)"
-[ -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID"
-
update() {
- if [ -t 1 -a -t 2 ]
- then
- # running on a terminal
- echo >&2 "Running on a terminal - (this script also supports running headless from crontab)"
+ [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
- echo >&2
- echo >&2 "Updating source..."
- git pull || exit 1
- new_commit="\$(get_latest_commit_id)"
- [ -z "\${new_commit}" ] && echo >&2 "CANNOT GET NEW LAST COMMIT ID" && exit 1
- [ "\${new_commit}" = "\${last_commit}" ] && echo >&2 "Nothing to be done!" && exit 0
+ emptyline
- echo >&2
- echo >&2 "re-installing..."
- ${REINSTALL_COMMAND// --dont-wait/} --dont-wait || exit 1
+ if [ -d .git ]
+ then
+ info "Updating netdata source from github..."
- else
- # running head-less
- # do not generate any output, unless we fail
+ last_commit="\$(get_latest_commit_id)"
+ [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
- # create a temporary file for the log
- tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
+ git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
- # update source from git
- git pull >>"\${tmp}" 2>&1 || failed "CANNOT FETCH LATEST SOURCE"
new_commit="\$(get_latest_commit_id)"
- [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID"
- [ "\${new_commit}" = "\${last_commit}" ] && exit 0
-
- # install the latest version
- ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >>"\${tmp}" 2>&1 || failed "CANNOT BUILD AND INSTALL NETDATA"
-
- rm "\${tmp}"
+ if [ \${force} -eq 0 ]
+ then
+ [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
+ [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
+ fi
+ elif [ \${force} -eq 0 ]
+ then
+ failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
fi
+ emptyline
+ info "Re-installing netdata..."
+ ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
+
+ [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
return 0
}
###############################################################################
###############################################################################
REINSTALL
-chmod 755 netdata-updater.sh.new
-mv -f netdata-updater.sh.new netdata-updater.sh
-echo >&2 "Update script generated : ./netdata-updater.sh"
+ chmod 755 netdata-updater.sh.new
+ mv -f netdata-updater.sh.new netdata-updater.sh
+ echo >&2 "Update script generated : ./netdata-updater.sh"
+elif [ -f "netdata-updater.sh" ]
+ then
+ rm "netdata-updater.sh"
+fi
+
+cat >&2 <<"DONE"
+
+
+ .-. .-. .-. .-. .-. netdata
+ '-' '-' '-' '-' ' is installed and is running now!
+
+ enjoy real-time, performance and health monitoring...
+
+DONE
+exit 0