PKGBUILDs/core/systemd/initcpio-install-systemd

152 lines
4.7 KiB
Plaintext
Raw Normal View History

2014-07-16 02:33:04 +00:00
#!/bin/bash
add_systemd_unit() {
# Add a systemd unit file to the initcpio image. Hard dependencies on binaries
# and other unit files will be discovered and added.
# $1: path to rules file (or name of rules file)
local unit= rule= entry= key= value= binary= dep=
unit=$(PATH=/usr/lib/systemd/system:/lib/systemd/system type -P "$1")
if [[ -z $unit ]]; then
# complain about not found unit file
return 1
fi
add_file "$unit"
while IFS='=' read -r key values; do
read -ra values <<< "$values"
case $key in
Requires|OnFailure)
# only add hard dependencies (not Wants)
map add_systemd_unit "${values[@]}"
;;
Exec*)
2020-07-28 20:23:56 +00:00
# do not add binaries unless they are required,
# strip special executable prefixes
case ${values[0]} in
-*) ;;
!!*) add_binary "${values[0]#!!}" ;;
*) add_binary "${values[0]#[@!:+]}" ;;
esac
2014-07-16 02:33:04 +00:00
;;
esac
done <"$unit"
# preserve reverse soft dependency
for dep in {/usr,}/lib/systemd/system/*.wants/${unit##*/}; do
if [[ -L $dep ]]; then
add_symlink "$dep"
fi
done
# add hard dependencies
if [[ -d $unit.requires ]]; then
for dep in "$unit".requires/*; do
add_systemd_unit ${dep##*/}
done
fi
}
2016-07-20 13:31:52 +00:00
add_systemd_drop_in() {
local unit=$1 dropin_name=$2
mkdir -p "$BUILDROOT/etc/systemd/system/$unit.d"
cat >"$BUILDROOT/etc/systemd/system/$unit.d/$2.conf"
}
2014-07-16 02:33:04 +00:00
build() {
local rules unit
add_binary /usr/bin/kmod /usr/bin/modprobe
2020-12-02 19:41:16 +00:00
add_binary /usr/bin/mount
2016-06-25 18:50:12 +00:00
add_binary /usr/bin/sulogin
2020-12-02 19:41:16 +00:00
add_binary /usr/bin/umount
add_binary /usr/lib/systemd/systemd /init
2014-11-12 02:53:00 +00:00
map add_binary \
2020-06-03 02:01:51 +00:00
/usr/bin/journalctl \
2015-06-27 21:19:51 +00:00
/usr/bin/systemd-tmpfiles \
2014-11-12 02:53:00 +00:00
/usr/lib/systemd/systemd-hibernate-resume \
2018-07-05 19:40:41 +00:00
/usr/lib/systemd/systemd-shutdown \
2017-08-08 23:58:20 +00:00
/usr/lib/systemd/systemd-sulogin-shell \
2014-11-12 02:53:00 +00:00
/usr/lib/systemd/system-generators/systemd-fstab-generator \
2015-06-27 21:19:51 +00:00
/usr/lib/systemd/system-generators/systemd-gpt-auto-generator \
/usr/lib/systemd/system-generators/systemd-hibernate-resume-generator
2014-07-16 02:33:04 +00:00
# udev rules and systemd units
map add_udev_rule "$rules" \
50-udev-default.rules \
60-persistent-storage.rules \
64-btrfs.rules \
80-drivers.rules \
2014-11-12 02:53:00 +00:00
99-systemd.rules
2014-07-16 02:33:04 +00:00
map add_systemd_unit \
initrd-cleanup.service \
initrd-fs.target \
initrd-parse-etc.service \
initrd-root-fs.target \
2016-06-03 23:51:30 +00:00
initrd-root-device.target \
2014-07-16 02:33:04 +00:00
initrd-switch-root.service \
initrd-switch-root.target \
initrd-udevadm-cleanup-db.service \
initrd.target \
kmod-static-nodes.service \
2014-11-12 02:53:00 +00:00
local-fs.target \
local-fs-pre.target \
paths.target \
2015-04-19 14:43:25 +00:00
reboot.target \
2014-11-12 02:53:00 +00:00
slices.target \
2014-07-16 02:33:04 +00:00
sockets.target \
2014-11-12 02:53:00 +00:00
swap.target \
2014-07-16 02:33:04 +00:00
systemd-fsck@.service \
2014-11-12 02:53:00 +00:00
systemd-hibernate-resume@.service \
2014-07-16 02:33:04 +00:00
systemd-journald.service \
2014-12-18 19:03:46 +00:00
systemd-journald-audit.socket \
2014-11-12 02:53:00 +00:00
systemd-journald-dev-log.socket \
2016-10-04 12:29:10 +00:00
systemd-modules-load.service \
2014-07-16 02:33:04 +00:00
systemd-tmpfiles-setup-dev.service \
systemd-udev-trigger.service \
systemd-udevd-control.socket \
systemd-udevd-kernel.socket \
2014-11-12 02:53:00 +00:00
systemd-udevd.service \
2016-06-25 18:50:12 +00:00
timers.target \
rescue.target \
emergency.target
2014-07-16 02:33:04 +00:00
add_symlink "/usr/lib/systemd/system/default.target" "initrd.target"
2014-11-12 02:53:00 +00:00
add_symlink "/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
2014-07-16 02:33:04 +00:00
2017-07-02 21:41:10 +00:00
printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
'passwd: files' \
'group: files' \
'shadow: files'
2016-06-25 18:50:12 +00:00
2020-06-24 12:30:42 +00:00
echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
2020-06-11 19:27:02 +00:00
echo 'root:*:::::::' >"$BUILDROOT/etc/shadow"
2021-04-04 23:15:23 +00:00
getent group root audio disk input kmem kvm lp optical render sgx storage tty uucp video | awk -F: ' { print $1 ":x:" $3 ":" }' >"$BUILDROOT/etc/group"
2016-10-04 12:29:10 +00:00
add_dir "/etc/modules-load.d"
(
. "$_f_config"
set -f
2017-10-17 12:02:40 +00:00
printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
2016-10-04 12:29:10 +00:00
)
2014-07-16 02:33:04 +00:00
}
help() {
cat <<HELPEOF
This will install a basic systemd setup in your initramfs, and is meant to
2016-11-30 13:49:51 +00:00
replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
2014-07-16 02:33:04 +00:00
components will need to be ported, and will not work as intended. You also may
wish to still include the 'base' hook (before this hook) to ensure that a
rescue shell exists on your initramfs.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et: