-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.sh
executable file
·40 lines (35 loc) · 1.68 KB
/
debug.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
#### Help:
# To use debug mode you need to call this file from your code e.g.
# '. /some/path/debug.sh'
#
# You can use following env vars to control debug mode:
# DEBUG=[true/false] (default: false) - Intercept exit from script and wait for DEBUG_TIMEOUT
# DEBUG_TIMEOUT <seconds> (default: 3600) - Timeout of debug pause
# VERBOSE=[true/false] (default: false) - Verbose script execution
# Set default value
: "${DEBUG_TIMEOUT:=3600}"
if [[ "${DEBUG}" == "true" ]]; then
echo "#######################################################"
echo "# #"
echo "# DEBUG mode is on! #"
echo "# #"
echo "#######################################################"
trap 'echo "#######################################################";
echo "# #";
echo "# Exit attempt intercepted. #";
echo -n "#";
echo -n "Sleep for ${DEBUG_TIMEOUT} seconds activated!" | sed -e :a -e "s/^.\{1,51\}$/ & /;ta";
echo "#";
echo "# #";
echo "#######################################################";
sleep ${DEBUG_TIMEOUT};' EXIT
fi
if [[ "${VERBOSE}" == "true" ]]; then
echo "#######################################################"
echo "# #"
echo "# VERBOSE mode is on! #"
echo "# #"
echo "#######################################################"
set -x
fi