-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-esp.sh
executable file
·26 lines (21 loc) · 1.1 KB
/
patch-esp.sh
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
#!/bin/bash -e
# See https://github.com/systemd/mkosi/issues/2024 and https://github.com/systemd/mkosi/issues/1638
echo -n "Patching UKI name to comply with systemd-sysupdate... "
img=${1:-$(mkosi --json summary|jq -r '.Images[0]|(.OutputDirectory+"/"+.Output+".raw")')}
IMAGE_ID=${IMAGE_ID:-$(mkosi --json summary|jq -r '.Images[0].ImageId')}
OUTPUT=${OUTPUT:-$(mkosi --json summary|jq -r '.Images[0].Output')}
if ! [ -f "$img" ] ; then
echo "$img does not exist"
exit 1
fi
esp=$(mktemp)
dd status=none of=$esp if=$img $(sfdisk -J $img|jq -r '.partitiontable|("bs="+(.sectorsize|tostring)+" skip=")+(.partitions[0]|((.start|tostring)+" count="+(.size|tostring)))')
if mdir -i $esp "EFI/Linux/$IMAGE_ID-*.efi" >/dev/null 2>/dev/null ; then
mren -i $esp "EFI/Linux/$IMAGE_ID-*.efi" "EFI/Linux/${OUTPUT}.efi"
mdel -i $esp "vmlinuz*" >/dev/null 2>/dev/null || true
dd conv=notrunc status=none if=$esp of=$img $(sfdisk -J $img|jq -r '.partitiontable|("bs="+(.sectorsize|tostring)+" seek=")+(.partitions[0]|((.start|tostring)+" count="+(.size|tostring)))')
echo "done"
else
echo "nothing to patch"
fi
rm $esp