forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.lunar
228 lines (203 loc) · 6.46 KB
/
messages.lunar
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
# #
# messages - lunar message display functions #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar@tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# #
# moved to messages.lunar by sofar 2003 #
# #
############################################################
# error msgs go to stderr !
error_message() {
echo -e "$*" >&2
}
# normal messages go to stdout
message() {
if [[ -z "$SILENT" ]] ; then
echo -e "$*"
fi
}
verbose_msg() {
if [[ "$VERBOSE" == "on" ]] ; then
message "+ $*" >&2
fi
}
debug_msg() {
local PLUSSES
if [[ -n "$LUNAR_DEBUG" ]] ; then
if [[ "$LUNAR_DEBUG" -ge "2" ]] ; then
PLUSSES="+++++++++++++++++++++++++*"
echo -n "${PLUSSES:0:${#FUNCNAME[@]}} " >&2
fi
if [[ "$LUNAR_DEBUG" -ge "4" ]] ; then
echo -n "$(basename $0)[$$]: " >&2
fi
if [[ "$LUNAR_DEBUG" -ge "3" ]] ; then
echo -n "$(basename ${BASH_SOURCE[1]}):${BASH_LINENO[1]}: " >&2
fi
if [[ "$LUNAR_DEBUG" -ge "2" ]] ; then
if [[ "${FUNCNAME[1]}" != "$1" ]]; then
echo "$@" >&2
else
echo "${FUNCNAME[1]} ($@)" >&2
fi
else
echo "++ $@" >&2
fi
if [[ "$LUNAR_DEBUG" -ge "5" ]] ; then
echo "++ $@" >> $TMPDIR/lp_debuglog.$$
if [ -f $TMPDIR/l_debug_var.$$ ] ; then
mv $TMPDIR/l_debug_var.$$ $TMPDIR/l_debug_var.$$.old
else
return
fi
set | grep '^[A-Z]' | sed 's/^/VAR /' > $TMPDIR/l_debug_var.$$
diff -U0 $TMPDIR/l_debug_var.$$.old $TMPDIR/l_debug_var.$$ | \
grep -v "^@@" | grep "VAR" | tee -a $TMPDIR/lp_debuglog.$$ >&2
fi
fi
}
# function : xterm_msg
# usage : xterm_msg MESSAGE
# purpose : To display a short message in the title bar of a X terminal
xterm_msg() {
debug_msg "xterm_bar ($@)"
echo -ne "\033]0;$HOSTNAME $(basename $0)[$$]: $@ \007"
}
# function : report FILE [description] MODULE VERSION
report() {
local TMP_MAIL
debug_msg "report ($@)"
if [ ! -f "$1" ] ; then
return
fi
if [ "$VIEW_REPORTS" == "on" ] ; then
sound REPORT
if query "View $2 for ${MODULE_COLOR}${3}-${VERSION_COLOR}${4}${DEFAULT_COLOR}${QUERY_COLOR} ?" n ; then
view_file "$1"
fi
fi
if [ "$MAIL_REPORTS" == "on" ] ; then
TMP_MAIL=$(temp_create "mailreport")
date -u > $TMP_MAIL
echo >> $TMP_MAIL
view_file "$1" >> $TMP_MAIL
mail -s "Lunar Report from $HOSTNAME : $2 for $3-$4" \
$ADMIN < $TMP_MAIL 2>/dev/null
temp_destroy $TMP_MAIL
fi
true
}
query() {
local RESPONSE
debug_msg "query ($@)"
# 2 arguments
# query "what do you want? " DEFAULT
if [ -z "$SILENT" ]; then
unset RESPONSE
while [ -z "$RESPONSE" ]; do
if [ -n "$MODULE" ]; then
echo -e -n "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}: "
fi
echo -e -n "${QUERY_COLOR}$1${QUERY_COLOR} [$2] ${DEFAULT_COLOR}"
read -t $PROMPT_DELAY -n 1 RESPONSE
if [ -z "$RESPONSE" ]; then
RESPONSE=${RESPONSE:-$2}
else
echo
fi
case $RESPONSE in
y|Y) true ;;
n|N) false ;;
*) unset RESPONSE ;;
esac
done
else
case $2 in
y|Y) true ;;
n|N) false ;;
*) message "Error: bad input in query()" ; exit 1 ;;
esac
fi
}
# mquery is a wrapper to autodetect if a certain y/n parameter in a module
# config is not set yet and handles the case in a single function
# usage: mquery USE_LILO "Use lilo instead of grub ?" y [yesopts] [noopts]
# note : $MODULE must be set properly
# note : both [yesopts] and [noopts] may be empty or ""
mquery()
{
debug_msg "mquery ($@)"
if [ -n "$MODULE" ]; then
if [ -z "$(get_module_config $1)" ]; then
# it's not set yet... start the asking loop
if query "$2" "$3" ; then
set_module_config "$1" y
else
set_module_config "$1" n
fi
fi
# and lookup the result in case of yes/no opts
if [ "$(get_module_config $1)" == "y" ] ; then
OPTS="$OPTS $4"
else
OPTS="$OPTS $5"
fi
fi
}
color() {
debug_msg "color ($@)"
case $1 in
off) unset MODULE_COLOR
unset VERSION_COLOR
unset QUERY_COLOR
unset LRM_COLOR
unset CHECK_COLOR
unset RESURRECT_COLOR
unset FILE_COLOR
unset SYMLINK_COLOR
unset PROBLEM_COLOR
unset MESSAGE_COLOR
unset DEFAULT_COLOR
COLOR=off
;;
on) COLOR=on
;;
esac
}
sound()
{
debug_msg "sound ($@)"
if [ "$SOUND" == "on" ]; then
if [ -f "$SOUND_DIRECTORY/$SOUND_THEME/$1" ]; then
( cd / ; play "$SOUND_DIRECTORY/$SOUND_THEME/$1" > /dev/null 2>&1 & )
fi
fi
}
# function : show_fancy_progress
# usage : show_fancy_progress <fancy_progress_var_string>
# purpose : display progress ex: show_fancy_progress "Processing: $MODULE"
show_fancy_progress () {
debug_msg "show_fancy_progress ($@)"
echo -en "\r \r$1\r"
}