]> git.ipfire.org Git - thirdparty/dracut.git/blob - 50-dracut.install
Revert "github workflow"
[thirdparty/dracut.git] / 50-dracut.install
1 #!/bin/bash
2
3 COMMAND="$1"
4 KERNEL_VERSION="$2"
5 BOOT_DIR_ABS="$3"
6 KERNEL_IMAGE="$4"
7
8 # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
9 # So, let's skip to create initrd.
10 if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
11 exit 0
12 fi
13
14 if [[ -d "$BOOT_DIR_ABS" ]]; then
15 INITRD="initrd"
16 else
17 BOOT_DIR_ABS="/boot"
18 INITRD="initramfs-${KERNEL_VERSION}.img"
19 fi
20
21 ret=0
22 case "$COMMAND" in
23 add)
24 INITRD_IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
25 if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
26 # we found an initrd at the same place as the kernel
27 # use this and don't generate a new one
28 cp --reflink=auto "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/$INITRD" \
29 && chown root:root "$BOOT_DIR_ABS/$INITRD" \
30 && chmod 0600 "$BOOT_DIR_ABS/$INITRD" \
31 && exit 0
32 fi
33
34 if [[ -f /etc/kernel/cmdline ]]; then
35 read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
36 elif [[ -f /usr/lib/kernel/cmdline ]]; then
37 read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
38 else
39 declare -a BOOT_OPTIONS
40
41 read -r -d '' -a line < /proc/cmdline
42 for i in "${line[@]}"; do
43 [[ "${i#initrd=*}" != "$i" ]] && continue
44 BOOT_OPTIONS+=("$i")
45 done
46 fi
47
48 unset noimageifnotneeded
49
50 for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do
51 if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then
52 noimageifnotneeded="yes"
53 break
54 fi
55 done
56 dracut -f ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
57 ret=$?
58 ;;
59 remove)
60 rm -f -- "$BOOT_DIR_ABS/$INITRD"
61 ret=$?
62 ;;
63 esac
64 exit $ret