Compare commits
2 Commits
1b757a98eb
...
d6e11a3e63
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6e11a3e63 | ||
|
|
f27930a294 |
@@ -1,6 +1,45 @@
|
|||||||
#!/bin/bash
|
#!/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=(
|
IMAGES=(
|
||||||
"https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
"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"
|
"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"
|
"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 directory
|
||||||
TARGET_DIR="/var/lib/libvirt/images"
|
TARGET_DIR="/var/lib/libvirt/images"
|
||||||
|
|
||||||
@@ -36,6 +81,11 @@ main() {
|
|||||||
local failure_count=0
|
local failure_count=0
|
||||||
|
|
||||||
for url in "${IMAGES[@]}"; do
|
for url in "${IMAGES[@]}"; do
|
||||||
|
# Skip empty URLs
|
||||||
|
if [[ -z "$url" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
local filename
|
local filename
|
||||||
filename=$(basename "$url")
|
filename=$(basename "$url")
|
||||||
local filepath="$TARGET_DIR/$filename"
|
local filepath="$TARGET_DIR/$filename"
|
||||||
|
|||||||
@@ -53,20 +53,47 @@ if [[ ! -d "$IMAGE_DIR" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Image URLs (hardcoded original URLs from download_images.sh)
|
# Function to get all locally available image files (including Fedora Rawhide)
|
||||||
ORIGINAL_IMAGES=(
|
get_local_images() {
|
||||||
"https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
find "$IMAGE_DIR" -maxdepth 1 -type f \( -name "*.qcow2" -o -name "*.raw" -o -name "*.img" \) | \
|
||||||
"https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
|
while read -r image; do
|
||||||
"https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2"
|
basename "$image"
|
||||||
"https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
done | sort
|
||||||
"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
}
|
||||||
"https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Function to get filename from URL
|
# Function to check if a local file matches the pattern for a Fedora Rawhide image
|
||||||
get_filename_from_url() {
|
is_fedora_rawhide_image() {
|
||||||
local url=$1
|
local filename=$1
|
||||||
basename "$url"
|
# Pattern matching for Fedora Rawhide images that contain "Fedora-Cloud-Base-Generic-Rawhide"
|
||||||
|
if [[ "$filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get the latest Fedora Rawhide image path from local directory
|
||||||
|
get_latest_fedora_rawhide_path() {
|
||||||
|
local latest_file
|
||||||
|
latest_file=$(find "$IMAGE_DIR" -maxdepth 1 -name "Fedora-Cloud-Base-Generic-Rawhide*.qcow2" -type f \
|
||||||
|
| sort -r \
|
||||||
|
| head -1)
|
||||||
|
|
||||||
|
if [[ -n "$latest_file" ]]; then
|
||||||
|
echo "$latest_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to provide a mapping between local files and their original URLs
|
||||||
|
create_original_url_mapping() {
|
||||||
|
# Create a hash-like mapping for known images
|
||||||
|
cat << 'EOF'
|
||||||
|
noble-server-cloudimg-amd64.img=https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
|
||||||
|
Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2=https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2
|
||||||
|
openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2=https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2
|
||||||
|
Rocky-10-GenericCloud-Base.latest.x86_64.qcow2=https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
|
||||||
|
debian-13-genericcloud-amd64.raw=https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw
|
||||||
|
CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2=https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find all main.tf files and process them
|
# Find all main.tf files and process them
|
||||||
@@ -96,16 +123,40 @@ for file in $MAIN_TF_FILES; do
|
|||||||
temp_file=$(mktemp)
|
temp_file=$(mktemp)
|
||||||
|
|
||||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
|
# Check if the line contains a file:// URL
|
||||||
if [[ "$line" =~ .*image_location.*=.*\"file://(.*?)\".* ]]; then
|
if [[ "$line" =~ .*image_location.*=.*\"file://(.*?)\".* ]]; then
|
||||||
# Extract local path from the file:// URL
|
# Extract local path from the file:// URL
|
||||||
local_file_path="${BASH_REMATCH[1]}"
|
local_file_path="${BASH_REMATCH[1]}"
|
||||||
local_filename=$(basename "$local_file_path")
|
local_filename=$(basename "$local_file_path")
|
||||||
|
|
||||||
# Find matching original URL for this filename
|
# Handle Fedora Rawhide images specially
|
||||||
|
if [[ "$local_filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
echo " Reverting Fedora Rawhide image: $local_filename"
|
||||||
|
|
||||||
|
# For Rawhide, we'll keep the file:// reference but note that it's a special case
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
else
|
||||||
|
echo " Would process Fedora Rawhide image: $local_filename (keeping file:// reference)"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# For regular images, try to map back to original URL
|
||||||
|
# Create mapping for this specific case
|
||||||
|
mapping=$(create_original_url_mapping)
|
||||||
|
|
||||||
|
# Find matching original URL
|
||||||
found_match=false
|
found_match=false
|
||||||
for original_url in "${ORIGINAL_IMAGES[@]}"; do
|
while IFS= read -r mapping_line; do
|
||||||
if [[ "$(basename "$original_url")" == "$local_filename" ]]; then
|
if [[ -z "$mapping_line" ]] || [[ "$mapping_line" =~ ^#.*$ ]]; then
|
||||||
echo " Found matching file: $local_filename"
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
file_pattern=$(echo "$mapping_line" | cut -d'=' -f1)
|
||||||
|
original_url=$(echo "$mapping_line" | cut -d'=' -f2)
|
||||||
|
|
||||||
|
if [[ "$file_pattern" == "$local_filename" ]]; then
|
||||||
|
echo " Found matching original URL: $local_filename"
|
||||||
|
|
||||||
if [ "$DRY_RUN" = false ]; then
|
if [ "$DRY_RUN" = false ]; then
|
||||||
# Use precise string replacement to avoid corrupting the file
|
# Use precise string replacement to avoid corrupting the file
|
||||||
@@ -119,12 +170,13 @@ for file in $MAIN_TF_FILES; do
|
|||||||
found_match=true
|
found_match=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done <<< "$mapping"
|
||||||
|
|
||||||
if [ "$found_match" = false ]; then
|
if [ "$found_match" = false ]; then
|
||||||
echo " Warning: No matching original URL found for $local_filename"
|
echo " Warning: No matching original URL found for $local_filename"
|
||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# Not a line with image_location, just copy as is
|
# Not a line with image_location, just copy as is
|
||||||
echo "$line" >> "$temp_file"
|
echo "$line" >> "$temp_file"
|
||||||
@@ -146,10 +198,54 @@ for file in $MAIN_TF_FILES; do
|
|||||||
remote_url="${BASH_REMATCH[1]}"
|
remote_url="${BASH_REMATCH[1]}"
|
||||||
filename=$(basename "$remote_url")
|
filename=$(basename "$remote_url")
|
||||||
|
|
||||||
# Check if the local file exists
|
# Check if the local file exists (including Fedora Rawhide cases)
|
||||||
local_path="$IMAGE_DIR/$filename"
|
local_path="$IMAGE_DIR/$filename"
|
||||||
|
|
||||||
if [[ -f "$local_path" ]]; then
|
# Special handling for Fedora Rawhide - check if it's the right pattern
|
||||||
|
if [[ "$filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
# For Fedora Rawhide, we need to be more flexible with matching patterns
|
||||||
|
echo " Checking Fedora Rawhide pattern for: $filename"
|
||||||
|
|
||||||
|
# Find the most recent Fedora image that matches the pattern but has different timestamp
|
||||||
|
latest_rawhide=$(find "$IMAGE_DIR" -maxdepth 1 -name "Fedora-Cloud-Base-Generic-Rawhide*.qcow2" -type f \
|
||||||
|
| sort -r \
|
||||||
|
| head -1)
|
||||||
|
|
||||||
|
if [[ -n "$latest_rawhide" ]]; then
|
||||||
|
echo " Found matching local Fedora Rawhide image: $(basename $latest_rawhide)"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
new_line="${line/\"$remote_url\"/\"file://$latest_rawhide\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Updated to local file: file://$latest_rawhide"
|
||||||
|
else
|
||||||
|
echo " Would update Fedora Rawhide to: file://$latest_rawhide"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No matching locally - check if we can find a similar pattern
|
||||||
|
echo " Checking for any Fedora-Cloud-Base-Generic-Rawhide*.qcow2 files..."
|
||||||
|
# Look for any file with the same prefix but different timestamp
|
||||||
|
local_candidates=$(find "$IMAGE_DIR" -maxdepth 1 -name "*Fedora-Cloud-Base-Generic-Rawhide*" -type f)
|
||||||
|
|
||||||
|
if [[ -n "$local_candidates" ]]; then
|
||||||
|
most_recent=$(echo "$local_candidates" | sort -r | head -1)
|
||||||
|
echo " Found matching local Fedora Rawhide image: $(basename $most_recent)"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
new_line="${line/\"$remote_url\"/\"file://$most_recent\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Updated to local file: file://$most_recent"
|
||||||
|
else
|
||||||
|
echo " Would update Fedora Rawhide to: file://$most_recent"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " Local Fedora Rawhide image not found, using original URL"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
elif [[ -f "$local_path" ]]; then
|
||||||
echo " Found local image: $filename"
|
echo " Found local image: $filename"
|
||||||
|
|
||||||
if [ "$DRY_RUN" = false ]; then
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user