2022-11-04 18:08:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
echo $* >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
requireCommands() {
|
|
|
|
for cmd in $*; do
|
|
|
|
if ! command -v $cmd &> /dev/null; then
|
|
|
|
fail "Cannot find required command: $cmd"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-08-21 17:45:09 +00:00
|
|
|
newlineToJson() {
|
|
|
|
first_item=true
|
|
|
|
printf '['
|
|
|
|
while IFS= read -r line; do
|
|
|
|
if [ "$first_item" = false ]; then
|
|
|
|
printf ', '
|
|
|
|
fi
|
|
|
|
printf '"%s"' "$line"
|
|
|
|
first_item=false
|
|
|
|
done
|
|
|
|
printf ']\n'
|
|
|
|
}
|
|
|
|
|
2023-09-23 02:25:57 +00:00
|
|
|
release="$(awk -F'[<>]' '/release-version/ { print $3 }' config.xml)"
|
2023-07-20 18:42:05 +00:00
|
|
|
if [ -f buildver ]; then
|
|
|
|
date="$(cat buildver)"
|
|
|
|
else
|
|
|
|
date=$(date +%Y%m%d%H%m)
|
|
|
|
fi
|
2022-11-04 21:46:46 +00:00
|
|
|
image="${1:-outdir/Fedora-Asahi-Remix.aarch64-0.0.0.raw}"
|
2022-11-05 17:38:16 +00:00
|
|
|
package="${2:-fedora-${release}-${date}}"
|
|
|
|
|
|
|
|
[ "$release" = rawhide ] && pretty_release="Rawhide" || pretty_release="$release"
|
2022-11-04 18:08:16 +00:00
|
|
|
|
|
|
|
if [ ! -r "$image" ]; then
|
|
|
|
fail "$image does not exist or cannot be read!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "$package" ]; then
|
|
|
|
fail "$package already exists, aborting"
|
|
|
|
fi
|
|
|
|
|
2022-12-23 08:18:21 +00:00
|
|
|
requireCommands 7z awk cat cp dd fdisk file mkdir mv stat wget
|
2022-11-04 18:08:16 +00:00
|
|
|
|
2022-12-23 20:25:24 +00:00
|
|
|
workdir="$(mktemp -dp /var/tmp)"
|
2022-11-04 18:08:16 +00:00
|
|
|
trap 'rm -rf "$workdir"' EXIT
|
|
|
|
|
|
|
|
basedir="$PWD"
|
|
|
|
imagename="$(basename "$image")"
|
|
|
|
imagedir="$(dirname "$image")"
|
|
|
|
|
|
|
|
# extract filesystems from disk image
|
2022-11-04 21:46:46 +00:00
|
|
|
pushd "$imagedir" > /dev/null
|
2022-12-23 08:18:21 +00:00
|
|
|
eval "$(fdisk -Lnever -lu -b 4096 "$imagename" | awk "/^${imagename}/ { printf \"dd if=${imagename} of=${workdir}/%s skip=%s count=%s bs=4096\\n\", \$1, \$2, \$4 }")"
|
2022-11-04 21:46:46 +00:00
|
|
|
popd > /dev/null
|
2022-11-04 18:08:16 +00:00
|
|
|
|
|
|
|
# build package
|
|
|
|
mkdir -p "${workdir}/package/esp"
|
2022-12-23 08:18:21 +00:00
|
|
|
7z x -o"${workdir}/package/esp" "${workdir}/${imagename}1"
|
2022-11-04 18:08:16 +00:00
|
|
|
mv "${workdir}/${imagename}2" "${workdir}/package/boot.img"
|
|
|
|
mv "${workdir}/${imagename}3" "${workdir}/package/root.img"
|
|
|
|
|
2023-08-29 14:35:02 +00:00
|
|
|
# fix up grub in the ESP
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=2235692
|
|
|
|
sed -i 's:source :configfile :' "${workdir}/package/esp/EFI/fedora/grub.cfg"
|
|
|
|
rm "${workdir}/package/esp/EFI/BOOT/grubaa64.efi" "${workdir}/package/esp/EFI/BOOT/grub.cfg"
|
|
|
|
|
2022-11-05 05:05:39 +00:00
|
|
|
esp_volume_id="$(file "${workdir}/${imagename}1" | awk -v 'RS=,' '/serial number/ { print $3 }')"
|
|
|
|
esp_size="$(stat -c %s "${workdir}/${imagename}1")"
|
|
|
|
boot_size="$(stat -c %s "${workdir}/package/boot.img")"
|
|
|
|
root_size="$(stat -c %s "${workdir}/package/root.img")"
|
|
|
|
|
2022-12-23 08:18:21 +00:00
|
|
|
# boot picker icon
|
2022-11-05 15:57:52 +00:00
|
|
|
if [ ! -f fedora.icns ]; then
|
|
|
|
wget https://pagure.io/fedora-logos/blob/master/f/bootloader/fedora.icns
|
|
|
|
fi
|
|
|
|
cp -p fedora.icns "${workdir}/package"
|
|
|
|
|
2022-11-04 21:46:46 +00:00
|
|
|
pushd "${workdir}/package" > /dev/null
|
2022-12-23 08:18:21 +00:00
|
|
|
7z a -tzip -r "${basedir}/${package}" .
|
2022-11-04 21:46:46 +00:00
|
|
|
popd > /dev/null
|
|
|
|
|
2023-08-21 17:45:09 +00:00
|
|
|
openh264_rpms=$(rpmdistro-repoquery fedora "$release" gstreamer1-plugin-openh264 mozilla-openh264 openh264 --location)
|
|
|
|
|
2023-07-20 15:31:18 +00:00
|
|
|
cat > "${package}.json" <<EOF
|
2022-11-04 21:46:46 +00:00
|
|
|
{
|
2023-07-20 15:31:18 +00:00
|
|
|
"name": "Fedora Linux ${pretty_release}",
|
|
|
|
"default_os_name": "Fedora Linux ${pretty_release}",
|
|
|
|
"boot_object": "m1n1.bin",
|
|
|
|
"next_object": "m1n1/boot.bin",
|
|
|
|
"package": "${package}.zip",
|
|
|
|
"icon": "fedora.icns",
|
2023-08-02 08:49:49 +00:00
|
|
|
"supported_fw": ["13.5"],
|
2023-08-21 17:45:09 +00:00
|
|
|
"extras": $(printf '%s\n' "$openh264_rpms" | newlineToJson),
|
2023-07-20 15:31:18 +00:00
|
|
|
"partitions": [
|
|
|
|
{
|
|
|
|
"name": "EFI",
|
|
|
|
"type": "EFI",
|
|
|
|
"size": "${esp_size}B",
|
|
|
|
"format": "fat",
|
|
|
|
"volume_id": "${esp_volume_id}",
|
|
|
|
"copy_firmware": true,
|
|
|
|
"copy_installer_data": true,
|
|
|
|
"source": "esp"
|
|
|
|
},
|
2022-11-04 21:46:46 +00:00
|
|
|
{
|
2023-07-20 15:31:18 +00:00
|
|
|
"name": "Boot",
|
|
|
|
"type": "Linux",
|
|
|
|
"size": "${boot_size}B",
|
|
|
|
"image": "boot.img"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Root",
|
|
|
|
"type": "Linux",
|
|
|
|
"size": "${root_size}B",
|
|
|
|
"expand": true,
|
|
|
|
"image": "root.img"
|
2022-11-04 21:46:46 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
2023-07-20 00:39:31 +00:00
|
|
|
|
2023-07-20 15:31:18 +00:00
|
|
|
cat > installer_data.json <<EOF
|
|
|
|
{
|
|
|
|
"os_list": [
|
|
|
|
$(cat "${package}.json")
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2023-07-20 00:39:31 +00:00
|
|
|
# Package up the logs
|
|
|
|
mkdir -p "${workdir}/logs"
|
|
|
|
cp -p \
|
|
|
|
outdir/build/image-root.log \
|
|
|
|
outdir/Fedora-Asahi-Remix.aarch64-0.0.0.changes \
|
|
|
|
outdir/Fedora-Asahi-Remix.aarch64-0.0.0.packages \
|
|
|
|
outdir/kiwi.result.json \
|
|
|
|
"${workdir}/logs/"
|
|
|
|
pushd "${workdir}/logs" > /dev/null
|
2023-07-20 17:00:28 +00:00
|
|
|
7z a -tzip -r "${basedir}/${package}.logs.zip" .
|
2023-07-20 00:39:31 +00:00
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
# Package up the raw image
|
|
|
|
zstd -c9 < "${image}" > "${basedir}/${package}.raw.zst"
|