fix(uninstaller): define rm_file before first use (#21246)
Ilya Mashchenko committed
Oct 30, 2025 at 21:37 UTC
f8e226995e1a5e2866fbb2ef29845f59d564f1ad
1 file changed
+98
-98
packaging/installer/netdata-uninstaller.sh
+98
-98
@@ -252,6 +252,104 @@ cleanup_data_and_config() {
252
rm_dir "${NETDATA_PREFIX}/etc/netdata"
253
}
254
255
+setup_terminal() {
256
+ TPUT_RESET=""
257
+ TPUT_YELLOW=""
258
+ TPUT_WHITE=""
259
+ TPUT_BGRED=""
260
+ TPUT_BGGREEN=""
261
+ TPUT_BOLD=""
262
+ TPUT_DIM=""
263
+
264
+ # Is stderr on the terminal? If not, then fail
265
+ test -t 2 || return 1
266
+
267
+ if command -v tput 1> /dev/null 2>&1; then
268
+ if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
269
+ # Enable colors
270
+ TPUT_RESET="$(tput sgr 0)"
271
+ TPUT_YELLOW="$(tput setaf 3)"
272
+ TPUT_WHITE="$(tput setaf 7)"
273
+ TPUT_BGRED="$(tput setab 1)"
274
+ TPUT_BGGREEN="$(tput setab 2)"
275
+ TPUT_BOLD="$(tput bold)"
276
+ TPUT_DIM="$(tput dim)"
277
+ fi
278
+ fi
279
+
280
+ return 0
281
+}
282
+setup_terminal || echo > /dev/null
283
+
284
+ESCAPED_PRINT_METHOD=
285
+if printf "%s " test > /dev/null 2>&1; then
286
+ ESCAPED_PRINT_METHOD="printfq"
287
+fi
288
+escaped_print() {
289
+ if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
290
+ printf "%s " "${@}"
291
+ else
292
+ printf "%s" "${*}"
293
+ fi
294
+ return 0
295
+}
296
+
297
+run_logfile="/dev/null"
298
+run() {
299
+ user="${USER--}"
300
+ dir="${PWD}"
301
+
302
+ if [ "$(id -u)" = "0" ]; then
303
+ info="[root ${dir}]# "
304
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
305
+ else
306
+ info="[${user} ${dir}]$ "
307
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
308
+ fi
309
+
310
+ {
311
+ printf "%s" "${info}"
312
+ escaped_print "${@}"
313
+ printf "%s" " ... "
314
+ } >> "${run_logfile}"
315
+
316
+ printf "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" >&2
317
+ escaped_print >&2 "${@}"
318
+ printf "%s\n" "${TPUT_RESET}" >&2
319
+
320
+ "${@}"
321
+
322
+ ret=$?
323
+ if [ ${ret} -ne 0 ]; then
324
+ printf >&2 "%s FAILED %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
325
+ printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
326
+ NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
327
+ else
328
+ printf >&2 "%s OK %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
329
+ printf >> "${run_logfile}" "OK\n"
330
+ fi
331
+
332
+ return ${ret}
333
+}
334
+
335
+rm_file() {
336
+ FILE="$1"
337
+ if [ -f "${FILE}" ]; then
338
+ if user_input "Do you want to delete this file '$FILE' ? "; then
339
+ run rm -v "${FILE}"
340
+ fi
341
+ fi
342
+}
343
+
344
+rm_dir() {
345
+ DIR="$1"
346
+ if [ -n "$DIR" ] && [ -d "$DIR" ]; then
347
+ if user_input "Do you want to delete this directory '$DIR' ? "; then
348
+ run rm -v -f -R "${DIR}"
349
+ fi
350
+ fi
351
+}
352
+
353
detect_existing_install
354
disable_updater
355
@@ -374,86 +472,6 @@ service() {
472
473
# -----------------------------------------------------------------------------
474
377
-setup_terminal() {
378
- TPUT_RESET=""
379
- TPUT_YELLOW=""
380
- TPUT_WHITE=""
381
- TPUT_BGRED=""
382
- TPUT_BGGREEN=""
383
- TPUT_BOLD=""
384
- TPUT_DIM=""
385
-
386
- # Is stderr on the terminal? If not, then fail
387
- test -t 2 || return 1
388
-
389
- if command -v tput 1> /dev/null 2>&1; then
390
- if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
391
- # Enable colors
392
- TPUT_RESET="$(tput sgr 0)"
393
- TPUT_YELLOW="$(tput setaf 3)"
394
- TPUT_WHITE="$(tput setaf 7)"
395
- TPUT_BGRED="$(tput setab 1)"
396
- TPUT_BGGREEN="$(tput setab 2)"
397
- TPUT_BOLD="$(tput bold)"
398
- TPUT_DIM="$(tput dim)"
399
- fi
400
- fi
401
-
402
- return 0
403
-}
404
-setup_terminal || echo > /dev/null
405
-
406
-ESCAPED_PRINT_METHOD=
407
-if printf "%s " test > /dev/null 2>&1; then
408
- ESCAPED_PRINT_METHOD="printfq"
409
-fi
410
-escaped_print() {
411
- if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
412
- printf "%s " "${@}"
413
- else
414
- printf "%s" "${*}"
415
- fi
416
- return 0
417
-}
418
-
419
-run_logfile="/dev/null"
420
-run() {
421
- user="${USER--}"
422
- dir="${PWD}"
423
-
424
- if [ "$(id -u)" = "0" ]; then
425
- info="[root ${dir}]# "
426
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
427
- else
428
- info="[${user} ${dir}]$ "
429
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
430
- fi
431
-
432
- {
433
- printf "%s" "${info}"
434
- escaped_print "${@}"
435
- printf "%s" " ... "
436
- } >> "${run_logfile}"
437
-
438
- printf "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" >&2
439
- escaped_print >&2 "${@}"
440
- printf "%s\n" "${TPUT_RESET}" >&2
441
-
442
- "${@}"
443
-
444
- ret=$?
445
- if [ ${ret} -ne 0 ]; then
446
- printf >&2 "%s FAILED %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
447
- printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
448
- NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
449
- else
450
- printf >&2 "%s OK %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
451
- printf >> "${run_logfile}" "OK\n"
452
- fi
453
-
454
- return ${ret}
455
-}
456
-
475
portable_del_group() {
476
groupname="${1}"
477
@@ -622,24 +640,6 @@ quit_msg() {
640
fi
641
}
642
625
-rm_file() {
626
- FILE="$1"
627
- if [ -f "${FILE}" ]; then
628
- if user_input "Do you want to delete this file '$FILE' ? "; then
629
- run rm -v "${FILE}"
630
- fi
631
- fi
632
-}
633
-
634
-rm_dir() {
635
- DIR="$1"
636
- if [ -n "$DIR" ] && [ -d "$DIR" ]; then
637
- if user_input "Do you want to delete this directory '$DIR' ? "; then
638
- run rm -v -f -R "${DIR}"
639
- fi
640
- fi
641
-}
642
-
643
safe_pidof() {
644
pidof_cmd="$(command -v pidof 2> /dev/null)"
645
if [ -n "${pidof_cmd}" ]; then