summarylogtreecommitdiffstats
path: root/dracut-uefi-install
blob: f1f2429e19833775280a0843b261ebf875f8e243 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash -e

[ -f "/etc/dracut-uefi-hook.conf" ] && source /etc/dracut-uefi-hook.conf

ESP_PATH=$(bootctl --print-esp-path)
MACHINE_ID=$(</etc/machine-id)
source <(grep '^BUILD_ID=' /etc/os-release)

declare -A kernels
dracut_update=0

while read -r line; do
    if [[ $line =~ ^usr/lib/modules/([^/]+)/pkgbase$ ]]; then
        read -r pkgbase < "/${line}"
        kernels["${pkgbase}"]="${BASH_REMATCH[1]}"
    else
        dracut_update=1 # Dracut files have been updated
        break 
    fi
done

if (( dracut_update )); then
    for candidate in /usr/lib/modules/*; do
        [ -f "$candidate/pkgbase" ] || continue
        if read -r pkgbase &> /dev/null < "$candidate/pkgbase"; then
            kernels["${pkgbase}"]="$(basename "$candidate")"
        fi
    done
fi

for kernel in "${!kernels[@]}"; do
    version="${kernels[$kernel]}"
    path="/usr/lib/modules/${version}/pkgbase"
    
    read -r pkgbase < "$path"

    echo "==> Building linux image $kernel ($version)"
    
    if [[ "$hook_for_pretty_name" == "true" ]]; then
        tmp_file=$(mktemp)
        cat /etc/os-release > "$tmp_file"
        echo "VERSION_ID=\"$pkgbase $version\"" >> "$tmp_file"
        unshare -m /bin/sh -c "mount --bind '$tmp_file' /etc/os-release && dracut -q -f --uefi --kver '${version}'"
        rm "$tmp_file"
    else
        dracut -q -f --uefi --kver "${version}"
    fi

    if [[ "$pkgbase" == "$default_kernel_package" ]]; then
        echo "===> Mark linux image $kernel ($version) as default"
        bootctl set-default "linux-${version}-${MACHINE_ID}-${BUILD_ID}.efi" || {
        	echo "===> Unable to mark linux image $kernel ($version) as default" >&2
        }
    fi
done