From 41f56a1ad4a8067ba5bc6795e64e45c145406e20 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 12 Aug 2024 09:19:24 -0400 Subject: [PATCH] break stuff! --- install.sh | 98 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/install.sh b/install.sh index 493789e..4d45de9 100644 --- a/install.sh +++ b/install.sh @@ -3,13 +3,12 @@ set -e set +x -IMG_URL="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img" -IMG_NAME="noble-server-cloudimg-amd64.img" -VM_ID=8000 -VM_NAME=${2:-ubuntu-cloudinit2404} -MEMORY=2048 -CORES=2 -STORAGE=${1:-proxmox} +# Default Variables (Can be overridden with command-line arguments) +IMG_URL=${1:-"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"} +IMG_NAME=${2:-"noble-server-cloudimg-amd64.img"} +DISTRO=${3:-"ubuntu"} # Default to "ubuntu" +VERSION=${4:-"2404"} # Default to "2404" +STORAGE=${5:-"proxmox"} # Default to "proxmox" check_command() { if [ $? -ne 0 ]; then @@ -19,50 +18,67 @@ check_command() { } delete_existing_vm() { - if qm status $VM_ID &> /dev/null; then - echo "Deleting existing VM with ID $VM_ID..." - qm destroy $VM_ID --purge + local vm_id=$1 + if qm status $vm_id &> /dev/null; then + echo "Deleting existing VM with ID $vm_id..." + qm destroy $vm_id --purge check_command "Deleting existing VM" fi } -delete_existing_vm +create_vm() { + local vm_id=$1 + local vm_name=$2 + local memory=$3 -if [ -f "$IMG_NAME" ]; then - echo "Image file already exists at: $(realpath $IMG_NAME)" - echo "Skipping download..." -else - echo "Downloading Ubuntu Cloud Image..." - wget $IMG_URL -O $IMG_NAME - check_command "Downloading Ubuntu Cloud Image" -fi + delete_existing_vm $vm_id -echo "Creating a new virtual machine with name $VM_NAME..." -qm create $VM_ID --memory $MEMORY --core $CORES --name $VM_NAME --net0 virtio,bridge=vmbr0 -check_command "Creating virtual machine" + if [ -f "$IMG_NAME" ]; then + echo "Image file already exists at: $(realpath $IMG_NAME)" + echo "Skipping download..." + else + echo "Downloading cloud image..." + wget $IMG_URL -O $IMG_NAME + check_command "Downloading cloud image" + fi -echo "Importing the downloaded Ubuntu disk to storage ($STORAGE)..." -qm disk import $VM_ID $IMG_NAME $STORAGE -check_command "Importing disk to storage" + echo "Creating a new virtual machine with name $vm_name..." + qm create $vm_id --memory $memory --core 1 --name $vm_name --net0 virtio,bridge=vmbr0 + check_command "Creating virtual machine" -echo "Attaching the imported disk to the VM..." -qm set $VM_ID --scsihw virtio-scsi-pci --scsi0 proxmox:8000/vm-8000-disk-0.raw -check_command "Attaching disk to VM" + echo "Importing the downloaded cloud image disk to storage ($STORAGE)..." + qm disk import $vm_id $IMG_NAME $STORAGE + check_command "Importing disk to storage" -echo "Adding cloud init drive..." -qm set $VM_ID --ide2 $STORAGE:cloudinit -check_command "Adding cloud init drive" + echo "Attaching the imported disk to the VM..." + qm set $vm_id --scsihw virtio-scsi-pci --scsi0 ${STORAGE}:$vm_id/vm-$vm_id-disk-0.raw + check_command "Attaching disk to VM" -echo "Making cloud init drive bootable and restricting BIOS..." -qm set $VM_ID --boot c --bootdisk scsi0 -check_command "Setting boot options" + echo "Adding cloud init drive..." + qm set $vm_id --ide2 $STORAGE:cloudinit + check_command "Adding cloud init drive" -echo "Adding serial console..." -qm set $VM_ID --serial0 socket --vga serial0 -check_command "Adding serial console" + echo "Making cloud init drive bootable and restricting BIOS..." + qm set $vm_id --boot c --bootdisk scsi0 + check_command "Setting boot options" -echo "Suggested command for creating a template:" -echo "qm template $VM_ID" + echo "Adding serial console..." + qm set $vm_id --serial0 socket --vga serial0 + check_command "Adding serial console" -echo "Script completed successfully! Don't forget to create the template when you're ready with:" -echo "qm template $VM_ID" + echo "VM $vm_name ($vm_id) with $memory MB RAM created successfully!" + + echo "IMPORTANT: Before converting $vm_name to a template, do not forget to configure the cloud-init options." + echo "DO NOT boot the VM before setting the cloud-init options, as this will solidify the VM's hostname and other settings!" +} + +# Create VMs with different memory configurations + +create_vm 8100 "${DISTRO}-${VERSION}-512mb" 512 +create_vm 8101 "${DISTRO}-${VERSION}-1gb" 1024 +create_vm 8102 "${DISTRO}-${VERSION}-2gb" 2048 +create_vm 8103 "${DISTRO}-${VERSION}-4gb" 4096 +create_vm 8104 "${DISTRO}-${VERSION}-8gb" 8192 +create_vm 8105 "${DISTRO}-${VERSION}-12gb" 12288 + +echo "All VMs created successfully!"