Files
lima/cmd/limactl-url-fedora-rawhide
Kir Kolyshkin eaba0be694 limactl-url-fedora-rawhide: don't rely on COMPOSE_ID
The rawhide/COMPOSE_ID file on dl.fedoraproject.org is sometimes out of
sync with the contents of the images directory. For example, currently
COMPOSE_ID says Fedora-Rawhide-20260929.n.0, while the only image
available is Fedora-Cloud-Base-Generic-Rawhide-20261002.n.0, so
starting an instance from experimental/fedora-rawhide fails with:

	failed to download `https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-Rawhide-20260929.n.0.x86_64.qcow2`: unexpected HTTP status Not Found

Instead, get the image file name from the CHECKSUM file in the images
directory, which describes the images actually present there. As a
bonus, this also gives us the image digest.

While at it, add --retry to curl invocations.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-10-02 16:37:11 -07:00

72 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# SPDX-FileCopyrightText: Copyright The Lima Authors
# SPDX-License-Identifier: Apache-2.0
set -eu
if [ "$#" -ne 1 ]; then
echo >&2 "Usage: $0 _images/fedora-rawhide"
exit 1
fi
if [ "$1" != "_images/fedora-rawhide" ]; then
echo >&2 "Expected argument to be '_images/fedora-rawhide', but got '$1'"
exit 1
fi
CACHE_HOME_DEFAULT="${HOME}/.cache"
if [ "$(uname -s)" = "Darwin" ]; then
CACHE_HOME_DEFAULT="${HOME}/Library/Caches"
fi
: "${XDG_CACHE_HOME:=${CACHE_HOME_DEFAULT}}"
CACHE_DIR="${XDG_CACHE_HOME}/lima/limactl-url-fedora-rawhide"
URL="https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud"
# Print the image entry for the given architecture.
#
# The image name and digest are taken from the CHECKSUM file in the images
# directory, rather than from rawhide/COMPOSE_ID, as the latter is sometimes
# out of sync with the directory contents, referring to an image that no
# longer exists.
image() {
arch="$1"
dir="${URL}/${arch}/images"
# CHECKSUM is like "Fedora-Cloud-images-Rawhide-x86_64-20260316.n.0-CHECKSUM"
checksum="$(curl -fsSL --retry 5 "${dir}/" |
sed -n 's/.*href="\(Fedora-Cloud-images-Rawhide-'"${arch}"'-[^"]*-CHECKSUM\)".*/\1/p' | head -n 1)"
if [ -z "${checksum}" ]; then
echo >&2 "No CHECKSUM file found in ${dir}/"
return 1
fi
# line is like "SHA256 (Fedora-Cloud-Base-Generic-Rawhide-20260316.n.0.x86_64.qcow2) = <digest>"
line="$(curl -fsSL --retry 5 "${dir}/${checksum}" |
grep -E "^SHA256 \(Fedora-Cloud-Base-Generic-Rawhide-[^)]+\.${arch}\.qcow2\) = [0-9a-f]{64}$" | head -n 1)"
if [ -z "${line}" ]; then
echo >&2 "No image found in ${dir}/${checksum}"
return 1
fi
name="${line#SHA256 (}"
name="${name%%)*}"
digest="${line##* }"
cat <<EOF
- location: "${dir}/${name}"
arch: "${arch}"
digest: "sha256:${digest}"
EOF
}
IMAGE_X86_64="$(image x86_64)"
IMAGE_AARCH64="$(image aarch64)"
mkdir -p "${CACHE_DIR}"
FILE="${CACHE_DIR}/fedora-rawhide.yaml"
cat <<EOF >"${FILE}"
images:
${IMAGE_X86_64}
${IMAGE_AARCH64}
EOF
echo "$FILE"