]>
Commit | Line | Data |
---|---|---|
69395a52 | 1 | #!/bin/bash |
9dd9d81f | 2 | |
ccb8ce04 HH |
3 | COMMAND="$1" |
4 | KERNEL_VERSION="$2" | |
5 | BOOT_DIR_ABS="$3" | |
6 | KERNEL_IMAGE="$4" | |
83bb0893 | 7 | |
b71d162a YW |
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 | ||
b39b8452 JMC |
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 | ||
ccb8ce04 HH |
21 | ret=0 |
22 | case "$COMMAND" in | |
23 | add) | |
bc140a0b HH |
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 | |
b39b8452 JMC |
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" \ | |
bc140a0b HH |
31 | && exit 0 |
32 | fi | |
33 | ||
ccb8ce04 | 34 | if [[ -f /etc/kernel/cmdline ]]; then |
a6018700 | 35 | read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline |
a7d3ad67 | 36 | elif [[ -f /usr/lib/kernel/cmdline ]]; then |
a6018700 | 37 | read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline |
ccb8ce04 | 38 | fi |
83bb0893 | 39 | |
a6018700 HH |
40 | if ! [[ ${BOOT_OPTIONS[*]} ]]; then |
41 | read -r -d '' -a BOOT_OPTIONS < /proc/cmdline | |
ccb8ce04 | 42 | fi |
83bb0893 | 43 | |
ccb8ce04 | 44 | unset noimageifnotneeded |
83bb0893 | 45 | |
ccb8ce04 HH |
46 | for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do |
47 | if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then | |
48 | noimageifnotneeded="yes" | |
49 | break | |
50 | fi | |
51 | done | |
b39b8452 | 52 | dracut ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION" |
9dd9d81f HH |
53 | ret=$? |
54 | ;; | |
55 | remove) | |
b39b8452 | 56 | rm -f -- "$BOOT_DIR_ABS/$INITRD" |
9dd9d81f HH |
57 | ret=$? |
58 | ;; | |
59 | esac | |
60 | exit $ret |