updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / splashy-full / splash-initscripts
bloba3e49a4a92161193136e562043b898b57c899bb3
2 # initscripts-splash functions
5 . /etc/splash.conf
7 if [ "$SPLASH_DEBUG" = "true" ]; then
8         if ! [ -d /var/log/splash ]; then
9                 mkdir -p /var/log/splash
10         fi
11         if ! [ -f /var/log/splash/splash.log ]; then
12                 mount -ns -t tmpfs -o size=1M tmpfs /var/log/splash
13                 echo "Hello damned debugger" > /var/log/splash/splash.log
14         fi
17 debug_log() {
18         [ "$SPLASH_DEBUG" = "true" ] || return 1
20         echo "$1" >> /var/log/splash/splash.log
23 splash_enabled_cmdline() { debug_log "$0 ${FUNCNAME}"
24         local ENABLE=false
25         local SINGLE=false
27         for x in $CMDLINE; do
28                 case $x in
29                         single)
30                                 SINGLE=true
31                         ;;
32                         splash)
33                                 ENABLE=true
34                         ;;
35                         nosplash)
36                                 ENABLE=false
37                         ;;
38                 esac
39         done
41         [ "${SINGLE}" = "false" ] || return 1
42         [ "${ENABLE}" = "true" ] || return 1
44         return 0
47 splash_enabled_config() { debug_log "$0 ${FUNCNAME}"
48         if [[ -n ${SPLASH} && -f /etc/rc.d/${SPLASH}-functions ]]; then
49                 return 0
50         else
51                 if [[ -f /etc/rc.d/splashy-functions ]]; then
52                         SPLASH="splashy"
53                         return 0
54                 else
55                         return 1
56                 fi
57         fi
60 if [ -z "$RUNLEVEL" ]; then
61         return 0
64 if ! splash_enabled_cmdline; then
65         return 0
68 if ! splash_enabled_config; then
69         return 0
72 count_daemons() {
73         local COUNT=0
74         for daemon in "${DAEMONS[@]}"; do
75                 if [ "$daemon" = "${daemon#!}" ]; then
76                         ((COUNT++))
77                 fi
78         done
80         echo ${COUNT}
83 count_stats() {
84         local COUNT=$(grep -e status -e stat_busy /etc/${1} | grep -c -v \#)
86         if ! [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
87                 ((COUNT--))
88         fi
89         if ! [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then
90                 ((COUNT--))
91         fi
93         echo ${COUNT}
96 set_sysinit() { debug_log "$0 ${FUNCNAME}"
97         SPLASH_PROGRESS_STATS=$(count_stats rc.sysinit)
98         SPLASH_PROGRESS_DAEMONS=$(count_daemons)
99         SPLASH_PROGRESS_TOTAL=$(($SPLASH_PROGRESS_STATS+$SPLASH_PROGRESS_DAEMONS))
100         SPLASH_PROGRESS_COUNT=0
101         SPLASH_AUTORUN_COMMAND="splash_sysinit"
103         debug_log "SPLASH_PROGRESS_TOTAL=$SPLASH_PROGRESS_TOTAL SPLASH_AUTORUN_COMMAND=$SPLASH_AUTORUN_COMMAND"
106 set_multi() { debug_log "$0 ${FUNCNAME}"
107         SPLASH_PROGRESS_STATS=$(count_stats rc.sysinit)
108         SPLASH_PROGRESS_DAEMONS=$(count_daemons)
109         SPLASH_PROGRESS_TOTAL=$(($SPLASH_PROGRESS_STATS+$SPLASH_PROGRESS_DAEMONS))
110         SPLASH_PROGRESS_COUNT=$(($SPLASH_PROGRESS_STATS-1))
111         SPLASH_AUTORUN_COMMAND="splash_multi"
113         debug_log "SPLASH_PROGRESS_TOTAL=$SPLASH_PROGRESS_TOTAL SPLASH_AUTORUN_COMMAND=$SPLASH_AUTORUN_COMMAND"
116 set_shutdown() { debug_log "$0 ${FUNCNAME}"
117         SPLASH_PROGRESS_STATS=$(count_stats rc.shutdown)
118         SPLASH_RUNNING_DAEMONS=(`/bin/ls /var/run/daemons`)
119         SPLASH_PROGRESS_DAEMONS=${#SPLASH_RUNNING_DAEMONS[*]}
120         SPLASH_PROGRESS_TOTAL=$(($SPLASH_PROGRESS_STATS+$SPLASH_PROGRESS_DAEMONS))
121         SPLASH_PROGRESS_COUNT=0
122         SPLASH_AUTORUN_COMMAND="splash_shutdown"
124         debug_log "SPLASH_PROGRESS_TOTAL=$SPLASH_PROGRESS_TOTAL SPLASH_AUTORUN_COMMAND=$SPLASH_AUTORUN_COMMAND"
127 if [ -z "${SPLASH_INIT_DONE}" ]; then
128         export SPLASH_INIT_DONE="true"
130         debug_log "$0 Running initscript..."
132         case "$RUNLEVEL" in
133                 S)
134                         set_sysinit
135                         SPLASH_STATUS_MESSAGE="Booting Arch Linux..."
136                         ;;
137                 3)
138                         set_multi
139                         SPLASH_STATUS_MESSAGE="Loading daemons..."
140                         ;;
141                 5)
142                         set_multi
143                         SPLASH_STATUS_MESSAGE="Loading daemons..."
144                         ;;
145                 6)
146                         set_shutdown
147                         SPLASH_STATUS_MESSAGE="Rebooting Arch Linux..."
148                         ;;
149                 0)
150                         set_shutdown
151                         SPLASH_STATUS_MESSAGE="Shutting down Arch Linux..."
152                         ;;
153         esac
156 . /etc/rc.d/${SPLASH}-functions
158 # splash functions:
160 splash_progress() { debug_log "$0 ${FUNCNAME}"
161         if [ -n "$SPLASH_PROGRESS_COUNT" ]; then
162                 ${SPLASH}_progress $SPLASH_PROGRESS_COUNT $SPLASH_PROGRESS_TOTAL
163                 ((SPLASH_PROGRESS_COUNT++))
164         fi
167 splash_print() { debug_log "$0 ${FUNCNAME}"
168         ${SPLASH}_print "${1}"
170         debug_log "$1"
173 splash_exit() { debug_log "$0 ${FUNCNAME}"
174         ${SPLASH}_exit ${DEFAULT_TTY} ${SWITCH_TTY}
177 splash_sysinit() { debug_log "$0 ${FUNCNAME}"
178         ${SPLASH}_sysinit ${DEFAULT_TTY}
181 splash_multi() { debug_log "$0 ${FUNCNAME}"
182         ${SPLASH}_multi
184         trap splash_exit 0
185         splash_progress
188 splash_shutdown() { debug_log "$0 ${FUNCNAME}"
189         ${SPLASH}_shutdown ${DEFAULT_TTY}
191         if [ -n "`pidof $SPLASH`" ]; then
192                 export KILLALL5_OPTS="-o `pidof $SPLASH`"
193         fi
196 if [ -n "${SPLASH_AUTORUN_COMMAND}" ]; then
197         $SPLASH_AUTORUN_COMMAND
198         splash_print "${SPLASH_STATUS_MESSAGE}"
199         sleep 0.5
202 # functions:
204 deltext() { debug_log "$0 ${FUNCNAME}"
205         if [ "$CONSOLE_PRINT" == "true" ]; then
206                 printf "${DEL_TEXT}"
207         else
208                 return 0
209         fi
212 printhl() { debug_log "$0 ${FUNCNAME}"
213         if [ "$CONSOLE_PRINT" == "true" ]; then
214                 printf "${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR} \n"
215         else
216                 return 0
217         fi
220 printsep() { debug_log "$0 ${FUNCNAME}"
221         if [ "$CONSOLE_PRINT" == "true" ]; then
222                 printf "\n${C_SEPARATOR}   ------------------------------\n"
223         else
224                 return 0
225         fi
228 stat_bkgd() { debug_log "$0 ${FUNCNAME}"
229         if [ "$CONSOLE_PRINT" == "true" ]; then
230                 printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
231                 deltext
232                 printf "   ${C_OTHER}[${C_BKGD}BKGD${C_OTHER}]${C_CLEAR} "
233         fi
236 stat_busy() { debug_log "$0 ${FUNCNAME}"
237         if [ "$CONSOLE_PRINT" == "true" ]; then
238                 printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
239                 printf "${SAVE_POSITION}"
240                 deltext
241                 printf "   ${C_OTHER}[${C_BUSY}BUSY${C_OTHER}]${C_CLEAR} "
242         fi
243         splash_print "${1}"
246 stat_append() { debug_log "$0 ${FUNCNAME}"
247         if [ "$CONSOLE_PRINT" == "true" ]; then
248                 printf "${RESTORE_POSITION}"
249                 printf "${C_MAIN}${1}${C_CLEAR}"
250                 printf "${SAVE_POSITION}"
251         else
252                 return 0
253         fi
256 stat_done() { debug_log "$0 ${FUNCNAME}"
257         if [ "$CONSOLE_PRINT" == "true" ]; then
258                 deltext
259                 printf "   ${C_OTHER}[${C_DONE}DONE${C_OTHER}]${C_CLEAR} \n"
260         fi
261         splash_progress
264 stat_fail() { debug_log "$0 ${FUNCNAME}"
265         if [ "$CONSOLE_PRINT" == "true" ]; then
266                 printf "   ${C_OTHER}[${C_FAIL}FAIL${C_OTHER}]${C_CLEAR} \n"
267         fi
268         splash_print "Something failed, killing splash..."
269         sleep 2
270         splash_exit
273 #daemons:
275 log_daemon() { debug_log "$0 ${FUNCNAME}"
276         case $1 in
277                 ?dm|slim)
278                         splash_exit
279                 ;;
280         esac
283 start_daemon() { debug_log "$0 ${FUNCNAME}"
284         log_daemon $1
285         splash_progress
286         /etc/rc.d/$1 start
289 start_daemon_bkgd() { debug_log "$0 ${FUNCNAME}"
290         if [ "$CONSOLE_PRINT" == "true" ]; then
291                 stat_bkgd "Starting $1"
292         fi
293         log_daemon $1
294         (/etc/rc.d/$1 start) &>/dev/null &
295         splash_progress
298 stop_daemon() { debug_log "$0 ${FUNCNAME}"
299         /etc/rc.d/$1 stop
301         for daemon in ${SPLASH_RUNNING_DAEMONS[@]}; do
302                 if [ "$daemon" = "$1" ]; then
303                         splash_progress
304                         break
305                 fi
306         done
309 # End of file
310 # vim: set ts=2 noet: