archrelease: copy trunk to extra-x86_64
[arch-packages.git] / systemd / trunk / initcpio-install-systemd
blobff29d8c54a63df61fc376bab803b315e89ab5b15
1 #!/bin/bash
3 add_systemd_unit() {
4 # Add a systemd unit file to the initcpio image. Hard dependencies on binaries
5 # and other unit files will be discovered and added.
6 # $1: path to rules file (or name of rules file)
8 local unit= rule= entry= key= value= binary= dep=
10 unit=$(PATH=/usr/lib/systemd/system:/lib/systemd/system type -P "$1")
11 if [[ -z $unit ]]; then
12 # complain about not found unit file
13 return 1
16 add_file "$unit"
18 while IFS='=' read -r key values; do
19 read -ra values <<< "$values"
21 case $key in
22 Requires|OnFailure)
23 # only add hard dependencies (not Wants)
24 map add_systemd_unit "${values[@]}"
26 Exec*)
27 # do not add binaries unless they are required,
28 # strip special executable prefixes
29 case ${values[0]} in
30 -*) ;;
31 !!*) add_binary "${values[0]#!!}" ;;
32 *) add_binary "${values[0]#[@!:+]}" ;;
33 esac
35 esac
37 done <"$unit"
39 # preserve reverse soft dependency
40 for dep in {/usr,}/lib/systemd/system/*.wants/${unit##*/}; do
41 if [[ -L $dep ]]; then
42 add_symlink "$dep"
44 done
46 # add hard dependencies
47 if [[ -d $unit.requires ]]; then
48 for dep in "$unit".requires/*; do
49 add_systemd_unit ${dep##*/}
50 done
54 add_systemd_drop_in() {
55 local unit=$1 dropin_name=$2
57 mkdir -p "$BUILDROOT/etc/systemd/system/$unit.d"
58 cat >"$BUILDROOT/etc/systemd/system/$unit.d/$2.conf"
61 build() {
62 local rules unit
64 add_binary /usr/bin/kmod /usr/bin/modprobe
65 add_binary /usr/bin/mount
66 add_binary /usr/bin/sulogin
67 add_binary /usr/bin/umount
68 add_binary /usr/lib/systemd/systemd /init
70 map add_binary \
71 /usr/bin/journalctl \
72 /usr/bin/systemd-tmpfiles \
73 /usr/lib/systemd/systemd-hibernate-resume \
74 /usr/lib/systemd/systemd-shutdown \
75 /usr/lib/systemd/systemd-sulogin-shell \
76 /usr/lib/systemd/system-generators/systemd-fstab-generator \
77 /usr/lib/systemd/system-generators/systemd-gpt-auto-generator \
78 /usr/lib/systemd/system-generators/systemd-hibernate-resume-generator
80 # udev rules
81 map add_udev_rule "$rules" \
82 50-udev-default.rules \
83 60-persistent-storage.rules \
84 64-btrfs.rules \
85 80-drivers.rules \
86 99-systemd.rules
88 # systemd units
89 map add_systemd_unit \
90 initrd-cleanup.service \
91 initrd-fs.target \
92 initrd-parse-etc.service \
93 initrd-root-fs.target \
94 initrd-root-device.target \
95 initrd-switch-root.service \
96 initrd-switch-root.target \
97 initrd-udevadm-cleanup-db.service \
98 initrd.target \
99 kmod-static-nodes.service \
100 local-fs.target \
101 local-fs-pre.target \
102 paths.target \
103 reboot.target \
104 slices.target \
105 sockets.target \
106 swap.target \
107 systemd-fsck@.service \
108 systemd-hibernate-resume@.service \
109 systemd-journald-audit.socket \
110 systemd-journald-dev-log.socket \
111 systemd-journald.service \
112 systemd-modules-load.service \
113 systemd-pcrphase-initrd.service \
114 systemd-tmpfiles-setup-dev.service \
115 systemd-udevd-control.socket \
116 systemd-udevd-kernel.socket \
117 systemd-udevd.service \
118 systemd-udev-trigger.service \
119 timers.target \
120 rescue.target \
121 emergency.target
123 # add libraries dlopen()ed by tpm2-util
124 for LIB in tss2-{esys,rc,mu,tcti-'*'}; do
125 for FILE in $(find /usr/lib/ -maxdepth 1 -name "lib${LIB}.so*"); do
126 if [[ -L "${FILE}" ]]; then
127 add_symlink "${FILE}"
128 else
129 add_binary "${FILE}"
131 done
132 done
134 add_symlink "/usr/lib/systemd/system/default.target" "initrd.target"
135 add_symlink "/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
137 printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
138 'passwd: files' \
139 'group: files' \
140 'shadow: files'
142 echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
143 echo 'root:*:::::::' >"$BUILDROOT/etc/shadow"
144 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"
146 add_dir "/etc/modules-load.d"
148 . "$_f_config"
149 set -f
150 printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
154 help() {
155 cat <<HELPEOF
156 This will install a basic systemd setup in your initramfs, and is meant to
157 replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
158 components will need to be ported, and will not work as intended. You also may
159 wish to still include the 'base' hook (before this hook) to ensure that a
160 rescue shell exists on your initramfs.
161 HELPEOF
164 # vim: set ft=sh ts=4 sw=4 et: