summarylogtreecommitdiffstats
path: root/dracut-install
blob: e0ef1ad2ce9212cb708e28f93e4944dceac5374f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash -e

all=0
lines=()

while read -r line; do
	if [[ "${line}" != */vmlinuz ]]; then
		# triggers when it's a change to dracut files
		all=1
		continue
	fi

	lines+=("/${line%/vmlinuz}")

	pkgbase="$(<"${lines[-1]}/pkgbase")"
	install -Dm644 "/${line}" "/boot/vmlinuz-${pkgbase}"
done

if (( all )); then
	lines=(/usr/lib/modules/*)
fi

for line in "${lines[@]}"; do
	if ! pacman -Qqo "${line}/pkgbase" &> /dev/null; then
		# if pkgbase does not belong to any package then skip this kernel
		continue
	fi

	pkgbase="$(<"${line}/pkgbase")"
	kver="${line##*/}"
	dracut_restore_img="/usr/lib/modules/${kver}/initrd"

	echo ":: Building initramfs for ${pkgbase} (${kver})"
	dracut --force --hostonly --no-hostonly-cmdline ${dracut_restore_img} "${kver}"
	install -Dm644 ${dracut_restore_img} "/boot/initramfs-${pkgbase}.img"

	echo ":: Building fallback initramfs for ${pkgbase} (${kver})"
	dracut --force --no-hostonly "/boot/initramfs-${pkgbase}-fallback.img" "${kver}"
done