*: refactor

Documentation will be rewritten and added later.
This commit is contained in:
illiliti
2021-07-31 20:20:16 +03:00
parent 7bfc7fe315
commit a468c11a30
45 changed files with 618 additions and 2161 deletions

15
hook/eudev/eudev Normal file
View File

@ -0,0 +1,15 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
for _bin in udevd udevadm; do
copy_exec "$_bin"
done
mkdir -p "${tmpdir}/lib/udev/rules.d"
cat > "${tmpdir}/lib/udev/rules.d/device.rules" << EOF
SUBSYSTEMS=="block", ACTION=="add", RUN+="/sbin/helper"
ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/sbin/helper"
EOF

10
hook/eudev/eudev.init Normal file
View File

@ -0,0 +1,10 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
udevd -dN never
udevadm trigger -c add -t subsystems
udevadm trigger -c add -t devices
udevadm settle

View File

@ -0,0 +1,4 @@
# vim: set ft=sh:
# shellcheck shell=sh
udevadm control -e

8
hook/keymap/keymap Normal file
View File

@ -0,0 +1,8 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
copy_file "$keymap_path" "$keymap_path" 0644
copy_exec loadkmap

8
hook/keymap/keymap.init Normal file
View File

@ -0,0 +1,8 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
# TODO support loadkeys
loadkmap < "$keymap_path"

36
hook/luks/luks Normal file
View File

@ -0,0 +1,36 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
[ "$luks_key" ] && {
copy_file "${luks_key#*=}" /root/luks_key 0400
sed "s|${luks_key#*=}|/root/luks_key|" \
"${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_"
mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config"
}
[ "$luks_header" ] && {
copy_file "${luks_header#*=}" /root/luks_header 0400
sed "s|${luks_header#*=}|/root/luks_header|" \
"${tmpdir}/etc/tinyramfs/config" > "${tmpdir}/_"
mv "${tmpdir}/_" "${tmpdir}/etc/tinyramfs/config"
}
[ "$hostonly" ] &&
for _mod in \
aes ecb xts lrw wp512 sha256 \
sha512 twofish serpent dm-crypt
do
copy_kmod "$_mod"
done
# https://bugs.archlinux.org/task/56771
[ -e /lib/libgcc_s.so.1 ] && copy_file /lib/libgcc_s.so.1 /lib/libgcc_s.so.1 0755 1
copy_exec cryptsetup

15
hook/luks/luks.init Normal file
View File

@ -0,0 +1,15 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
mkdir -p /run/cryptsetup
resolve_device "$luks_root"
DM_DISABLE_UDEV=1 cryptsetup open \
${luks_discard:+--allow-discards} \
${luks_header:+--header="$luks_header"} \
${luks_key:+--key-file="$luks_key"} -- "$device" \
"${luks_name:-crypt-${device##*/}}" || panic "failed to unlock LUKS"

34
hook/lvm/lvm Normal file
View File

@ -0,0 +1,34 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
[ "$hostonly" ] &&
for _mod in \
dm-log dm-cache dm-mirror \
dm-snapshot dm-multipath dm-thin-pool
do
copy_kmod "$_mod"
done
copy_exec lvm
_config='
devices {
write_cache_state = 0
}
backup {
backup = 0
archive = 0
}
global {
use_lvmetad = 0
}'
mkdir -p "${tmpdir}/etc/lvm"
lvm config \
--config "$_config" \
${lvm_config:+--mergedconfig} \
> "${tmpdir}/etc/lvm/lvm.conf"

30
hook/lvm/lvm.init Normal file
View File

@ -0,0 +1,30 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
mkdir -p /run/lvm /run/lock/lvm
set -- --sysinit -qq -aay ${lvm_discard:+--config=devices\{issue_discards=1\}}
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
set -- lvchange "$@" "${lvm_group}/${lvm_name}"
elif [ "$lvm_group" ]; then
set -- vgchange "$@" "$lvm_group"
elif [ "$lvm_tag" ]; then
set -- lvchange "$@" "@${lvm_tag}"
else
set -- vgchange "$@"
fi
_count=0
# Handle race condition.
while ! DM_DISABLE_UDEV=1 lvm "$@"; do
if [ "$((_count += 1))" = 10 ]; then
panic "failed to trigger LVM"
else
sleep 1
fi
done

14
hook/mdev/mdev Normal file
View File

@ -0,0 +1,14 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
for _bin in mdev find kill; do
copy_exec "$_bin"
done
cat > "${tmpdir}/etc/mdev.conf" << EOF
SUBSYSTEM=block;.* 0:0 660 @/sbin/helper
\$MODALIAS=.* 0:0 660 @/sbin/helper
EOF

24
hook/mdev/mdev.init Normal file
View File

@ -0,0 +1,24 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
mdev -s
mdev -df 2> /dev/null &
# https://shellcheck.net/wiki/SC2034
# shellcheck disable=2034
mdev_pid=$!
find /sys/devices -name uevent |
while read -r uevent; do
printf add > "$uevent"
done 2> /dev/null
find /sys/devices -name uevent |
while read -r uevent; do
printf add > "$uevent"
done 2> /dev/null

7
hook/mdev/mdev.init.late Normal file
View File

@ -0,0 +1,7 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
kill "$mdev_pid"

14
hook/mdevd/mdevd Normal file
View File

@ -0,0 +1,14 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
for _bin in mdevd mdevd-coldplug kill; do
copy_exec "$_bin"
done
cat > "${tmpdir}/etc/mdev.conf" << EOF
SUBSYSTEM=block;.* 0:0 660 @/sbin/helper
\$MODALIAS=.* 0:0 660 @/sbin/helper
EOF

13
hook/mdevd/mdevd.init Normal file
View File

@ -0,0 +1,13 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
mdevd 2> /dev/null &
# https://shellcheck.net/wiki/SC2034
# shellcheck disable=2034
mdevd_pid=$!
mdevd-coldplug

View File

@ -0,0 +1,7 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
kill "$mdevd_pid"

4
hook/proc/proc Normal file
View File

@ -0,0 +1,4 @@
# vim: set ft=sh:
# shellcheck shell=sh
copy_exec find

19
hook/proc/proc.init Normal file
View File

@ -0,0 +1,19 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
printf '/sbin/helper\n' > /proc/sys/kernel/hotplug
find /sys/devices -name uevent |
while read -r uevent; do
printf add > "$uevent"
done 2> /dev/null
find /sys/devices -name uevent |
while read -r uevent; do
printf add > "$uevent"
done 2> /dev/null

4
hook/proc/proc.init.late Normal file
View File

@ -0,0 +1,4 @@
# vim: set ft=sh:
# shellcheck shell=sh
printf '\0' > /proc/sys/kernel/hotplug

View File

@ -0,0 +1,15 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
for _bin in /lib/systemd/systemd-udevd udevadm; do
copy_exec "$_bin"
done
mkdir -p "${tmpdir}/lib/udev/rules.d"
cat > "${tmpdir}/lib/udev/rules.d/device.rules" << EOF
SUBSYSTEMS=="block", ACTION=="add", RUN+="/sbin/helper"
ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/sbin/helper"
EOF

View File

@ -0,0 +1,10 @@
# vim: set ft=sh:
# shellcheck shell=sh
#
# https://shellcheck.net/wiki/SC2154
# shellcheck disable=2154
systemd-udevd -dN never
udevadm trigger -c add -t subsystems
udevadm trigger -c add -t devices
udevadm settle

View File

@ -0,0 +1,4 @@
# vim: set ft=sh:
# shellcheck shell=sh
udevadm control -e