Created
February 20, 2024 10:11
-
-
Save karubits/56a9f3d509723ebaf24c4aa19a7a648c to your computer and use it in GitHub Desktop.
Download cloud images in bulk to host on a file server for ingestion with proxmox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define target directory for downloading and storing cloud images | |
TARGET_DIRECTORY="/opt/firmware/cloud-images" | |
mkdir -p "$TARGET_DIRECTORY" | |
# Array of Debian releases and their cloud image URLs | |
declare -A debian_releases=( | |
["debian-buster"]="https://cloud.debian.org/images/cloud/buster/latest/debian-10-genericcloud-amd64.qcow2 SHA512" | |
["debian-buster-backports"]="https://cloud.debian.org/images/cloud/buster-backports/latest/debian-10-backports-genericcloud-amd64.qcow2 SHA512" | |
["debian-bullseye"]="https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 SHA512" | |
["debian-bullseye-backports"]="https://cloud.debian.org/images/cloud/bullseye-backports/latest/debian-11-backports-genericcloud-amd64.qcow2 SHA512" | |
["debian-bookworm"]="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2 SHA512" | |
["debian-bookworm-backports"]="https://cloud.debian.org/images/cloud/bookworm-backports/latest/debian-12-backports-genericcloud-amd64.qcow2 SHA512" | |
["ubuntu-bionic"]="https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img SHA256" | |
["ubuntu-focal"]="https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-disk-kvm.img SHA256" | |
["ubuntu-jammy"]="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img SHA256" | |
) | |
# Loop through the Debian releases to download images and verify checksums | |
for release in "${!debian_releases[@]}"; do | |
echo -e "\033[1;35m----------------------------------------\033[0m" | |
echo -e "\033[1;32mπ Processing $release...\033[0m" | |
# Split the URL and checksum type | |
IFS=' ' read -r IMAGE_URL CHECKSUM_TYPE <<< "${debian_releases[$release]}" | |
CHECKSUM_URL="${IMAGE_URL%/*}/${CHECKSUM_TYPE}SUMS" # Construct checksum URL | |
IMAGE_FILE="$TARGET_DIRECTORY/$(basename "$IMAGE_URL")" | |
CHECKSUM_FILE="$IMAGE_FILE.$CHECKSUM_TYPE" # Name checksum file based on type | |
# Download the cloud image | |
echo -e "\033[1;34mπ₯ Downloading $release image...\033[0m" | |
wget -q --show-progress --progress=bar:force -O "$IMAGE_FILE" "$IMAGE_URL" | |
# Download the checksum file | |
echo -e "\033[1;34mπ Downloading checksum file for $release...\033[0m" | |
wget -q --show-progress --progress=bar:force -q -O "$CHECKSUM_FILE" "$CHECKSUM_URL" | |
# Verify the checksum | |
echo -e "\033[1;33mπ Verifying checksum for $release...\033[0m" | |
cd "$TARGET_DIRECTORY" | |
if [[ "$CHECKSUM_TYPE" == "SHA256" ]]; then | |
CHECKSUM_COMMAND="shasum -a 256" | |
else | |
CHECKSUM_COMMAND="shasum -a 512" | |
fi | |
$CHECKSUM_COMMAND -c <(grep $(basename "$IMAGE_URL") "$CHECKSUM_FILE") --ignore-missing | |
if [ $? -eq 0 ]; then | |
echo -e "\033[1;32mβ $release image verified successfully.\033[0m" | |
else | |
echo -e "\033[1;31mβ Checksum verification failed for $release. Exiting script.\033[0m" | |
exit 1 | |
fi | |
# Install required packages using virt-customize | |
echo -e "\033[1;36mπ¦ Installing packages on $release image...\033[0m" | |
sudo virt-customize -a "$IMAGE_FILE" --install qemu-guest-agent,ca-certificates,apt-transport-https,net-tools,lnav,wget,curl,dnsutils | |
echo -e "\033[1;32mπ Packages installed successfully on $release image.\033[0m" | |
done | |
echo -e "\033[1;35m----------------------------------------\033[0m" | |
echo -e "\033[1;32mπ All processes completed successfully.\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment