#!/bin/sh
# system one time initialization tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /etc/runit/functions

if [ -x /lib/vdev/vdev_modprobe ]; then
        /lib/vdev/vdev_modprobe -b
fi

if [ -f /etc/runit/native.boot.run -o -n "$bootrun" ] && [ -d /etc/runit/boot-run ]; then
        for f in /etc/runit/boot-run/*.sh; do
                [ -r "$f" ] && . "$f"
        done
else
        for script in /etc/rcS.d/S* ; do
                path=$(realpath "$script")
                name=${path##*/}
                [ -d "/etc/sv/$name" ] && continue
                [ -e "/etc/runit/no.emulate.sysv.d/$name" ] && continue
                if [ "$name" = 'alsa-utils' ]; then # arg for alsa-utils is the sound card
                        "$script" start
                        continue
                fi
                # bootlogd's sysvinit script is too slow and make little sense with runit
                if [ "$name" = 'bootlogd' ]; then
                        continue
                fi
                "$script" start --force-sysv
        done
fi

# Start core services: one-time system tasks.
for f in /etc/runit/core-services/*.sh; do
        [ -r $f ] && . $f
done

# Now /run is mounted.
install -m000 /dev/null /run/runit.stopit
install -m000 /dev/null /run/runit.reboot

# That is it.  We do as little, as possible at stage1. Services, that do
# not have runscripts and invoked via init.d scripts are started at
# stage2. This way, daemon that hangs or otherwise misbehave do not
# block whole boot process.
#
# Thanks to Lorenz for suggestion.

