gentoo: only coldplug services started by autoconfig if autoconfig is in the default...
[fbsplash.git] / gentoo / splash-functions-bl1.sh
blob260a172368a4a90915bee7ada64fad9d84f54f5f
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 # ----------------------------------------------------------------------
21 # System boot-up:
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.
33 splash_init() {
34 arg="$1"
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
39 spl_count=0
40 spl_scripts=0
41 spl_execed=""
42 else
43 splash_load_vars
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)
50 spl_count=0
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
58 splash_start
61 splash_svclist_init "${arg}"
62 splash_save_vars
65 # args: none
67 # This function is called when an 'rc_exit' event takes place,
68 # ie. when we're almost done with executing initscripts for a
69 # given runlevel.
70 splash_exit() {
71 # If we're in sysinit or rebooting, do nothing.
72 if [[ ${RUNLEVEL} == "S" || ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]]; then
73 return 0
76 if service_started "xdm"; then
77 splash_comm_send "exit staysilent"
78 else
79 splash_comm_send "exit"
81 splash_cache_destroy
84 splash_update_progress() {
85 local srv=$1
87 # FIXME
88 splash_load_vars
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))
96 else
97 progress=0
100 splash_comm_send "progress ${progress}"
101 splash_save_vars
102 splash_comm_send "paint"
105 ###########################################################################
106 # Common functions
107 ###########################################################################
109 splash_load_vars() {
110 [[ -e ${spl_cachedir}/progress ]] && source ${spl_cachedir}/progress
113 splash_save_vars() {
114 if [[ ! -d ${spl_cachedir} || ! -w ${spl_cachedir} ]]; then
115 return
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
125 splash_warn() {
126 ewarn "$*"
129 splash_err() {
130 eerror "$*"
133 ###########################################################################
134 # Cache
135 ###########################################################################
137 # args: <start|stop>
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
145 retval=$?
147 if [[ ${retval} -ne 0 ]]; then
148 eerror "Unable to create splash cache - switching to verbose."
149 splash_verbose
150 return "${retval}"
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
176 else
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
189 return 0
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
196 return
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 ###########################################################################
206 # Service list
207 ###########################################################################
209 # args: <internal-runlevel>
210 splash_svclist_init() {
211 arg="$1"
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"
216 done
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"
223 done
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"
234 svcs_started=" "
235 svcs_order=""
237 # We're sure our depcache is up-to-date, no need to waste
238 # time checking mtimes.
239 check_mtime() {
240 return 0
243 is_net_up() {
244 local netcount=0
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\..*$")"
255 esac
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
260 return 1
263 return 0
266 service_started() {
267 if [[ -z "${svcs_started/* ${1} */}" ]]; then
268 return 0
269 else
270 return 1
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.
277 start_service() {
278 local svc="$1"
280 if service_started ${svc}; then
281 return
284 # Prevent recursion..
285 svcs_started="${svcs_started}$1 "
287 if is_fake_service "${svc}" "${mylevel}"; then
288 svcs_order="${svcs_order} ${svc}"
289 return
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}"
306 done
307 else
308 if ! service_started ${x} ; then
309 start_service "${x}"
312 done
314 svcs_order="${svcs_order} ${svc}"
315 return
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.
321 autoconfig_svcs() {
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##*/}"
349 done
350 mylevel="${DEFAULTLEVEL}"
351 for i in ${LOGGER_SERVICE} ${sd} ${ss}; do
352 start_service "${i##*/}"
353 done
354 echo "${svcs_order}"
358 ###########################################################################
359 # Other
360 ###########################################################################
362 # Override sulogin calls from baselayout so that we can attempt to remove
363 # the splash screen
364 sulogin() {
365 splash "critical" > /dev/null 2>&1 &
366 /sbin/sulogin $*
369 # vim:ts=4