From 0a3207522059d57bfee927216e072e2d1bfe1a83 Mon Sep 17 00:00:00 2001 From: Lukas Greve Date: Sun, 2 Nov 2025 11:52:39 +0100 Subject: [PATCH] add logic to avoid refetching fedora rawhide if already present. Otherwise, this script redownload rawhide almost every day, as there is a new image everyday --- .../download_images.sh => download_images.sh | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) rename scripts/download_images.sh => download_images.sh (75%) diff --git a/scripts/download_images.sh b/download_images.sh similarity index 75% rename from scripts/download_images.sh rename to download_images.sh index a912db7..1cf57e0 100755 --- a/scripts/download_images.sh +++ b/download_images.sh @@ -4,13 +4,13 @@ get_fedora_latest_rawhide_url() { local base_url="https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images/" - # Method 1: Try fetching the latest link from the directory + # Method: Try fetching the latest link from the directory local temp_dir temp_dir=$(mktemp -d) # Download the HTML directory listing if curl -s -o "$temp_dir/listing.html" "$base_url"; then - # Look for lines with qcow2 files that match our pattern + # Look for the most recent Fedora-Cloud-Base-Generic-Rawhide qcow2 file local latest_file latest_file=$(grep -i "Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2" "$temp_dir/listing.html" | \ sort -r | head -1 | sed -E 's/.*href="([^"]*)".*/\1/') @@ -18,15 +18,15 @@ get_fedora_latest_rawhide_url() { if [[ -n "$latest_file" ]]; then echo "${base_url}${latest_file}" else - # If we can't find a specific file, try to find any valid Fedora image + # If we can't find Fedora-Cloud-Base-Generic-Rawhide specifically, + # look for any Fedora image with a qcow2 extension local any_file - any_file=$(grep -i "Fedora-Cloud-Base-Generic.*\.qcow2" "$temp_dir/listing.html" | \ + any_file=$(grep -i "Fedora.*\.qcow2" "$temp_dir/listing.html" | \ head -1 | sed -E 's/.*href="([^"]*)".*/\1/') if [[ -n "$any_file" ]]; then echo "${base_url}${any_file}" else - # Return empty string if we can't find any valid file echo "" fi fi @@ -39,6 +39,24 @@ get_fedora_latest_rawhide_url() { rm -rf "$temp_dir" } +# Function to check if a Fedora Rawhide image already exists in the target directory +check_fedora_rawhide_exists() { + local target_dir="$1" + + # Look for any existing Fedora Rawhide image by pattern + if [[ -d "$target_dir" ]]; then + local exists + exists=$(find "$target_dir" -maxdepth 1 -type f -name "*Fedora-Cloud-Base-Generic-Rawhide*.qcow2" 2>/dev/null | head -1) + if [[ -n "$exists" ]]; then + echo "true" + else + echo "false" + fi + else + echo "false" + fi +} + # Image URLs with dynamic Fedora URL handling IMAGES=( "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw" @@ -49,10 +67,13 @@ IMAGES=( "https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2" ) -# Add Fedora image if we can get a valid URL -FEDORA_URL=$(get_fedora_latest_rawhide_url) -if [[ -n "$FEDORA_URL" ]]; then - IMAGES+=("$FEDORA_URL") +# Add Fedora image if we can get a valid URL AND no Fedora Rawhide image exists +FEDORA_EXISTS=$(check_fedora_rawhide_exists "/var/lib/libvirt/images") +if [[ "$FEDORA_EXISTS" == "false" ]]; then + FEDORA_URL=$(get_fedora_latest_rawhide_url) + if [[ -n "$FEDORA_URL" ]]; then + IMAGES+=("$FEDORA_URL") + fi fi # Target directory