-
Notifications
You must be signed in to change notification settings - Fork 40
/
prologue.sh
89 lines (79 loc) · 1.59 KB
/
prologue.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This Bash file is not designed to be called directly, but rather is read by
# `source` Bash builtin command in the very beginning of another Bash script.
PS4='+${BASH_SOURCE[0]}:$LINENO: '
if [[ -t 1 ]] && type -t tput >/dev/null; then
if (( "$(tput colors)" == 256 )); then
PS4='$(tput setaf 10)'$PS4'$(tput sgr0)'
else
PS4='$(tput setaf 2)'$PS4'$(tput sgr0)'
fi
fi
new_args=()
while (( $# > 0 )); do
arg="$1"
shift
case "$arg" in
--debug)
debug=yes
new_args+=("$@")
break
;;
--)
new_args+=(-- "$@")
break
;;
*)
new_args+=("$arg")
;;
esac
done
set -- ${new_args[@]+"${new_args[@]}"}
unset new_args
if [[ ${debug-no} == yes || ${VERBOSE+DEFINED} == DEFINED ]]; then
set -x
fi
unset debug
function print_error_message ()
{
if [[ -t 2 ]] && type -t tput >/dev/null; then
if (( "$(tput colors)" == 256 )); then
echo "$(tput setaf 9)$1$(tput sgr0)" >&2
else
echo "$(tput setaf 1)$1$(tput sgr0)" >&2
fi
else
echo "$1" >&2
fi
}
function die_with_logic_error ()
{
set +x
print_error_message "$1: error: A logic error."
exit 1
}
function die_with_user_error ()
{
set +x
print_error_message "$1: error: $2"
print_error_message "Try \`$1 --help' for more information."
exit 1
}
function die_with_runtime_error ()
{
set +x
print_error_message "$1: error: $2"
exit 1
}
rollback_stack=()
function push_rollback_command ()
{
rollback_stack+=("$1")
}
function rollback ()
{
for (( i = ${#rollback_stack[@]} - 1; i >= 0; --i )); do
eval "${rollback_stack[$i]}"
done
rollback_stack=()
}
trap rollback EXIT