blob: 63999a1d5afa227bab31e446119642dc2f9b4540 (
plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#
# initscripts functions
#
# width:
STAT_COL=$(/bin/stty size)
# strip the rows number, we just want columns
STAT_COL=${STAT_COL##* }
if [ "$STAT_COL" = "0" ]; then
# if output was 0 (serial console), set default width to 80
STAT_COL=80
elif [ ! -t 1 ]; then
# disable color on output to non-tty
STAT_COL=80
USECOLOR=""
fi
# we use 13 characters for our own stuff
STAT_COL=$(($STAT_COL - 13))
# 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
# 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"
DEL_TEXT="\033[$(($STAT_COL+4))G"
fi
# prefixes:
PREFIX_REG="::"
PREFIX_HL=" >"
# functions:
deltext() {
printf "${DEL_TEXT}"
}
printhl() {
printf "${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR} \n"
}
printsep() {
printf "\n${C_SEPARATOR} ------------------------------\n"
}
stat_bkgd() {
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
deltext
printf " ${C_OTHER}[${C_BKGD}BKGD${C_OTHER}]${C_CLEAR} "
}
stat_busy() {
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
printf "${SAVE_POSITION}"
deltext
printf " ${C_OTHER}[${C_BUSY}BUSY${C_OTHER}]${C_CLEAR} "
}
stat_append() {
printf "${RESTORE_POSITION}"
printf "${C_MAIN}${1}${C_CLEAR}"
printf "${SAVE_POSITION}"
}
stat_done() {
deltext
printf " ${C_OTHER}[${C_DONE}DONE${C_OTHER}]${C_CLEAR} \n"
}
stat_fail() {
deltext
printf " ${C_OTHER}[${C_FAIL}FAIL${C_OTHER}]${C_CLEAR} \n"
}
stat_die() {
retval=1
[ "$1" = "" ] || retval=$1
stat_fail
exit $retval
}
status() {
stat_busy "$1"
shift
$* >/dev/null 2>&1
if [ $? -eq 0 ]; then
stat_done
return 0
else
stat_fail
return 1
fi
}
# daemons:
add_daemon() {
[ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons
/bin/touch /var/run/daemons/$1
}
rm_daemon() {
/bin/rm -f /var/run/daemons/$1
}
ck_daemon() {
[ -f /var/run/daemons/$1 ] && return 1
return 0
}
ck_depends() {
for daemon in $@; do
if ck_daemon $daemon; then
/etc/rc.d/$daemon start
fi
done
}
#Source additional functions at the end to allow overrides
if [ -d /etc/rc.d/functions.d/ ]; then
for f in $(/bin/ls /etc/rc.d/functions.d/); do
. /etc/rc.d/functions.d/$f
done
fi
# End of file
# vim: set ts=2 noet:
|