OCaml 4.14.0 rebuild
[arch-packages.git] / systemd / repos / core-x86_64 / initcpio-install-systemd
blobb9d79857ad140010d6fca56f8c9bf90578538f05
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 and systemd units
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 map add_systemd_unit \
89 initrd-cleanup.service \
90 initrd-fs.target \
91 initrd-parse-etc.service \
92 initrd-root-fs.target \
93 initrd-root-device.target \
94 initrd-switch-root.service \
95 initrd-switch-root.target \
96 initrd-udevadm-cleanup-db.service \
97 initrd.target \
98 kmod-static-nodes.service \
99 local-fs.target \
100 local-fs-pre.target \
101 paths.target \
102 reboot.target \
103 slices.target \
104 sockets.target \
105 swap.target \
106 systemd-fsck@.service \
107 systemd-hibernate-resume@.service \
108 systemd-journald.service \
109 systemd-journald-audit.socket \
110 systemd-journald-dev-log.socket \
111 systemd-modules-load.service \
112 systemd-tmpfiles-setup-dev.service \
113 systemd-udev-trigger.service \
114 systemd-udevd-control.socket \
115 systemd-udevd-kernel.socket \
116 systemd-udevd.service \
117 timers.target \
118 rescue.target \
119 emergency.target
121 add_symlink "/usr/lib/systemd/system/default.target" "initrd.target"
122 add_symlink "/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
124 printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
125 'passwd: files' \
126 'group: files' \
127 'shadow: files'
129 echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
130 echo 'root:*:::::::' >"$BUILDROOT/etc/shadow"
131 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"
133 add_dir "/etc/modules-load.d"
135 . "$_f_config"
136 set -f
137 printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
141 help() {
142 cat <<HELPEOF
143 This will install a basic systemd setup in your initramfs, and is meant to
144 replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
145 components will need to be ported, and will not work as intended. You also may
146 wish to still include the 'base' hook (before this hook) to ensure that a
147 rescue shell exists on your initramfs.
148 HELPEOF
151 # vim: set ft=sh ts=4 sw=4 et: