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
This commit is contained in:
@@ -4,13 +4,13 @@
|
|||||||
get_fedora_latest_rawhide_url() {
|
get_fedora_latest_rawhide_url() {
|
||||||
local base_url="https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images/"
|
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
|
local temp_dir
|
||||||
temp_dir=$(mktemp -d)
|
temp_dir=$(mktemp -d)
|
||||||
|
|
||||||
# Download the HTML directory listing
|
# Download the HTML directory listing
|
||||||
if curl -s -o "$temp_dir/listing.html" "$base_url"; then
|
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
|
local latest_file
|
||||||
latest_file=$(grep -i "Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2" "$temp_dir/listing.html" | \
|
latest_file=$(grep -i "Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2" "$temp_dir/listing.html" | \
|
||||||
sort -r | head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
sort -r | head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
||||||
@@ -18,15 +18,15 @@ get_fedora_latest_rawhide_url() {
|
|||||||
if [[ -n "$latest_file" ]]; then
|
if [[ -n "$latest_file" ]]; then
|
||||||
echo "${base_url}${latest_file}"
|
echo "${base_url}${latest_file}"
|
||||||
else
|
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
|
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/')
|
head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
||||||
|
|
||||||
if [[ -n "$any_file" ]]; then
|
if [[ -n "$any_file" ]]; then
|
||||||
echo "${base_url}${any_file}"
|
echo "${base_url}${any_file}"
|
||||||
else
|
else
|
||||||
# Return empty string if we can't find any valid file
|
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -39,6 +39,24 @@ get_fedora_latest_rawhide_url() {
|
|||||||
rm -rf "$temp_dir"
|
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
|
# 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"
|
||||||
@@ -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"
|
"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
|
# Add Fedora image if we can get a valid URL AND no Fedora Rawhide image exists
|
||||||
FEDORA_URL=$(get_fedora_latest_rawhide_url)
|
FEDORA_EXISTS=$(check_fedora_rawhide_exists "/var/lib/libvirt/images")
|
||||||
if [[ -n "$FEDORA_URL" ]]; then
|
if [[ "$FEDORA_EXISTS" == "false" ]]; then
|
||||||
IMAGES+=("$FEDORA_URL")
|
FEDORA_URL=$(get_fedora_latest_rawhide_url)
|
||||||
|
if [[ -n "$FEDORA_URL" ]]; then
|
||||||
|
IMAGES+=("$FEDORA_URL")
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Target directory
|
# Target directory
|
||||||
Reference in New Issue
Block a user