#!/bin/sh # Early boot, once per boot: busybox init's one ::sysinit action. Mounts what # the kernel has not, stacks a tmpfs on /tmp over the kernel's, then runs the # memory-backed directories, /etc/default/volatiles, mdev, the network and the # deferred maintainer scripts, in that order. Each step is recorded in # /run/brintos-sysinit as " ". # # Nothing here may call setsid or cttyhack, or start a daemon in the # background: this runtime lacks the syscalls, and init waits for this script # before it starts the console. LOG=/run/brintos-sysinit _log= mounted() { awk -v m="$1" '$2 == m { f = 1 } END { exit !f }' /proc/mounts 2>/dev/null } # The log reaches /run once /run is a tmpfs; the earlier steps are kept until then. note() { _log="$_log$1 $2 " mounted /run && printf '%s' "$_log" > "$LOG" } # Run a step if its program is installed, and record how it ended. step() { _name=$1 shift if [ -x "$1" ]; then "$@" note "$_name" "rc=$?" else note "$_name" absent fi } # /etc/default/volatiles, in populate-volatile.sh's format: # , type d, f, l or b. volatiles() { _rc=0 for _f in /etc/default/volatiles/*; do [ -f "$_f" ] || continue sed 's/#.*//' "$_f" | { _bad=0 while read -r _t _u _g _m _p _s; do [ -n "$_s" ] || continue [ -L "$_p" ] && [ ! -e "$_p" ] && _p=$(readlink -f "$_p") case $_t in d) [ -e "$_p" ] || { mkdir -p "$_p" && chown "$_u:$_g" "$_p" && chmod "$_m" "$_p"; } ;; f) [ -e "$_p" ] || { if [ "$_s" = none ]; then : > "$_p"; else cp "$_s" "$_p"; fi && chown "$_u:$_g" "$_p" && chmod "$_m" "$_p" } ;; l) [ -d "$_p" ] && [ ! -L "$_p" ] || [ "$(readlink "$_p")" = "$_s" ] || ln -sfn "$_s" "$_p" ;; b) mounted "$_p" || mount --bind "$_s" "$_p" ;; *) false ;; esac || { echo "brintos-sysinit: $_f: $_t $_p failed" >&2 _bad=1 } done exit $_bad } || _rc=1 done return $_rc } if [ -e /proc/mounts ]; then note proc kernel else mount -t proc proc /proc note proc "rc=$?" fi if mounted /sys; then note sys kernel else mount -t sysfs sysfs /sys note sys "rc=$?" fi mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /tmp note tmp "rc=$?" if mounted /run; then note run mounted else mount -t tmpfs -o mode=0755,nodev,nosuid,strictatime tmpfs /run note run "rc=$?" fi step volatile /sbin/brintos-volatile if [ -d /etc/default/volatiles ]; then volatiles note volatiles "rc=$?" else note volatiles absent fi # A coldplug scan only: mdev's own init script starts it as a daemon through # start-stop-daemon -b, which needs setsid. step mdev /sbin/mdev -s step network /etc/init.d/brintos-network start step run-postinsts /usr/sbin/run-postinsts exit 0