diskimage-builder/diskimage_builder/elements/fedora/root.d/10-fedora-cloud-image
Dmitriy Rabotyagov 2bfa132264 Fix baseurl for Fedora versions before 36
Fedora has moved their old images (prior to 37) to archives,
so default URIs are adjusted to reflect that.

Change-Id: I81dc6df4e4372149cffe448708ac2416d3528394
2023-08-07 14:38:05 +02:00

62 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
if [ 'amd64' = "$ARCH" ] ; then
ARCH="x86_64"
fi
if [[ "${ARCH}" == "arm64" ]]; then
ARCH="aarch64"
fi
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-""}
if [ -n "$DIB_LOCAL_IMAGE" ]; then
IMAGE_LOCATION=$DIB_LOCAL_IMAGE
# No need to copy a local image into the cache directory, so just specify
# the cached path as the original path.
CACHED_IMAGE=$IMAGE_LOCATION
BASE_IMAGE_FILE=`basename $DIB_LOCAL_IMAGE`
BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz
else
# note default DIB_RELEASE set in environment setup
case ${ARCH} in
x86_64|aarch64)
if [[ ${DIB_RELEASE} -ge 37 ]]; then
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://download.fedoraproject.org/pub/fedora/linux/releases/${DIB_RELEASE}/Cloud/${ARCH}/images}
elif [[ ${DIB_RELEASE} -ge 28 ]] && [[ ${DIB_RELEASE} -le 36 ]]; then
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/${DIB_RELEASE}/Cloud/${ARCH}/images}
else
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/${DIB_RELEASE}/CloudImages/${ARCH}/images}
fi
;;
ppc64|ppc64le)
if [[ ${DIB_RELEASE} -ge 37 ]]; then
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-https://dl.fedoraproject.org/pub/fedora-secondary/releases/${DIB_RELEASE}/Cloud/${ARCH}/images}
elif [[ ${DIB_RELEASE} -ge 28 ]] && [[ ${DIB_RELEASE} -le 36 ]]; then
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://archives.fedoraproject.org/pub/archive/fedora-secondary/releases/${DIB_RELEASE}/Cloud/${ARCH}/images}
else
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://archives.fedoraproject.org/pub/archive/fedora-secondary/releases/${DIB_RELEASE}/CloudImages/${ARCH}/images}
fi
;;
*)
echo "Error: unknown ARCH: ${ARCH}"
exit 1
;;
esac
SUBRELEASE=$(head -1 < <(curl -Ls $DIB_CLOUD_IMAGES/ | grep -o -P '(?<=Fedora-Cloud-Base-'${DIB_RELEASE}'-).*?(?=.'${ARCH}'.qcow2")' | sort -r))
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-Fedora-Cloud-Base-$DIB_RELEASE-$SUBRELEASE.$ARCH.qcow2}
BASE_IMAGE_TAR=Fedora-Cloud-Base-$DIB_RELEASE-$SUBRELEASE.$ARCH.tgz
IMAGE_LOCATION=$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE
CACHED_IMAGE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
fi
$TMP_HOOKS_PATH/bin/extract-image $BASE_IMAGE_FILE $BASE_IMAGE_TAR $IMAGE_LOCATION $CACHED_IMAGE