@cryptotaxi247 / netdata-1 / commits / f6be65b39

Fix the lack of cleanup in the netdata updater (#8414)

* Fix lack of proper cleanup in netdata updater * Use EXIT pseudo signal

James Mills committed Mar 25, 2020 at 20:24 UTC f6be65b39b8bb91cabcad5d78c4ba17433babc40
1 file changed +15 -3
packaging/installer/netdata-updater.sh
+15 -3
@@ -19,6 +19,8 @@
19 # Author: Paweł Krupa <paulfantom@gmail.com>
20 # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
21
22 +set -e
23 +
24 info() {
25 echo >&3 "$(date) : INFO: " "${@}"
26 }
@@ -42,12 +44,18 @@ safe_sha256sum() {
44 # this is what we will do if it fails (head-less only)
45 fatal() {
46 error "FAILED TO UPDATE NETDATA : ${1}"
47 + exit 1
48 +}
49
50 +cleanup() {
51 if [ -n "${logfile}" ]; then
52 cat >&2 "${logfile}"
53 rm "${logfile}"
54 fi
50 - exit 1
55 +
56 + if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then
57 + rm -rf "$tmpdir"
58 + fi
59 }
60
61 create_tmp_directory() {
@@ -73,7 +81,7 @@ download() {
81 fi
82 }
83
76 -function parse_version() {
84 +parse_version() {
85 r="${1}"
86 if echo "${r}" | grep -q '^v.*'; then
87 # shellcheck disable=SC2001
@@ -193,6 +201,11 @@ update() {
201 return 0
202 }
203
204 +logfile=
205 +tmpdir=
206 +
207 +trap cleanup EXIT
208 +
209 # Usually stored in /etc/netdata/.environment
210 : "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
211
@@ -209,7 +222,6 @@ if [ "${INSTALL_UID}" != "$(id -u)" ]; then
222 fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)"
223 fi
224
212 -logfile=
225 if [ -t 2 ]; then
226 # we are running on a terminal
227 # open fd 3 and send it to stderr