diff --git a/download_images.sh b/download_images.sh index 1012033..a912db7 100755 --- a/download_images.sh +++ b/download_images.sh @@ -1,6 +1,45 @@ #!/bin/bash -# Image URLs +# Function to get latest Fedora Rawhide image URL using a more reliable method +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 + 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 + 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/') + + 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 + local any_file + any_file=$(grep -i "Fedora-Cloud-Base-Generic.*\.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 + else + # If network fails, return empty string to skip Fedora download + echo "" + fi + + # Cleanup + rm -rf "$temp_dir" +} + +# Image URLs with dynamic Fedora URL handling IMAGES=( "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw" "https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2" @@ -10,6 +49,12 @@ 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") +fi + # Target directory TARGET_DIR="/var/lib/libvirt/images" @@ -36,6 +81,11 @@ main() { local failure_count=0 for url in "${IMAGES[@]}"; do + # Skip empty URLs + if [[ -z "$url" ]]; then + continue + fi + local filename filename=$(basename "$url") local filepath="$TARGET_DIR/$filename"