@cryptotaxi247 / netdata-1 / commits / 9786c9cbe

netdata-updater.sh now support -f to force re-installation even if git has not been updated

Costa Tsaousis (ktsaou) committed Sep 25, 2016 at 15:10 UTC 9786c9cbeaa4cba98ca432461cb3211e00661b79
1 file changed +98 -45
netdata-installer.sh
+98 -45
@@ -673,7 +673,15 @@ if [ ${DONOTSTART} -eq 1 ]
673 fi
674 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
675 fi
676 - echo >&2 "OK. It is now installed and ready."
676 + cat >&2 <<"DONE1"
677 +
678 +
679 + .-. .-. .-. .-. .-. netdata
680 + '-' '-' '-' '-' ' is installed on this system now!
681 +
682 + enjoy real-time, performance and health monitoring...
683 +
684 +DONE1
685 exit 0
686 fi
687
@@ -1069,83 +1077,113 @@ To start it, just run it:
1077 ${NETDATA_PREFIX}/usr/sbin/netdata
1078
1079
1072 -Enjoy!
1073 -
1080 END
1081 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1082
1077 -cat >netdata-updater.sh.new <<REINSTALL
1083 +if [ -d .git ]
1084 + then
1085 + cat >netdata-updater.sh.new <<REINSTALL
1086 #!/usr/bin/env bash
1087
1088 +force=0
1089 +[ "\${1}" = "-f" ] && force=1
1090 +
1091 export PATH="\${PATH}:${PATH}"
1092 export CFLAGS="${CFLAGS}"
1093
1083 -LAST_UID="${UID}"
1084 -if [ "\${LAST_UID}" != "\${UID}" ]
1094 +INSTALL_UID="${UID}"
1095 +if [ "\${INSTALL_UID}" != "\${UID}" ]
1096 then
1086 - echo >&2 "This script should be run as user with uid \${LAST_UID} but it now runs with uid \${UID}"
1097 + echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1098 exit 1
1099 fi
1100
1101 # make sure we cd to the working directory
1102 cd "${REINSTALL_PWD}" || exit 1
1103
1104 +# make sure there is .git here
1105 +[ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1106 +
1107 # signal netdata to start saving its database
1108 # this is handy if your database is big
1109 pids=\$(pidof netdata)
1110 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1111
1112 +tmp=
1113 +if [ -t 2 ]
1114 + then
1115 + # we are running on a terminal
1116 + # open fd 3 and send it to stderr
1117 + exec 3>&2
1118 +else
1119 + # we are headless
1120 + # create a temporary file for the log
1121 + tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1122 + # open fd 3 and send it to tmp
1123 + exec 3>\${tmp}
1124 +fi
1125 +
1126 +info() {
1127 + echo >&3 "\$(date) : INFO: " "\${@}"
1128 +}
1129 +
1130 +emptyline() {
1131 + echo >&3
1132 +}
1133 +
1134 +error() {
1135 + echo >&3 "\$(date) : ERROR: " "\${@}"
1136 +}
1137 +
1138 # this is what we will do if it fails (head-less only)
1139 failed() {
1100 - echo >&2 "\$(date) : FAILED TO UPDATE NETDATA : \${1}"
1101 - cat >&2 "\${tmp}"
1102 - rm "\${tmp}"
1103 - exit 1
1140 + error "FAILED TO UPDATE NETDATA : \${1}"
1141 +
1142 + if [ ! -z "\${tmp}" ]
1143 + then
1144 + cat >&2 "\${tmp}"
1145 + rm "\${tmp}"
1146 + fi
1147 + exit 1
1148 }
1149
1150 get_latest_commit_id() {
1107 - git log | grep ^commit | head -n 1 | cut -d ' ' -f 2
1151 + git log -1 2>&3 |\\
1152 + grep ^commit 2>&3 |\\
1153 + head -n 1 2>&3 |\\
1154 + cut -d ' ' -f 2 2>&3
1155 }
1156
1110 -last_commit="\$(get_latest_commit_id)"
1111 -[ -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID"
1112 -
1157 update() {
1114 - if [ -t 1 -a -t 2 ]
1115 - then
1116 - # running on a terminal
1117 - echo >&2 "Running on a terminal - (this script also supports running headless from crontab)"
1158 + [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1159
1119 - echo >&2
1120 - echo >&2 "Updating source..."
1121 - git pull || exit 1
1122 - new_commit="\$(get_latest_commit_id)"
1123 - [ -z "\${new_commit}" ] && echo >&2 "CANNOT GET NEW LAST COMMIT ID" && exit 1
1124 - [ "\${new_commit}" = "\${last_commit}" ] && echo >&2 "Nothing to be done!" && exit 0
1160 + emptyline
1161
1126 - echo >&2
1127 - echo >&2 "re-installing..."
1128 - ${REINSTALL_COMMAND// --dont-wait/} --dont-wait || exit 1
1162 + if [ -d .git ]
1163 + then
1164 + info "Updating netdata source from github..."
1165
1130 - else
1131 - # running head-less
1132 - # do not generate any output, unless we fail
1166 + last_commit="\$(get_latest_commit_id)"
1167 + [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1168
1134 - # create a temporary file for the log
1135 - tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1169 + git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1170
1137 - # update source from git
1138 - git pull >>"\${tmp}" 2>&1 || failed "CANNOT FETCH LATEST SOURCE"
1171 new_commit="\$(get_latest_commit_id)"
1140 - [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID"
1141 - [ "\${new_commit}" = "\${last_commit}" ] && exit 0
1142 -
1143 - # install the latest version
1144 - ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >>"\${tmp}" 2>&1 || failed "CANNOT BUILD AND INSTALL NETDATA"
1145 -
1146 - rm "\${tmp}"
1172 + if [ \${force} -eq 0 ]
1173 + then
1174 + [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1175 + [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1176 + fi
1177 + elif [ \${force} -eq 0 ]
1178 + then
1179 + failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1180 fi
1181
1182 + emptyline
1183 + info "Re-installing netdata..."
1184 + ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1185 +
1186 + [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1187 return 0
1188 }
1189
@@ -1154,6 +1192,21 @@ update && exit 0
1192 ###############################################################################
1193 ###############################################################################
1194 REINSTALL
1157 -chmod 755 netdata-updater.sh.new
1158 -mv -f netdata-updater.sh.new netdata-updater.sh
1159 -echo >&2 "Update script generated : ./netdata-updater.sh"
1195 + chmod 755 netdata-updater.sh.new
1196 + mv -f netdata-updater.sh.new netdata-updater.sh
1197 + echo >&2 "Update script generated : ./netdata-updater.sh"
1198 +elif [ -f "netdata-updater.sh" ]
1199 + then
1200 + rm "netdata-updater.sh"
1201 +fi
1202 +
1203 +cat >&2 <<"DONE"
1204 +
1205 +
1206 + .-. .-. .-. .-. .-. netdata
1207 + '-' '-' '-' '-' ' is installed and is running now!
1208 +
1209 + enjoy real-time, performance and health monitoring...
1210 +
1211 +DONE
1212 +exit 0