-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
120 lines (98 loc) · 2.35 KB
/
functions
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# initscripts functions
#
# width:
JOB_NAME="${1}"
# disable colors on broken terminals
TERM_COLORS="$(/bin/tput colors 2>/dev/null)"
if [ $? = 3 ]; then
TERM_COLORS=8
elif [ -n "${TERM_COLORS}" ]; then
case "${TERM_COLORS}" in
*[!0-9]*)
USECOLOR=""
;;
*)
[ "${TERM_COLORS}" -lt 8 ] && USECOLOR=""
;;
esac
else
USECOLOR=""
fi
unset TERM_COLORS
# clear the TZ envvar, so daemons always respect /etc/localtime
unset TZ
# colors:
if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
C_MAIN="\033[1;37;40m" # main text
C_OTHER="\033[1;34;40m" # prefix & brackets
C_SEPARATOR="\033[1;30;40m" # separator
C_BUSY="\033[0;36;40m" # busy
C_FAIL="\033[1;31;40m" # failed
C_DONE="\033[1;37;40m" # completed
C_BKGD="\033[1;35;40m" # backgrounded
C_H1="\033[1;37;40m" # highlight text 1
C_H2="\033[1;36;40m" # highlight text 2
C_CLEAR="\033[1;0m"
fi
if [ -t 1 ]; then
SAVE_POSITION="\033[s"
RESTORE_POSITION="\033[u"
else
SAVE_POSITION=""
RESTORE_POSITION=""
fi
# prefixes:
PREFIX_REG="::"
PREFIX_HL=">"
# functions:
printhl() {
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR}\n"
}
printsep() {
printf "\n${C_SEPARATOR} ------------------------------\n"
}
line_start() {
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR}"
}
line_append() {
printf "${C_MAIN}${1}"
}
line_end() {
printf "${C_CLEAR}\n"
}
stat_start() {
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
}
stat_done() {
if ! [ "${1}" = "" ]; then
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
else
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_REG} ${C_MAIN}Done${C_CLEAR}\n"
fi
}
stat_fail() {
if ! [ "${1}" = "" ]; then
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_REG} ${C_FAIL}${1}${C_CLEAR}\n"
else
printf "${C_H1}${JOB_NAME} ${C_OTHER}${PREFIX_REG} ${C_FAIL}Failed${C_CLEAR}\n"
fi
}
stat_die() {
retval=1
[ "$1" = "" ] || retval=$1
stat_fail
exit $retval
}
status() {
stat_start "$1"
shift
$* >/dev/null 2>&1
if [ $? -eq 0 ]; then
stat_done
return 0
else
stat_fail
return 1
fi
}