diff options
author | Cem Keylan <cem@ckyln.com> | 2020-01-13 11:37:16 +0300 |
---|---|---|
committer | Cem Keylan <cem@ckyln.com> | 2020-01-13 11:37:16 +0300 |
commit | 38a2e3f0ce51f335c63bf77646a827e216fc3025 (patch) | |
tree | 98dfc86e67ecbcf0afe992ebdc45246d93b7fc83 /rc.boot | |
parent | f4ecd3b5368a6588d797a59b0c6d49f79d9c70de (diff) | |
download | init-38a2e3f0ce51f335c63bf77646a827e216fc3025.tar.gz |
allow user hooks and make it more portable0.4.0
Diffstat (limited to 'rc.boot')
-rwxr-xr-x | rc.boot | 271 |
1 files changed, 131 insertions, 140 deletions
@@ -1,178 +1,169 @@ #!/bin/sh . /etc/init/rc.conf +. INITDIR/rc.lib -welcome() { printf '\033[1;36m->\033[m\033[1m Welcome to\033[35m Carbs Linux\033[m\033[1m!\n' ;} -mnt() { - mountpoint -q "$1" || { - dir=$1 - shift - mount "$@" "$dir" - } -} -emergency_shell() { - error \ - "Cannot continue init due to errors above, starting emergency shell" \ - "When ready, type 'exit' to continue the boot." +PATH=/usr/bin:/usr/sbin +old_ifs=$IFS +set -f - /bin/sh -l -} +welcome -main() { - PATH=/usr/bin:/usr/sbin - old_ifs=$IFS - set -f - - welcome - - log "Mounting pseudo filesystems..."; { - mnt /proc -o nosuid,noexec,nodev -t proc proc - mnt /sys -o nosuid,noexec,nodev -t sysfs sys - mnt /run -o mode=0755,nosuid,nodev -t tmpfs run - mnt /dev -o mode=0755,nosuid -t devtmpfs dev - - mkdir -pm 0755 /run/runit \ - /run/lvm \ - /run/user \ - /run/lock \ - /run/log \ - /dev/pts \ - /dev/shm - - mnt /dev/pts -o mode=0620,gid=5,nosuid,noexec -nt devpts devpts - mnt /dev/shm -o mode=1777,nosuid,nodev -nt tmpfs shm - } +out "Mounting pseudo filesystems..."; { + mnt /proc -o nosuid,noexec,nodev -t proc proc + mnt /sys -o nosuid,noexec,nodev -t sysfs sys + mnt /run -o mode=0755,nosuid,nodev -t tmpfs run + mnt /dev -o mode=0755,nosuid -t devtmpfs dev - log "Setting dmesg level..."; { - [ -n "$dmesg_level" ] && dmesg -n$dmesg_level - } + mkdir -pm 0755 /run/runit \ + /run/lvm \ + /run/user \ + /run/lock \ + /run/log \ + /dev/pts \ + /dev/shm - log "Starting eudev..."; { - command -v udevd >/dev/null && { - udevd --daemon - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices - udevadm settle - } - } + mnt /dev/pts -o mode=0620,gid=5,nosuid,noexec -nt devpts devpts + mnt /dev/shm -o mode=1777,nosuid,nodev -nt tmpfs shm +} + +out "Setting dmesg level..."; { + [ -n "$dmesg_level" ] && dmesg -n$dmesg_level +} - log "Remounting rootfs as ro..."; { - mount -o remount,ro / || emergency_shell +out "Starting eudev..."; { + command -v udevd >/dev/null && { + udevd --daemon + udevadm trigger --action=add --type=subsystems + udevadm trigger --action=add --type=devices + udevadm settle } +} - log "Activating encrypted devices (if any exist)..."; { - [ -e /etc/crypttab ] && [ -x /bin/cryptsetup ] && { - exec 3<&0 +out "Remounting rootfs as ro..."; { + mount -o remount,ro / || emergency_shell +} - while read -r name dev pass opts err; do - [ "${name##\#*}" ] || continue +out "Activating encrypted devices (if any exist)..."; { + [ -e /etc/crypttab ] && [ -x /bin/cryptsetup ] && { + exec 3<&0 - # Break on invalid crypttab. - [ "$err" ] && { - printf 'error: A valid crypttab has only 4 columns.\n' - break - } + while read -r name dev pass opts err; do + [ "${name##\#*}" ] || continue - # Turn 'UUID=*' lines into device names. - [ "${dev##UUID*}" ] || dev=$(blkid -l -o device -t "$dev") + # Break on invalid crypttab. + [ "$err" ] && { + printf 'error: A valid crypttab has only 4 columns.\n' + break + } - # Parse options by turning list into a pseudo array. - IFS=, - set -- $opts - IFS=$old_ifs + # Turn 'UUID=*' lines into device names. + [ "${dev##UUID*}" ] || dev=$(blkid -l -o device -t "$dev") - copts="cryptsetup luksOpen" + # Parse options by turning list into a pseudo array. + IFS=, + set -- $opts + IFS=$old_ifs - # Create an argument list (no other way to do this in sh). - for opt; do case $opt in - discard) copts="$copts --allow-discards" ;; - readonly|read-only) copts="$copts -r" ;; - tries=*) copts="$copts -T ${opt##*=}" ;; - esac; done + copts="cryptsetup luksOpen" - # If password is 'none', '-' or empty ask for it. - case $pass in - none|-|"") $copts "$dev" "$name" <&3 ;; - *) $copts -d "$pass" "$dev" "$name" ;; - esac - done < /etc/crypttab + # Create an argument list (no other way to do this in sh). + for opt; do case $opt in + discard) copts="$copts --allow-discards" ;; + readonly|read-only) copts="$copts -r" ;; + tries=*) copts="$copts -T ${opt##*=}" ;; + esac; done - exec 3>&- + # If password is 'none', '-' or empty ask for it. + case $pass in + none|-|"") $copts "$dev" "$name" <&3 ;; + *) $copts -d "$pass" "$dev" "$name" ;; + esac + done < /etc/crypttab - [ "$copts" ] && [ -x /bin/vgchance ] && { - log "Activating LVM devices for dm-crypt..." - vgchange --sysinit -a y || emergency_shell - } + exec 3>&- + + [ "$copts" ] && [ -x /bin/vgchance ] && { + out "Activating LVM devices for dm-crypt..." + vgchange --sysinit -a y || emergency_shell } } +} - log "Checking filesystems..."; { - fsck -ATat noopts=_netdev - [ $? -gt 1 ] && emergency_shell - } +out "Checking filesystems..."; { + fsck -ATat noopts=_netdev + [ $? -gt 1 ] && emergency_shell +} - log "Mounting rootfs rw..."; { - mount -o remount,rw / || emergency_shell - } +out "Mounting rootfs rw..."; { + mount -o remount,rw / || emergency_shell +} - log "Mounting all local filesystems..."; { - mount -at nosysfs,nonfs,nonfs4,nosmbfs,nocifs -O no_netdev || - emergency_shell - } +out "Mounting all local filesystems..."; { + mount -at nosysfs,nonfs,nonfs4,nosmbfs,nocifs -O no_netdev || + emergency_shell +} - log "Enabling swap..."; { - swapon -a || emergency_shell - } +out "Enabling swap..."; { + swapon -a || emergency_shell +} - log "Seeding random..."; { - if [ -f /var/random.seed ]; then - cat /var/random.seed > /dev/urandom - else - log "This may hang." - log "Mash the keyboard to generate entropy..." +out "Seeding random..."; { + if [ -f /var/random.seed ]; then + cat /var/random.seed > /dev/urandom + else + out "This may hang." + out "Mash the keyboard to generate entropy..." - dd count=1 bs=512 if=/dev/random of=/var/random.seed - fi - } + dd count=1 bs=512 if=/dev/random of=/var/random.seed + fi +} - log "Setting up loopback..."; { - ip link set up dev lo - } +out "Setting up loopback..."; { + ip link set up dev lo +} - log "Setting hostname..."; { - read -r hostname < /etc/hostname - printf '%s\n' "${hostname:-carbs-linux}" > /proc/sys/kernel/hostname - } 2>/dev/null +out "Setting hostname..."; { + read -r hostname < /etc/hostname + printf '%s\n' "${hostname:-carbs-linux}" > /proc/sys/kernel/hostname +} 2>/dev/null - log "Getting keymap settings..."; { - [ -n "$keymap" ] && loadkmap < "$keymap" - } +out "Getting keymap settings..."; { + [ -n "$keymap" ] && loadkmap < "$keymap" +} - log "Loading sysctl settings..."; { - find /run/sysctl.d \ - /etc/sysctl.d \ - /usr/local/lib/sysctl.d \ - /usr/lib/sysctl.d \ - /lib/sysctl.d \ - /etc/sysctl.conf \ - -name \*.conf -type f 2>/dev/null \ - | while read -r conf; do - seen="$seen ${conf##*/}" - - case $seen in - *" ${conf##*/} "*) ;; - *) printf '%s\n' "* Applying $conf ..." - sysctl -p "$conf" ;; - esac - done - } - command -v udevd >/dev/null && - udevadm control --exit +out "Loading sysctl settings..."; { + find /run/sysctl.d \ + /etc/sysctl.d \ + /usr/local/lib/sysctl.d \ + /usr/lib/sysctl.d \ + /lib/sysctl.d \ + /etc/sysctl.conf \ + -name \*.conf -type f 2>/dev/null \ + | while read -r conf; do + seen="$seen ${conf##*/}" + + case $seen in + *" ${conf##*/} "*) ;; + *) printf '%s\n' "* Applying $conf ..." + sysctl -p "$conf" ;; + esac + done +} + +out "Running boot hooks..."; { + run_hooks /etc/init/*.boot +} - log "Boot stage complete..." +out "Running rc.local..."; { + [ -r "/etc/init/rc.local" ] && \ + . /etc/init/rc.local } -main +command -v udevd >/dev/null && + udevadm control --exit + +out "Boot stage complete..." |