Skip to content

Commit 962cd12

Browse files
author
Adis Halilovic
committed
fix a bit DEBUG
1 parent 66a5d39 commit 962cd12

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

main.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ spinner_msg() { #{{{
137137
local msg="$3"
138138
if [[ -z "$status" ]]; then
139139
printf "%s %s.. ${C_BOLD}%s${C_RESET}" "$(log_date)" "${1}" "${msg}"
140+
if [[ "$LOG_DEBUG" =~ true|True ]]; then printf "\n"; fi
140141
elif (( status==0 )); then
141142
printf "%s %s.. ${C_GREEN_BOLD}%s${C_RESET}\n" "$(log_date)" "${1}" "${msg:="Done"}"
142143
elif (( status>0 || status<0 )); then
@@ -147,7 +148,7 @@ spinner_msg() { #{{{
147148

148149
debug() { #{{{
149150
[[ "$LOG_DEBUG" =~ true|True ]] && \
150-
printf "%s ${C_MAGENTA_BOLD}DEBUG: ${C_RESET} %s${C_BOLD} %s${C_RESET} %s\n" "$(log_date)" "${1}" "${2}" "${@:3}"
151+
printf "%s ${C_MAGENTA_BOLD}DEBUG:${C_RESET} %s${C_BOLD} %s${C_RESET} %s\n" "$(log_date)" "${1}" "${2}" "${@:3}"
151152
}
152153
#}}}: debug
153154

@@ -468,7 +469,9 @@ api_call() { #{{{
468469
fi
469470

470471
debug "Response:" \
471-
&& echo "${response}"
472+
&& echo "-----" \
473+
&& echo "${response}" \
474+
&& echo "-----"
472475

473476
# get first status code from response
474477
status_code="$(echo "$response" \
@@ -512,7 +515,7 @@ api_call() { #{{{
512515
setup_cron() { #{{{
513516
local temp_file
514517

515-
temp_file=$(mktemp)
518+
temp_file=$(mktemp -t crontab_XXX.bup)
516519
crontab -l > "$temp_file" 2>/dev/null || echo "" > "$temp_file"
517520

518521
if grep -qi -E "status|prune" "$temp_file"; then
@@ -529,7 +532,7 @@ setup_cron() { #{{{
529532
clean_cron() { #{{{
530533
local temp_file
531534

532-
temp_file=$(mktemp)
535+
temp_file=$(mktemp -t crontab_XXX.bup)
533536
crontab -l > "$temp_file" 2>/dev/null
534537

535538
if [[ -s "$temp_file" ]]; then
@@ -565,22 +568,24 @@ spinner() { #{{{
565568
local delay=0.15
566569
local spinstr='|/-\'
567570
spinner_msg "$msg"
568-
if [[ "${LOG_DEBUG}" == "false" ]]; then
571+
if [[ "${LOG_DEBUG}" =~ false|False ]]; then
569572
while ps a | awk '{print $1}' | grep "${spinner_pid}" >&/dev/null; do
570573
local temp=${spinstr#?}
571574
printf "${C_BOLD}[%c]${C_RESET}" "$spinstr"
572575
local spinstr=$temp${spinstr%"$temp"}
573576
sleep $delay
574577
printf "\b\b\b"
575578
done
576-
# else
577-
# tail -n0 -f "${log_file}" --pid "${spinner_pid}"
579+
else
580+
tail -n0 -f "${log_file}" --pid "${spinner_pid}"
578581
fi
579582
wait "${spinner_pid}"
580583
local exit_code=$?
581584
printf " \b\b\b\b\b\r"
582-
debug "$msg:" "$exit_code"
583-
spinner_msg "$msg" "$exit_code"
585+
debug "$msg (exit code):" "$exit_code"
586+
if [[ ! "${LOG_DEBUG}" =~ true|True ]]; then
587+
spinner_msg "$msg" "$exit_code"
588+
fi
584589
(( exit_code!=0 )) && log_err && exit $exit_code
585590
return $exit_code
586591
}
@@ -1169,6 +1174,7 @@ deregister_instance() { #{{{
11691174
debug "Payload:" "${payload}"
11701175

11711176
spinner_wait "Trying to deregister instance.."
1177+
if [[ "$LOG_DEBUG" =~ true|True ]]; then printf "\n"; fi
11721178
if api_call "$payload"; then
11731179
spinner_msg "Trying to deregister instance" 0
11741180
clean_local_setup & spinner "$!" "Starting cleanup"

0 commit comments

Comments
 (0)