From 2ce0a6b73520d4617b0d7cc2dfdd8fc7a8958311 Mon Sep 17 00:00:00 2001 From: Roger Sikorski Date: Sun, 5 Mar 2023 10:04:39 +0100 Subject: [PATCH] only download ubuntu.img if newer version exists Signed-off-by: Roger Sikorski --- ubuntu-lts.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ubuntu-lts.sh b/ubuntu-lts.sh index fc80c59..d4673a2 100755 --- a/ubuntu-lts.sh +++ b/ubuntu-lts.sh @@ -2,6 +2,10 @@ CURL_LAST_LTS_RELEASE=$(curl -s https://changelogs.ubuntu.com/meta-release-lts | grep Dist: | tail -n1) LAST_LTS_RELEASE=${CURL_LAST_LTS_RELEASE:6} +echo "" +echo "This script will download and setup an vm with the newest Ubuntu LTS Version ($LAST_LTS_RELEASE)" +echo "" + if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit @@ -13,21 +17,23 @@ if [ ! -f "ssh-keys.pub" ]; then exit fi +echo "Check and re-download Image $LAST_LTS_RELEASE-server-cloudimg-amd64.img if there is a newer img file" +wget -N "https://cloud-images.ubuntu.com/$LAST_LTS_RELEASE/current/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" -P /tmp/ + echo "Enter VM ID" read -r VM_ID echo "Enter VM Name" read -r VM_NAME -echo "Image download" -wget "https://cloud-images.ubuntu.com/$LAST_LTS_RELEASE/current/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" +echo "Ensure libguestfs-tools is installed" apt install libguestfs-tools -y echo "Install qemu-guest-agent on Ubuntu image" -virt-customize -a "$LAST_LTS_RELEASE-server-cloudimg-amd64.img" --install qemu-guest-agent +virt-customize -a "/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" --install qemu-guest-agent echo "Create Proxmox VM image from Ubuntu Cloud Image" qm create "$VM_ID" --memory 1024 --balloon 0 --cores 2 --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci -qm set "$VM_ID" --scsi0 local-lvm:0,import-from="$PWD/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" +qm set "$VM_ID" --scsi0 local-lvm:0,import-from="/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" qm set "$VM_ID" --agent enabled=1,fstrim_cloned_disks=1 echo "Create Cloud-Init Disk and configure boot" @@ -41,6 +47,3 @@ qm set "$VM_ID" \ --ciuser "devops" \ --sshkeys ssh-keys.pub \ --ipconfig0 "ip=dhcp,ip6=dhcp" - -echo "Delete downloaded image" -rm -f "$LAST_LTS_RELEASE-server-cloudimg-amd64.img"