79 lines
2.5 KiB
Bash
Executable File
79 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Image URLs
|
|
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"
|
|
"https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2"
|
|
"https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
|
"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"
|
|
)
|
|
|
|
# Target directory
|
|
TARGET_DIR="/var/lib/libvirt/images"
|
|
|
|
# Main script execution
|
|
main() {
|
|
# Check if we have write permissions to the target directory
|
|
if [[ ! -w "$TARGET_DIR" ]]; then
|
|
# Check if we're already running as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script requires write access to $TARGET_DIR"
|
|
echo "Re-executing with sudo..."
|
|
exec sudo "$0" "$@"
|
|
else
|
|
echo "Error: Cannot write to $TARGET_DIR even with sudo privileges."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Download all images
|
|
echo "Starting download of all images..."
|
|
echo ""
|
|
|
|
local success_count=0
|
|
local failure_count=0
|
|
|
|
for url in "${IMAGES[@]}"; do
|
|
local filename
|
|
filename=$(basename "$url")
|
|
local filepath="$TARGET_DIR/$filename"
|
|
|
|
if [[ -f "$filepath" ]]; then
|
|
echo "Image $filename already exists, skipping..."
|
|
((success_count++))
|
|
continue
|
|
fi
|
|
|
|
echo "Downloading $filename..."
|
|
|
|
# Use wget with progress and retry options
|
|
if ! wget -P "$TARGET_DIR" --progress=bar:force:noscroll -c "$url"; then
|
|
echo "Failed to download $filename"
|
|
((failure_count++))
|
|
else
|
|
echo "Download completed: $filename"
|
|
((success_count++))
|
|
fi
|
|
done
|
|
|
|
# Summary
|
|
echo ""
|
|
echo "Download summary:"
|
|
echo "Successful downloads: $success_count"
|
|
echo "Failed downloads: $failure_count"
|
|
|
|
if [[ $failure_count -gt 0 ]]; then
|
|
echo "Some downloads failed. Check above messages for details."
|
|
exit 1
|
|
else
|
|
echo "All images downloaded successfully!"
|
|
fi
|
|
}
|
|
|
|
# Run main function if script is executed directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi
|