diff --git a/device-helper b/device-helper index 610f1a7..92f05d9 100755 --- a/device-helper +++ b/device-helper @@ -14,23 +14,22 @@ create_symlink() ln -s "../../${dev_name}" "$sym" } -# int main() -{ - [ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 1 +[ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 1 - read -r dm_name < "/sys/block/${dev_name}/dm/name" && { - mkdir -p /dev/mapper - ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}" - } +exec > /dev/null 2>&1 - command -v blkid || exit 0 +read -r dm_name < "/sys/block/${dev_name}/dm/name" && { + mkdir -p /dev/mapper + ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}" +} - # prevent race condition - blkid "/dev/${dev_name}" || sleep 2 +command -v blkid || exit 0 - for line in $(blkid "/dev/${dev_name}"); do case "${line%%=*}" in - UUID) create_symlink /dev/disk/by-uuid "${line##*=}" ;; - LABEL) create_symlink /dev/disk/by-label "${line##*=}" ;; - PARTUUID) create_symlink /dev/disk/by-partuuid "${line##*=}" ;; - esac; done -} > /dev/null 2>&1 +# prevent race condition +blkid "/dev/${dev_name}" || sleep 2 + +for line in $(blkid "/dev/${dev_name}"); do case "${line%%=*}" in + UUID) create_symlink /dev/disk/by-uuid "${line##*=}" ;; + LABEL) create_symlink /dev/disk/by-label "${line##*=}" ;; + PARTUUID) create_symlink /dev/disk/by-partuuid "${line##*=}" ;; +esac; done diff --git a/docs/tinyramfs.cmdline.7 b/docs/tinyramfs.cmdline.7 index f5294ba..d6ba91f 100644 --- a/docs/tinyramfs.cmdline.7 +++ b/docs/tinyramfs.cmdline.7 @@ -5,7 +5,7 @@ .nh .ad l .\" Begin generated content: -.TH "tinyramfs.cmdline" "7" "2020-09-07" +.TH "tinyramfs.cmdline" "7" "2020-09-10" .P .SH NAME .P @@ -37,7 +37,7 @@ Enable debug mode.\& .P .RS 4 Specify breakpoint where shell should be invoked.\& Useful for -debugging.\& List of supported breakpoints: +debugging.\& List of builtin breakpoints: .P .RS 4 .ie n \{\ @@ -46,24 +46,6 @@ debugging.\& List of supported breakpoints: .el \{\ .IP \(bu 4 .\} -keymap -.RE -.RS 4 -.ie n \{\ -\h'-04'\(bu\h'+03'\c -.\} -.el \{\ -.IP \(bu 4 -.\} -devmgr -.RE -.RS 4 -.ie n \{\ -\h'-04'\(bu\h'+03'\c -.\} -.el \{\ -.IP \(bu 4 -.\} root .RE .RS 4 @@ -74,27 +56,12 @@ root .IP \(bu 4 .\} boot -.RE -.RS 4 -.ie n \{\ -\h'-04'\(bu\h'+03'\c -.\} -.el \{\ -.IP \(bu 4 -.\} -luks -.RE -.RS 4 -.ie n \{\ -\h'-04'\(bu\h'+03'\c -.\} -.el \{\ -.IP \(bu 4 -.\} -lvm .RE .P +Hooks can provide their own breakpoints.\& See source code of hooks +for more information.\& +.P .RE \fBroot\fR=UUID|LABEL|/dev/*|PARTUUID .P diff --git a/docs/tinyramfs.cmdline.7.scd b/docs/tinyramfs.cmdline.7.scd index a79d19f..31222a9 100644 --- a/docs/tinyramfs.cmdline.7.scd +++ b/docs/tinyramfs.cmdline.7.scd @@ -25,14 +25,13 @@ kernel parameters without needing to regenerate initramfs image. *break*=breakpoint Specify breakpoint where shell should be invoked. Useful for - debugging. List of supported breakpoints: + debugging. List of builtin breakpoints: - - keymap - - devmgr - root - boot - - luks - - lvm + + Hooks can provide their own breakpoints. See source code of hooks + for more information. *root*=UUID|LABEL|/dev/\*|PARTUUID diff --git a/hooks/eudev/eudev b/hooks/eudev/eudev index b9aa560..1700900 100644 --- a/hooks/eudev/eudev +++ b/hooks/eudev/eudev @@ -3,18 +3,17 @@ # # false positive # shellcheck disable=2154 -{ - for _binary in udevd udevadm; do - copy_binary "$_binary" - done - mkdir -p "${tmpdir}/lib/udev/rules.d" +for _binary in udevd udevadm; do + copy_binary "$_binary" +done - printf "%s\n" \ - 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ - > "${tmpdir}/lib/udev/rules.d/device-helper.rules" +mkdir -p "${tmpdir}/lib/udev/rules.d" - [ "$monolith" = 1 ] || printf "%s\n" \ - 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ - >> "${tmpdir}/lib/udev/rules.d/device-helper.rules" -} +printf "%s\n" \ + 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ +> "${tmpdir}/lib/udev/rules.d/device-helper.rules" + +[ "$monolith" = 1 ] || printf "%s\n" \ + 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ +>> "${tmpdir}/lib/udev/rules.d/device-helper.rules" diff --git a/hooks/eudev/eudev.init b/hooks/eudev/eudev.init index 5d6c5ac..e204e43 100644 --- a/hooks/eudev/eudev.init +++ b/hooks/eudev/eudev.init @@ -3,11 +3,10 @@ # # false positive # shellcheck disable=2154,2034 -{ - [ "$break" = devmgr ] && { print "break before run_eudev()"; sh; } - udevd -dN never - udevadm trigger -c add -t subsystems - udevadm trigger -c add -t devices - udevadm settle -} +[ "$break" = eudev ] && { print "break before eudev.init"; sh; } + +udevd -dN never +udevadm trigger -c add -t subsystems +udevadm trigger -c add -t devices +udevadm settle diff --git a/hooks/eudev/eudev.init.late b/hooks/eudev/eudev.init.late index 0188e3d..e25dd43 100644 --- a/hooks/eudev/eudev.init.late +++ b/hooks/eudev/eudev.init.late @@ -3,6 +3,5 @@ # # false positive # shellcheck disable=2154 -{ - udevadm control -e -} + +udevadm control -e diff --git a/hooks/keymap/keymap b/hooks/keymap/keymap index 2a44f5d..ef40ce3 100644 --- a/hooks/keymap/keymap +++ b/hooks/keymap/keymap @@ -3,7 +3,6 @@ # # false positive # shellcheck disable=2154 -{ - copy_file "$keymap_path" "$keymap_path" 644 0 - copy_binary loadkmap -} + +copy_file "$keymap_path" "$keymap_path" 644 0 +copy_binary loadkmap diff --git a/hooks/keymap/keymap.init b/hooks/keymap/keymap.init index 4627b85..88e789d 100644 --- a/hooks/keymap/keymap.init +++ b/hooks/keymap/keymap.init @@ -3,8 +3,7 @@ # # false positive # shellcheck disable=2154 -{ - [ "$break" = keymap ] && { print "break before run_keymap()"; sh; } - loadkmap < "$keymap_path" -} +[ "$break" = keymap ] && { print "break before keymap.init"; sh; } + +loadkmap < "$keymap_path" diff --git a/hooks/luks/luks b/hooks/luks/luks index f2dd916..8f46a1d 100644 --- a/hooks/luks/luks +++ b/hooks/luks/luks @@ -3,36 +3,35 @@ # # false positive # shellcheck disable=2154 -{ - [ "$hostonly" = 1 ] && - for _module in \ - aes ecb xts lrw wp512 sha256 \ - sha512 twofish serpent dm-crypt - do - copy_module "$_module" - done - copy_binary cryptsetup +[ "$luks_key" ] && { + copy_file "${luks_key#*=}" /root/key 400 0 - # avoid possible issues with libgcc_s.so.1 - # see https://bugs.archlinux.org/task/56771 - [ -e /lib/libgcc_s.so.1 ] && copy_file /lib/libgcc_s.so.1 /lib/libgcc_s.so.1 755 1 + sed "s|${luks_key#*=}|/root/key|" \ + "${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_" - if [ "$luks_key" ]; then - copy_file "${luks_key#*=}" /root/key 400 0 - - sed "s|${luks_key#*=}|/root/key|" \ - "${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_" - - mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config" - fi - - if [ "$luks_header" ]; then - copy_file "${luks_header#*=}" /root/header 400 0 - - sed "s|${luks_header#*=}|/root/header|" \ - "${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_" - - mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config" - fi + mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config" } + +[ "$luks_header" ] && { + copy_file "${luks_header#*=}" /root/header 400 0 + + sed "s|${luks_header#*=}|/root/header|" \ + "${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_" + + mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config" +} + +[ "$hostonly" = 1 ] && + for _module in \ + aes ecb xts lrw wp512 sha256 \ + sha512 twofish serpent dm-crypt + do + copy_module "$_module" + done + +copy_binary cryptsetup + +# avoid possible issues with libgcc_s.so.1 +# see https://bugs.archlinux.org/task/56771 +[ -e /lib/libgcc_s.so.1 ] && copy_file /lib/libgcc_s.so.1 /lib/libgcc_s.so.1 755 1 diff --git a/hooks/luks/luks.init b/hooks/luks/luks.init index 24ce6f4..5e00c88 100644 --- a/hooks/luks/luks.init +++ b/hooks/luks/luks.init @@ -6,17 +6,16 @@ # # word splitting is safe by design # shellcheck disable=2068 -{ - [ "$break" = luks ] && { print "break before unlock_luks()"; sh; } - export DM_DISABLE_UDEV=1 - mkdir -p /run/cryptsetup +[ "$break" = luks ] && { print "break before luks.init"; sh; } - resolve_device "$luks_root" +export DM_DISABLE_UDEV=1 +mkdir -p /run/cryptsetup - set -- \ - "${luks_discard:+--allow-discards}" "${luks_header:+--header $luks_header}" \ - "${luks_key:+-d $luks_key}" "$device" "${luks_name:-crypt-${device##*/}}" +resolve_device "$luks_root" - cryptsetup open $@ || panic "failed to unlock LUKS" -} +set -- \ + "${luks_discard:+--allow-discards}" "${luks_header:+--header $luks_header}" \ + "${luks_key:+-d $luks_key}" "$device" "${luks_name:-crypt-${device##*/}}" + +cryptsetup open $@ || panic "failed to unlock LUKS" diff --git a/hooks/lvm/lvm b/hooks/lvm/lvm index da0746b..bdb154e 100644 --- a/hooks/lvm/lvm +++ b/hooks/lvm/lvm @@ -3,33 +3,32 @@ # # false positive # shellcheck disable=2154 -{ - [ "$hostonly" = 1 ] && - for _module in \ - dm-log dm-cache dm-mirror \ - dm-snapshot dm-multipath dm-thin-pool - do - copy_module "$_module" - done - copy_binary lvm +[ "$hostonly" = 1 ] && + for _module in \ + dm-log dm-cache dm-mirror \ + dm-snapshot dm-multipath dm-thin-pool + do + copy_module "$_module" + done - lvm_config=" - devices { - write_cache_state = 0 - } - backup { - backup = 0 - archive = 0 - } - global { - use_lvmetad = 0 - }" +copy_binary lvm - mkdir -p "${tmpdir}/etc/lvm" +lvm_config=" + devices { + write_cache_state = 0 + } + backup { + backup = 0 + archive = 0 + } + global { + use_lvmetad = 0 + }" - lvm config \ - --config "$lvm_config" \ - ${lvm_config:+--mergedconfig} \ - > "${tmpdir}/etc/lvm/lvm.conf" -} +mkdir -p "${tmpdir}/etc/lvm" + +lvm config \ + --config "$lvm_config" \ + ${lvm_config:+--mergedconfig} \ +> "${tmpdir}/etc/lvm/lvm.conf" diff --git a/hooks/lvm/lvm.init b/hooks/lvm/lvm.init index 682e5bc..955469b 100644 --- a/hooks/lvm/lvm.init +++ b/hooks/lvm/lvm.init @@ -6,22 +6,21 @@ # # word splitting is safe by design # shellcheck disable=2068 -{ - [ "$break" = lvm ] && { print "break before trigger_lvm()"; sh; } - export DM_DISABLE_UDEV=1 - mkdir -p /run/lvm /run/lock/lvm +[ "$break" = lvm ] && { print "break before lvm.init"; sh; } - set -- \ - --sysinit -qq -aay "${lvm_discard:+--config=devices{issue_discards=1}}" +export DM_DISABLE_UDEV=1 +mkdir -p /run/lvm /run/lock/lvm - if [ "$lvm_group" ] && [ "$lvm_name" ]; then - lvm lvchange $@ "${lvm_group}/${lvm_name}" - elif [ "$lvm_group" ]; then - lvm vgchange $@ "$lvm_group" - elif [ "$lvm_tag" ]; then - lvm lvchange $@ "@${lvm_tag}" - else - lvm vgchange $@ - fi || panic "failed to trigger LVM" -} +set -- \ + --sysinit -qq -aay "${lvm_discard:+--config=devices{issue_discards=1}}" + +if [ "$lvm_group" ] && [ "$lvm_name" ]; then + lvm lvchange $@ "${lvm_group}/${lvm_name}" +elif [ "$lvm_group" ]; then + lvm vgchange $@ "$lvm_group" +elif [ "$lvm_tag" ]; then + lvm lvchange $@ "@${lvm_tag}" +else + lvm vgchange $@ +fi || panic "failed to trigger LVM" diff --git a/hooks/mdev/mdev b/hooks/mdev/mdev index fc853a1..97c25aa 100644 --- a/hooks/mdev/mdev +++ b/hooks/mdev/mdev @@ -3,16 +3,15 @@ # # false positive # shellcheck disable=2154,2016 -{ - for _binary in mdev find; do - copy_binary "$_binary" - done - printf "%s\n" \ - 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ - > "${tmpdir}/etc/mdev.conf" +for _binary in mdev find; do + copy_binary "$_binary" +done - [ "$monolith" = 1 ] || printf "%s\n" \ - '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ - >> "${tmpdir}/etc/mdev.conf" -} +printf "%s\n" \ + 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ +> "${tmpdir}/etc/mdev.conf" + +[ "$monolith" = 1 ] || printf "%s\n" \ + '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ +>> "${tmpdir}/etc/mdev.conf" diff --git a/hooks/mdev/mdev.init b/hooks/mdev/mdev.init index 1d6de64..9398096 100644 --- a/hooks/mdev/mdev.init +++ b/hooks/mdev/mdev.init @@ -3,15 +3,14 @@ # # false positive # shellcheck disable=2154,2034 -{ - [ "$break" = devmgr ] && { print "break before run_mdev()"; sh; } - - mdev -s - mdev -df 2> /dev/null & mdev_pid="$!" - find /sys/devices -name uevent | +[ "$break" = mdev ] && { print "break before mdev.init"; sh; } - while read -r uevent; do - printf add > "$uevent" - done 2> /dev/null -} +mdev -s +mdev -df 2> /dev/null & mdev_pid="$!" + +find /sys/devices -name uevent | + +while read -r uevent; do + printf add > "$uevent" +done 2> /dev/null diff --git a/hooks/mdev/mdev.init.late b/hooks/mdev/mdev.init.late index 6532d0d..975bdbe 100644 --- a/hooks/mdev/mdev.init.late +++ b/hooks/mdev/mdev.init.late @@ -3,6 +3,5 @@ # # false positive # shellcheck disable=2154 -{ - kill "$mdev_pid" -} + +kill "$mdev_pid" diff --git a/hooks/mdevd/mdevd b/hooks/mdevd/mdevd index 6e2afd3..a591024 100644 --- a/hooks/mdevd/mdevd +++ b/hooks/mdevd/mdevd @@ -3,16 +3,15 @@ # # false positive # shellcheck disable=2154,2016 -{ - for _binary in mdevd mdevd-coldplug; do - copy_binary "$_binary" - done - printf "%s\n" \ - 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ - > "${tmpdir}/etc/mdev.conf" +for _binary in mdevd mdevd-coldplug; do + copy_binary "$_binary" +done - [ "$monolith" = 1 ] || printf "%s\n" \ - '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ - >> "${tmpdir}/etc/mdev.conf" -} +printf "%s\n" \ + 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ +> "${tmpdir}/etc/mdev.conf" + +[ "$monolith" = 1 ] || printf "%s\n" \ + '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ +>> "${tmpdir}/etc/mdev.conf" diff --git a/hooks/mdevd/mdevd.init b/hooks/mdevd/mdevd.init index 9f8c02d..495a0f7 100644 --- a/hooks/mdevd/mdevd.init +++ b/hooks/mdevd/mdevd.init @@ -3,9 +3,8 @@ # # false positive # shellcheck disable=2154,2034 -{ - [ "$break" = devmgr ] && { print "break before run_mdevd()"; sh; } - - mdevd 2> /dev/null & mdevd_pid="$!" - mdevd-coldplug -} + +[ "$break" = mdevd ] && { print "break before mdevd.init"; sh; } + +mdevd 2> /dev/null & mdevd_pid="$!" +mdevd-coldplug diff --git a/hooks/mdevd/mdevd.init.late b/hooks/mdevd/mdevd.init.late index f85ed53..03894b3 100644 --- a/hooks/mdevd/mdevd.init.late +++ b/hooks/mdevd/mdevd.init.late @@ -3,6 +3,5 @@ # # false positive # shellcheck disable=2154 -{ - kill "$mdevd_pid" -} + +kill "$mdevd_pid" diff --git a/hooks/proc/proc b/hooks/proc/proc index a6f523a..5295d6f 100644 --- a/hooks/proc/proc +++ b/hooks/proc/proc @@ -1,5 +1,4 @@ # vim: set ft=sh: # shellcheck shell=sh -{ - copy_binary find -} + +copy_binary find diff --git a/hooks/proc/proc.init b/hooks/proc/proc.init index 7e837cf..f5fdf15 100644 --- a/hooks/proc/proc.init +++ b/hooks/proc/proc.init @@ -3,15 +3,14 @@ # # false positive # shellcheck disable=2154 -{ - [ "$break" = devmgr ] && { print "break before run_proc()"; sh; } - - command -v device-helper > /proc/sys/kernel/hotplug - # get ready for fork bomb. kek - find /sys/devices -name uevent | +[ "$break" = proc ] && { print "break before proc.init"; sh; } - while read -r uevent; do - printf add > "$uevent" - done 2> /dev/null -} +command -v device-helper > /proc/sys/kernel/hotplug + +# get ready for fork bomb. kek +find /sys/devices -name uevent | + +while read -r uevent; do + printf add > "$uevent" +done 2> /dev/null diff --git a/hooks/proc/proc.init.late b/hooks/proc/proc.init.late index 36edb56..be02e0c 100644 --- a/hooks/proc/proc.init.late +++ b/hooks/proc/proc.init.late @@ -1,5 +1,4 @@ # vim: set ft=sh: # shellcheck shell=sh -{ - printf '\n' > /proc/sys/kernel/hotplug -} + +printf '\n' > /proc/sys/kernel/hotplug diff --git a/hooks/systemd-udevd/systemd-udevd b/hooks/systemd-udevd/systemd-udevd index 1d8aa28..ef62f02 100644 --- a/hooks/systemd-udevd/systemd-udevd +++ b/hooks/systemd-udevd/systemd-udevd @@ -3,18 +3,17 @@ # # false positive # shellcheck disable=2154 -{ - for _binary in /lib/systemd/systemd-udevd udevadm; do - copy_binary "$_binary" - done - mkdir -p "${tmpdir}/lib/udev/rules.d" +for _binary in /lib/systemd/systemd-udevd udevadm; do + copy_binary "$_binary" +done - printf "%s\n" \ - 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ - > "${tmpdir}/lib/udev/rules.d/device-helper.rules" +mkdir -p "${tmpdir}/lib/udev/rules.d" - [ "$monolith" = 1 ] || printf "%s\n" \ - 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ - >> "${tmpdir}/lib/udev/rules.d/device-helper.rules" -} +printf "%s\n" \ + 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ +> "${tmpdir}/lib/udev/rules.d/device-helper.rules" + +[ "$monolith" = 1 ] || printf "%s\n" \ + 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ +>> "${tmpdir}/lib/udev/rules.d/device-helper.rules" diff --git a/hooks/systemd-udevd/systemd-udevd.init b/hooks/systemd-udevd/systemd-udevd.init index 1caa4d7..ec483b6 100644 --- a/hooks/systemd-udevd/systemd-udevd.init +++ b/hooks/systemd-udevd/systemd-udevd.init @@ -3,11 +3,10 @@ # # false positive # shellcheck disable=2154,2034 -{ - [ "$break" = devmgr ] && { print "break before run_systemd_udevd()"; sh; } - /lib/systemd/systemd-udevd -dN never - udevadm trigger -c add -t subsystems - udevadm trigger -c add -t devices - udevadm settle -} +[ "$break" = systemd-udevd ] && { print "break before systemd-udevd.init"; sh; } + +/lib/systemd/systemd-udevd -dN never +udevadm trigger -c add -t subsystems +udevadm trigger -c add -t devices +udevadm settle diff --git a/hooks/systemd-udevd/systemd-udevd.init.late b/hooks/systemd-udevd/systemd-udevd.init.late index 0188e3d..e25dd43 100644 --- a/hooks/systemd-udevd/systemd-udevd.init.late +++ b/hooks/systemd-udevd/systemd-udevd.init.late @@ -3,6 +3,5 @@ # # false positive # shellcheck disable=2154 -{ - udevadm control -e -} + +udevadm control -e diff --git a/init b/init index c5c9866..a066bbe 100755 --- a/init +++ b/init @@ -29,8 +29,6 @@ resolve_device() esac # prevent race condition - # XXX what the hell happens here? - # why this loop sometimes trigger panic if i remove '|| :' while [ ! -b "$device" ]; do sleep 1 [ "$((count += 1))" = "${rootdelay:=30}" ] && { panic "failed to lookup partition" @@ -41,14 +39,14 @@ resolve_device() run_hook() { - type="$1"; hksdir=/usr/share/tinyramfs/hooks + type="$1" # run hooks if any # false positive # shellcheck disable=1090 for hook in $hooks; do - [ -f "${hksdir}/${hook}/${hook}.${type}" ] || continue - . "${hksdir}/${hook}/${hook}.${type}" + [ -f "/usr/share/tinyramfs/hooks/${hook}/${hook}.${type}" ] || continue + . "/usr/share/tinyramfs/hooks/${hook}/${hook}.${type}" done } @@ -121,16 +119,13 @@ boot_system() switch_root $@ || panic "failed to boot system" } -# int main() -{ - # enable exit on error and disable globbing - # trap EXIT signal - set -ef; trap panic EXIT +# enable exit on error and disable globbing +# trap EXIT signal +set -ef; trap panic EXIT - prepare_environment - parse_cmdline - run_hook init - mount_root - run_hook init.late - boot_system -} +prepare_environment +parse_cmdline +run_hook init +mount_root +run_hook init.late +boot_system diff --git a/tinyramfs b/tinyramfs index c104f5f..b84acc8 100755 --- a/tinyramfs +++ b/tinyramfs @@ -134,11 +134,7 @@ prepare_initramfs() copy_binary "$_binary" done - if command -v blkid > /dev/null; then - copy_binary blkid - else - print "blkid not found. you will unable to use UUID, LABEL, PARTUUID" - fi + command -v blkid > /dev/null && copy_binary blkid copy_file "${srcdir}/init" /init 755 0 copy_file "$config" /etc/tinyramfs/config 644 0 @@ -237,7 +233,7 @@ copy_hook() { hook="$1" - for _dir in "$hksdir" /etc/tinyramfs/hooks "${srcdir}/hooks"; do + for _dir in "$hksdir" /etc/tinyramfs/hooks /usr/share/tinyramfs/hooks; do [ -f "${_dir}/${hook}/${hook}" ] || ! continue done || panic "could not find $hook hook" @@ -247,13 +243,13 @@ copy_hook() # shellcheck disable=1090 . "${_dir}/${hook}/${hook}" - for _file in init init.late; do - [ -f "${_dir}/${hook}/${hook}.${_file}" ] || continue + for _type in init init.late; do + [ -f "${_dir}/${hook}/${hook}.${_type}" ] || continue - print "copying ${hook}.${_file}" + print "copying ${hook}.${_type}" - copy_file "${_dir}/${hook}/${hook}.${_file}" \ - "/usr/share/tinyramfs/hooks/${hook}/${hook}.${_file}" 644 0 + copy_file "${_dir}/${hook}/${hook}.${_type}" \ + "/usr/share/tinyramfs/hooks/${hook}/${hook}.${_type}" 644 0 done } @@ -262,7 +258,6 @@ copy_modules() # skip this function if kernel # compiled with builtin modules if [ "$monolith" = 1 ]; then - print "skipping modules" return 0 elif [ "$hostonly" = 1 ]; then @@ -351,21 +346,18 @@ make_initramfs() print "done! check out $output" ) -# int main() -{ - [ "$(id -u)" = 0 ] || panic "must be run as root" +[ "$(id -u)" = 0 ] || panic "must be run as root" - # enable exit on error and disable globbing - set -ef +# enable exit on error and disable globbing +set -ef - prepare_environment "$@" - prepare_initramfs +prepare_environment "$@" +prepare_initramfs - # copy and run hooks if any - for _hook in $hooks; do - copy_hook "$_hook" - done +# copy and run hooks if any +for _hook in $hooks; do + copy_hook "$_hook" +done - copy_modules - make_initramfs -} +copy_modules +make_initramfs