summaryrefslogtreecommitdiffstats
path: root/netdata-installer.sh
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-09-17 01:53:35 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-09-17 01:53:35 +0300
commit133931e9361a23db4b4c0ada90f96871a92fb286 (patch)
tree7d9a3028738acbe760c1991bc9dc64c1c0453a05 /netdata-installer.sh
parent6122e4a3242ee0fb17da84f91e806879e532cec3 (diff)
make the updater detect it runs with proper user for the job and that there are new commits before re-installing netdata
Diffstat (limited to 'netdata-installer.sh')
-rwxr-xr-xnetdata-installer.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh
index a01d81e598..304d9b9920 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -1077,6 +1077,13 @@ echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
cat >netdata-updater.sh.new <<REINSTALL
#!/usr/bin/env bash
+LAST_UID="${UID}"
+if [ "\${LAST_UID}" != "\${UID}" ]
+ then
+ echo >&2 "This script should be run as user with uid \${LAST_UID} but it now runs with uid \${UID}"
+ exit 1
+fi
+
# make sure we cd to the working directory
cd "${REINSTALL_PWD}" || exit 1
@@ -1093,6 +1100,13 @@ failed() {
exit 1
}
+get_latest_commit_id() {
+ git log | grep ^commit | head -n 1 | cut -d ' ' -f 2
+}
+
+last_commit="\$(get_latest_commit_id)"
+[ -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID"
+
update() {
if [ -t 1 -a -t 2 ]
then
@@ -1102,6 +1116,9 @@ update() {
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
echo >&2
echo >&2 "re-installing..."
@@ -1116,6 +1133,9 @@ update() {
# 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"