commit b578fe559f75f3033b2729295d0ac8d759a133d8 Author: root Date: Sat Jan 20 21:58:38 2024 +0200 1 diff --git a/create-proxmox-cloudinit-images.sh b/create-proxmox-cloudinit-images.sh new file mode 100755 index 0000000..b1f41d3 --- /dev/null +++ b/create-proxmox-cloudinit-images.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +function createImage() { + + IMAGE_FILE_URL="$1" + IMAGE_ID="$2" + IMAGE_FILE="$3" + IMAGE_NAME="$4" + IMAGE_RAM="$5" + IMAGE_CORES="$6" + IMAGE_STORE="$7" + IMAGE_TYPE="$8" + + stat "${IMAGE_FILE}" + if [ "$?" -gt "0" ] + then + wget "${IMAGE_FILE_URL}" -O "${IMAGE_FILE}" + + apt update + apt install -y libguestfs-tools + case "${IMAGE_TYPE}" in + deb*|ubuntu*) + virt-customize -a ${IMAGE_FILE} --install qemu-guest-agent + ;; + alma*|rhel*|centos*) + virt-customize -a ${IMAGE_FILE} --install qemu-guest-agent + ;; + *) + echo "Unknown OS type" + ;; + esac + fi + + qm create ${IMAGE_ID} --name "${IMAGE_NAME}" --memory ${IMAGE_RAM} --cores ${IMAGE_CORES} \ + --net0 virtio,bridge=vmbr0 + qm importdisk ${IMAGE_ID} ${IMAGE_FILE} ${IMAGE_STORE} + qm set ${IMAGE_ID} --scsihw virtio-scsi-pci --scsi0 ${IMAGE_STORE}:vm-9000-disk-0 + qm set ${IMAGE_ID} --boot c --bootdisk scsi0 + qm set ${IMAGE_ID} --ide2 ${IMAGE_STORE}:cloudinit + qm set ${IMAGE_ID} --serial0 socket --vga serial0 + qm set ${IMAGE_ID} --agent enabled=1 + + rm -vf "${IMAGE_FILE}" +} + + +function getDownloadSpeed() { + local url="$1" + local duration=10 # Set the duration for the download test (in seconds) + local speed=$(curl -o /dev/null -s -w '%{speed_download}\n' --max-time $duration "$url") + + echo "$speed" +} + + +LOCAL_STORE="$( head -1 store-name)" + +if [ -z "${LOCAL_STORE}" ] +then + echo "Missing proxmox vm store name" + exit 1 +else + echo "Using proxmox vm store: ${LOCAL_STORE}" +fi + +USE_LOCAL_IMAGES="0" + +## Debian 12 (BookWorm) +DEBIAN_12_IMAGE_URL="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2" +DEBIAN_12_LOCAL_IMAGE_URL="https://www.ngtech.co.il/static/cloud-images/debian-12-generic-amd64.qcow2" + +DEBIAN_12_TEMPLATE_ID="9000" +DEBIAN_12_IMAGE_FILENAME="debian-12.qcow2" +DEBIAN_12_TEMPLATE_NAME="debian-12-cloudinit-template" +DEBIAN_12_TEMPLATE_RAM="2048" +DEBIAN_12_TEMPLATE_CORES="2" +DEBIAN_12_TEMPLATE_STORE="${LOCAL_STORE}" + +## Download Speed test comparison between debian and local mirror +REMOTE_DOWNLOAD_SPEED=$(getDownloadSpeed "${DEBIAN_12_IMAGE_URL}" ) +LOCAL_DOWNLOAD_SPEED=$(getDownloadSpeed "${DEBIAN_12_LOCAL_IMAGE_URL}" ) + +echo "${REMOTE_DOWNLOAD_SPEED}" +echo "${LOCAL_DOWNLOAD_SPEED}" + +if [ "${LOCAL_DOWNLOAD_SPEED}" -gt "${REMOTE_DOWNLOAD_SPEED}" ]; +then + USE_LOCAL_IMAGES="1" +fi + +if [ "${USE_LOCAL_IMAGES}" -eq "1" ] +then + DEBIAN_12_IMAGE_URL="${DEBIAN_12_LOCAL_IMAGE_URL}" +fi + +createImage "${DEBIAN_12_IMAGE_URL}" "${DEBIAN_12_TEMPLATE_ID}" \ + "${DEBIAN_12_IMAGE_FILENAME}" "${DEBIAN_12_TEMPLATE_NAME}" \ + "${DEBIAN_12_TEMPLATE_RAM}" "${DEBIAN_12_TEMPLATE_CORES}" "${DEBIAN_12_TEMPLATE_STORE}" "deb" + + +## AlmaLinux 8 +ALMA_8_IMAGE_URL="https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2" +ALMA_8_LOCAL_IMAGE_URL="https://www.ngtech.co.il/static/cloud-images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2" +ALMA_8_TEMPLATE_ID="9001" +ALMA_8_IMAGE_FILENAME="alma-8.qcow2" +ALMA_8_TEMPLATE_NAME="alma-8-cloudinit-template" +ALMA_8_TEMPLATE_RAM="2048" +ALMA_8_TEMPLATE_CORES="2" +ALMA_8_TEMPLATE_STORE="${LOCAL_STORE}" + +if [ "${USE_LOCAL_IMAGES}" -eq "1" ] +then + ALMA_8_IMAGE_URL="${ALMA_8_LOCAL_IMAGE_URL}" +fi + +createImage "${ALMA_8_IMAGE_URL}" "${ALMA_8_TEMPLATE_ID}" \ + "${ALMA_8_IMAGE_FILENAME}" "${ALMA_8_TEMPLATE_NAME}" \ + "${ALMA_8_TEMPLATE_RAM}" "${ALMA_8_TEMPLATE_CORES}" "${ALMA_8_TEMPLATE_STORE}" "alma" + + +## AlmaLinux 9 +ALMA_9_IMAGE_URL="https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2" +ALMA_9_LOCAL_IMAGE_URL="https://www.ngtech.co.il/static/cloud-images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2" +ALMA_9_TEMPLATE_ID="9002" +ALMA_9_IMAGE_FILENAME="alma-9.qcow2" +ALMA_9_TEMPLATE_NAME="alma-9-cloudinit-template" +ALMA_9_TEMPLATE_RAM="2048" +ALMA_9_TEMPLATE_CORES="2" +ALMA_9_TEMPLATE_STORE="${LOCAL_STORE}" + +if [ "${USE_LOCAL_IMAGES}" -eq "1" ] +then + ALMA_9_IMAGE_URL="${ALMA_9_LOCAL_IMAGE_URL}" +fi + +createImage "${ALMA_9_IMAGE_URL}" "${ALMA_9_TEMPLATE_ID}" \ + "${ALMA_9_IMAGE_FILENAME}" "${ALMA_9_TEMPLATE_NAME}" \ + "${ALMA_9_TEMPLATE_RAM}" "${ALMA_9_TEMPLATE_CORES}" "${ALMA_9_TEMPLATE_STORE}" "alma" + + +## Ubuntu 22.04 +UBUNTU_2204_IMAGE_URL="https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64-disk-kvm.img" +UBUNTU_2204_LOCAL_IMAGE_URL="https://www.ngtech.co.il/static/cloud-images/ubuntu-22.04-server-cloudimg-amd64-disk-kvm.img" +UBUNTU_2204_TEMPLATE_ID="9003" +UBUNTU_2204_IMAGE_FILENAME="ubuntu-2204.qcow2" +UBUNTU_2204_TEMPLATE_NAME="ubuntu-2204-cloudinit-template" +UBUNTU_2204_TEMPLATE_RAM="2048" +UBUNTU_2204_TEMPLATE_CORES="2" +UBUNTU_2204_TEMPLATE_STORE="${LOCAL_STORE}" + +if [ "${USE_LOCAL_IMAGES}" -eq "1" ] +then + UBUNTU_2204_IMAGE_URL="${UBUNTU_2204_LOCAL_IMAGE_URL}" +fi + +createImage "${UBUNTU_2204_IMAGE_URL}" "${UBUNTU_2204_TEMPLATE_ID}" \ + "${UBUNTU_2204_IMAGE_FILENAME}" "${UBUNTU_2204_TEMPLATE_NAME}" \ + "${UBUNTU_2204_TEMPLATE_RAM}" "${UBUNTU_2204_TEMPLATE_CORES}" "${UBUNTU_2204_TEMPLATE_STORE}" "alma" + + diff --git a/store-name b/store-name new file mode 100644 index 0000000..38bb706 --- /dev/null +++ b/store-name @@ -0,0 +1 @@ +local-lvm