make the updater detect it runs with proper user for the job and that there are new commits before re-installing netdata
Costa Tsaousis (ktsaou) committed
Sep 17, 2016 at 01:53 UTC
133931e9361a23db4b4c0ada90f96871a92fb286
1 file changed
+20
netdata-installer.sh
+20
@@ -1077,6 +1077,13 @@ echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1077
cat >netdata-updater.sh.new <<REINSTALL
1078
#!/usr/bin/env bash
1079
1080
+LAST_UID="${UID}"
1081
+if [ "\${LAST_UID}" != "\${UID}" ]
1082
+ then
1083
+ echo >&2 "This script should be run as user with uid \${LAST_UID} but it now runs with uid \${UID}"
1084
+ exit 1
1085
+fi
1086
+
1087
# make sure we cd to the working directory
1088
cd "${REINSTALL_PWD}" || exit 1
1089
@@ -1093,6 +1100,13 @@ failed() {
1100
exit 1
1101
}
1102
1103
+get_latest_commit_id() {
1104
+ git log | grep ^commit | head -n 1 | cut -d ' ' -f 2
1105
+}
1106
+
1107
+last_commit="\$(get_latest_commit_id)"
1108
+[ -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID"
1109
+
1110
update() {
1111
if [ -t 1 -a -t 2 ]
1112
then
@@ -1102,6 +1116,9 @@ update() {
1116
echo >&2
1117
echo >&2 "Updating source..."
1118
git pull || exit 1
1119
+ new_commit="\$(get_latest_commit_id)"
1120
+ [ -z "\${new_commit}" ] && echo >&2 "CANNOT GET NEW LAST COMMIT ID" && exit 1
1121
+ [ "\${new_commit}" = "\${last_commit}" ] && echo >&2 "Nothing to be done!" && exit 0
1122
1123
echo >&2
1124
echo >&2 "re-installing..."
@@ -1116,6 +1133,9 @@ update() {
1133
1134
# update source from git
1135
git pull >>"\${tmp}" 2>&1 || failed "CANNOT FETCH LATEST SOURCE"
1136
+ new_commit="\$(get_latest_commit_id)"
1137
+ [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID"
1138
+ [ "\${new_commit}" = "\${last_commit}" ] && exit 0
1139
1140
# install the latest version
1141
${REINSTALL_COMMAND// --dont-wait/} --dont-wait >>"\${tmp}" 2>&1 || failed "CANNOT BUILD AND INSTALL NETDATA"