2 # splash-functions-bl1.sh
3 # -----------------------
4 # This is a legacy file for baselayout v1. It won't be extended to
5 # support any new features. For these, consult the code of the splash
6 # plugin for baselayout v2.
8 # Distributed under the terms of the GNU General Public License v2
10 # Author: Michal Januszewski <spock@gentoo.org>
11 # Maintainer: Michal Januszewski <spock@gentoo.org>
13 # ####################################################################
14 # Change any settings ONLY if you are sure what you're doing.
15 # Don't cry if it breaks afterwards.
16 # ####################################################################
18 # ----------------------------------------------------------------------
19 # RUNLEVEL SOFTLEVEL INTERNAL SVCS
20 # ----------------------------------------------------------------------
22 # S <none> sysinit CRITICAL_SERVICES
23 # S boot <none> boot_serv - CRITICAL_SERVICES
24 # 3 default <none> std
26 # System restart/shutdown:
27 # 0/6 reboot/shutdown <none> all
29 # args: <internal_runlevel>
31 # This function is called when an 'rc_init' event takes place,
32 # ie. when the runlevel is changed.
36 # Initialize variables -- either set the default values or load them from a file
37 if [[ ${RUNLEVEL} == "S" && ${arg} == "sysinit" ]] ||
38 [[ ${SOFTLEVEL} == "reboot" ||
${SOFTLEVEL} == "shutdown" ]]; then
46 export spl_count spl_scripts spl_execed
48 if [[ ${RUNLEVEL} == "S" && ${arg} == "sysinit" ]]; then
49 spl_scripts
=$
(splash_svclist_get start |
tr ' ' '\n' |
wc -l)
51 elif [[ ${SOFTLEVEL} == "reboot" ||
${SOFTLEVEL} == "shutdown" ]]; then
52 spl_started
=($
(dolisting
"${svcdir}/started/"))
53 spl_scripts
=${#spl_started[*]}
56 if [[ ${RUNLEVEL} == "S" && ${arg} == "sysinit" ]] ||
57 [[ ${SOFTLEVEL} == "reboot" ||
${SOFTLEVEL} == "shutdown" ]]; then
61 splash_svclist_init
"${arg}"
67 # This function is called when an 'rc_exit' event takes place,
68 # ie. when we're almost done with executing initscripts for a
71 # If we're in sysinit or rebooting, do nothing.
72 if [[ ${RUNLEVEL} == "S" || ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]]; then
76 if service_started
"xdm"; then
77 splash_comm_send
"exit staysilent"
79 splash_comm_send
"exit"
84 splash_update_progress
() {
89 [[ -n "${spl_execed}" && -z "${spl_execed//* $srv */}" ]] && return
90 [[ -z "${spl_scripts}" ]] && return
91 spl_execed
="${spl_execed} ${srv} "
92 spl_count
=$
((${spl_count} + 1))
94 if [ "${spl_scripts}" -gt 0 ]; then
95 progress
=$
(($spl_count * 65535 / $spl_scripts))
100 splash_comm_send
"progress ${progress}"
102 splash_comm_send
"paint"
105 ###########################################################################
107 ###########################################################################
110 [[ -e ${spl_cachedir}/progress
]] && source ${spl_cachedir}/progress
114 if [[ ! -d ${spl_cachedir} ||
! -w ${spl_cachedir} ]]; then
118 t
="spl_execed=\"${spl_execed}\"\n"
119 t
="${t}spl_count=${spl_count}\n"
120 t
="${t}spl_scripts=${spl_scripts}\n"
122 (echo -e "$t" > ${spl_cachedir}/progress
) 2>/dev
/null
133 ###########################################################################
135 ###########################################################################
139 # Prepare the splash cache.
140 splash_cache_prep
() {
141 # Mount an in-RAM filesystem at spl_tmpdir.
142 mount
-ns -t "${spl_cachetype}" cachedir
"${spl_tmpdir}" \
143 -o rw
,mode
=0644,size
="${spl_cachesize}"k
147 if [[ ${retval} -ne 0 ]]; then
148 eerror
"Unable to create splash cache - switching to verbose."
153 # Copy the dependency cache and services lists to our new cache dir.
154 # With some luck, we won't have to update it.
155 cp -a ${svcdir}/{depcache
,deptree
} "${spl_tmpdir}" 2>/dev
/null
156 cp -a ${spl_cachedir}/{svcs_start
,svcs_stop
,levels
} "${spl_tmpdir}" 2>/dev
/null
158 # Now that the data from the old cache is copied, move tmpdir to cachedir.
159 mount
-n --move "${spl_tmpdir}" "${spl_cachedir}"
161 h
=$
(ls -ld --full-time ${spl_cachedir}/deptree
2>/dev
/null | cut
-f6,7,8 -d' ')
163 # Point depscan.sh to our cachedir
164 /sbin
/depscan.sh
--svcdir "${spl_cachedir}"
166 if [[ "$1" == "start" ]]; then
167 # Check whether the list of services that will be started during boot
168 # needs updating. This is generally the case if:
169 # - one of the caches doesn't exist
170 # - our deptree was out of date
171 # - we're booting with a different boot/default level than the last time
172 # - one of the runlevel dirs has been modified since the last boot
173 if [[ ! -e ${spl_cachedir}/levels || \
174 ! -e ${spl_cachedir}/svcs_start
]]; then
175 echo $
(splash_svclist_update
"start") > ${spl_cachedir}/svcs_start
177 local lastlev timestamp
178 { read lastlev
; read timestamp
; } < ${spl_cachedir}/levels
179 if [[ "${lastlev}" != "${BOOTLEVEL}/${DEFAULTLEVEL}" || \
180 "${timestamp}" != "$(ls -ld --full-time /etc/runlevels/${BOOTLEVEL} | cut -f6,7,8 -d' ')/$(ls -ld --full-time /etc/runlevels/${DEFAULTLEVEL} | cut -f6,7,8 -d' ')" || \
181 "$(ls -ld --full-time ${spl_cachedir}/deptree 2>/dev/null | cut -f6,7,8 -d' ')" != "${h}" ]]; then
182 echo $
(splash_svclist_update
"start") > ${spl_cachedir}/svcs_start
186 echo -n > ${spl_cachedir}/profile
192 splash_cache_destroy
() {
193 # There's no point in saving all the data if we're running off a livecd.
194 if [[ -n "${CDBOOT}" ]]; then
195 umount
-l "${spl_cachedir}" 2>/dev
/null
199 splash_cache_cleanup envcache depcache deptree svcs_start svcs_stop
200 echo "${BOOTLEVEL}/${DEFAULTLEVEL}" > "${spl_cachedir}/levels"
201 echo "$(stat -c '%y' /etc/runlevels/${BOOTLEVEL})/$(stat -c '%y' /etc/runlevels/${DEFAULTLEVEL})" \
202 >> "${spl_cachedir}/levels"
205 ###########################################################################
207 ###########################################################################
209 # args: <internal-runlevel>
210 splash_svclist_init
() {
213 if [[ ${SOFTLEVEL} == "reboot" ||
${SOFTLEVEL} == "shutdown" ]]; then
214 for i
in `dolisting "${svcdir}/started/" | sed -e "s#${svcdir}/started/##g"`; do
215 splash_svc_update
${i} "svc_inactive_stop"
217 elif [[ ${RUNLEVEL} == "S" ]]; then
218 local svcs
=$
(splash_svclist_get start
)
220 if [[ ${arg} == "sysinit" ]]; then
221 for i
in ${svcs} ; do
222 splash_svc_update
${i} "svc_inactive_start"
228 splash_svclist_update
() {
230 # Source our own deptree and required functions
231 source ${spl_cachedir}/deptree
232 [[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh"
237 # We're sure our depcache is up-to-date, no need to waste
238 # time checking mtimes.
246 case "${RC_NET_STRICT_CHECKING}" in
248 netcount
="$(echo ${svcs_started} | tr ' ' '\n' | \
249 egrep -c "\
/net\..
*$
")"
252 netcount
="$(echo ${svcs_started} | tr ' ' '\n' | \
253 grep -v 'net\.lo' | egrep -c "\
/net\..
*$
")"
257 # Only worry about net.* services if this is the last one running,
258 # or if RC_NET_STRICT_CHECKING is set ...
259 if [[ ${netcount} -lt 1 ||
${RC_NET_STRICT_CHECKING} == "yes" ]]; then
267 if [[ -z "${svcs_started/* ${1} */}" ]]; then
274 # This simulates the service startup and has to mimic the behaviour of
275 # svc_start() from /sbin/runscript.sh and start_service() from rc-functions.sh
276 # as closely as possible.
280 if service_started
${svc}; then
284 # Prevent recursion..
285 svcs_started
="${svcs_started}$1 "
287 if is_fake_service
"${svc}" "${mylevel}"; then
288 svcs_order
="${svcs_order} ${svc}"
292 svcs_startup
="$(ineed "${svc}") \
293 $(valid_iuse "${svc}") \
294 $(valid_iafter "${svc}")"
296 for x
in ${svcs_startup} ; do
297 if [[ ${x} == "net" ]] && [[ ${svc%%.*} != "net" || ${svc##*.} == ${svc} ]] && ! is_net_up
; then
298 local netservices
="$(dolisting "/etc
/runlevels
/${BOOTLEVEL}/net.
*") \
299 $(dolisting "/etc
/runlevels
/${mylevel}/net.
*")"
301 for y
in ${netservices} ; do
302 mynetservice
="${y##*/}"
303 if ! service_started
${mynetservice} ; then
304 start_service
"${mynetservice}"
308 if ! service_started
${x} ; then
314 svcs_order
="${svcs_order} ${svc}"
318 # This function should return a list of services that will be started
319 # from /etc/init.d/autoconfig. In order to do that, we source
320 # /etc/init.d/autoconfig and use its list_services() function.
322 [[ -r /etc
/init.d
/autoconfig
]] ||
return
323 .
/etc
/init.d
/autoconfig
324 echo "$(list_services)"
327 as
="$(autoconfig_svcs)"
328 [[ -n "${SOFTLEVEL}" ]] && ss
="$(dolisting "/etc
/runlevels
/${SOFTLEVEL}/") "
329 sb
="$(dolisting "/etc
/runlevels
/${BOOTLEVEL}/") "
330 sd
="$(dolisting "/etc
/runlevels
/${DEFAULTLEVEL}/") "
332 # If autoconfig is one of the services that will be started,
333 # insert an updated list of services into our list.
334 if [[ -z "${ss/*\/autoconfig */}" ]]; then
335 ss
="${ss/\/autoconfig /\/autoconfig $as }"
338 if [[ -z "${sb/*\/autoconfig */}" ]]; then
339 sb
="${sb/\/autoconfig /\/autoconfig $as }"
342 if [[ -z "${sd/*\/autoconfig */}" ]]; then
343 sd
="${sd/\/autoconfig /\/autoconfig $as }"
346 mylevel
="${BOOTLEVEL}"
347 for i
in ${CRITICAL_SERVICES} ${sb}; do
348 start_service
"${i##*/}"
350 mylevel
="${DEFAULTLEVEL}"
351 for i
in ${LOGGER_SERVICE} ${sd} ${ss}; do
352 start_service
"${i##*/}"
358 ###########################################################################
360 ###########################################################################
362 # Override sulogin calls from baselayout so that we can attempt to remove
365 splash
"critical" > /dev
/null
2>&1 &