diff options
-rw-r--r-- | rc.lib | 114 |
1 files changed, 78 insertions, 36 deletions
@@ -31,42 +31,59 @@ log() { } -out() { printf '\033[1;36m-> \033[39m%s\033[m\n' "$@" | log ;} -err() { printf '\033[1;31m!> \033[39m%s\033[m\n' "$@" | log ;} - -shell() { - err "Dropping to shell, type 'exit' to continue the boot process." - sh -l +out() { + printf '%b%s \033[39m%s\033[m\n' "${3:-"\033[1;36m"}" "${2:-->}" "$1" + log "$1" } -run_hook() { - out "Running '$1' hooks..." - for hook in "/etc/init/"*".$1" "/usr/lib/init/hooks/"*".$1"; do - [ -f "$hook" ] || continue - out "Running '$hook'..." - . "$hook" - done -} +err() { out "$1" "!>" "\033[1;31m" ;} + +device_helper() { + # We devices based on user preference, and what's available + # on the system. + # + # Get the device daemon to be used, if we don't have a daemon + # available on the system, do not continue any further. + [ "$devd" ] || { + devd=$(command -v udevd) || devd=$(command -v mdev) || + return 0 + } -random() { - seed=/var/random.seed case "$1" in - load) - out "Seeding random..." - [ -f "$seed" ] || { - out "Generating entropy, this might take a while..." - dd count=1 bs=512 if=/dev/random of="$seed" 2>/dev/null - } - cat "$seed" > /dev/urandom - ;; - save) - mkdir -p "${seed%/*}" - out "Saving random seed..." - dd count=1 bs=512 if=/dev/urandom of="$seed" 2>/dev/null - ;; + settle) case "${devd##*/}" in + udevd) + udevd -d + udevadm trigger -c add -t subsystems + udevadm trigger -c add -t devices + udevadm settle + ;; + mdev) + mdev -s + mdev -df & mdev_pid=$! + ;; + esac + ;; + exit) case "${devd##*/}" in + udevd) + udevadm control --exit + ;; + mdev) + [ "$mdev_pid" ] && kill "$mdev_pid" + command -v mdev > /proc/sys/kernel/hotplug + ;; + esac esac } +mnt() { + [ -f /proc/mounts ] && while read -r _ mnt _; do + case "$mnt" in "$1") return 0; esac + done < /proc/mounts + + mnt="$1"; shift + mount "$@" "$mnt" 2>&1 | log +} + parse_cmdline() { # This is a primitive way of parsing kernel command line # options. Before now, carbs-init ignored these options @@ -86,16 +103,41 @@ parse_cmdline() { ro) RO=1 ;; forcefsck) FORCEFSCK="-f" ;; fastboot) FASTBOOT=1 ;; - loglevel=?) dmesg_level=${arg##*=} ;; + loglevel=?) dmesg_level=${arg#loglevel=} ;; + devd=*) devd=${arg#devd=} ;; esac done } -mnt() { - [ -f /proc/mounts ] && while read -r _ mnt _; do - case "$mnt" in "$1") return 0; esac - done < /proc/mounts +random() { + seed=/var/random.seed + case "$1" in + load) + out "Seeding random..." + [ -f "$seed" ] || { + out "Generating entropy, this might take a while..." + dd count=1 bs=512 if=/dev/random of="$seed" 2>/dev/null + } + cat "$seed" > /dev/urandom + ;; + save) + mkdir -p "${seed%/*}" + out "Saving random seed..." + dd count=1 bs=512 if=/dev/urandom of="$seed" 2>/dev/null + ;; + esac +} - mnt="$1"; shift - mount "$@" "$mnt" 2>&1 | log +run_hook() { + out "Running '$1' hooks..." + for hook in "/etc/init/"*".$1" "/usr/lib/init/hooks/"*".$1"; do + [ -f "$hook" ] || continue + out "Running '$hook'..." + . "$hook" + done +} + +shell() { + err "Dropping to shell, type 'exit' to continue the boot process." + sh -l } |