break stuff!
This commit is contained in:
		
							parent
							
								
									759ecac565
								
							
						
					
					
						commit
						41f56a1ad4
					
				
							
								
								
									
										98
									
								
								install.sh
								
								
								
								
							
							
						
						
									
										98
									
								
								install.sh
								
								
								
								
							|  | @ -3,13 +3,12 @@ | ||||||
| set -e | set -e | ||||||
| set +x | set +x | ||||||
| 
 | 
 | ||||||
| IMG_URL="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img" | # Default Variables (Can be overridden with command-line arguments) | ||||||
| IMG_NAME="noble-server-cloudimg-amd64.img" | IMG_URL=${1:-"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"} | ||||||
| VM_ID=8000 | IMG_NAME=${2:-"noble-server-cloudimg-amd64.img"} | ||||||
| VM_NAME=${2:-ubuntu-cloudinit2404} | DISTRO=${3:-"ubuntu"}  # Default to "ubuntu" | ||||||
| MEMORY=2048 | VERSION=${4:-"2404"}    # Default to "2404" | ||||||
| CORES=2 | STORAGE=${5:-"proxmox"} # Default to "proxmox" | ||||||
| STORAGE=${1:-proxmox} |  | ||||||
| 
 | 
 | ||||||
| check_command() { | check_command() { | ||||||
|     if [ $? -ne 0 ]; then |     if [ $? -ne 0 ]; then | ||||||
|  | @ -19,50 +18,67 @@ check_command() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| delete_existing_vm() { | delete_existing_vm() { | ||||||
|     if qm status $VM_ID &> /dev/null; then |     local vm_id=$1 | ||||||
|         echo "Deleting existing VM with ID $VM_ID..." |     if qm status $vm_id &> /dev/null; then | ||||||
|         qm destroy $VM_ID --purge |         echo "Deleting existing VM with ID $vm_id..." | ||||||
|  |         qm destroy $vm_id --purge | ||||||
|         check_command "Deleting existing VM" |         check_command "Deleting existing VM" | ||||||
|     fi |     fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| delete_existing_vm | create_vm() { | ||||||
|  |     local vm_id=$1 | ||||||
|  |     local vm_name=$2 | ||||||
|  |     local memory=$3 | ||||||
| 
 | 
 | ||||||
| if [ -f "$IMG_NAME" ]; then |     delete_existing_vm $vm_id | ||||||
|     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 |  | ||||||
| 
 | 
 | ||||||
| echo "Creating a new virtual machine with name $VM_NAME..." |     if [ -f "$IMG_NAME" ]; then | ||||||
| qm create $VM_ID --memory $MEMORY --core $CORES --name $VM_NAME --net0 virtio,bridge=vmbr0 |         echo "Image file already exists at: $(realpath $IMG_NAME)" | ||||||
| check_command "Creating virtual machine" |         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)..." |     echo "Creating a new virtual machine with name $vm_name..." | ||||||
| qm disk import $VM_ID $IMG_NAME $STORAGE |     qm create $vm_id --memory $memory --core 1 --name $vm_name --net0 virtio,bridge=vmbr0 | ||||||
| check_command "Importing disk to storage" |     check_command "Creating virtual machine" | ||||||
| 
 | 
 | ||||||
| echo "Attaching the imported disk to the VM..." |     echo "Importing the downloaded cloud image disk to storage ($STORAGE)..." | ||||||
| qm set $VM_ID --scsihw virtio-scsi-pci --scsi0 proxmox:8000/vm-8000-disk-0.raw |     qm disk import $vm_id $IMG_NAME $STORAGE | ||||||
| check_command "Attaching disk to VM" |     check_command "Importing disk to storage" | ||||||
| 
 | 
 | ||||||
| echo "Adding cloud init drive..." |     echo "Attaching the imported disk to the VM..." | ||||||
| qm set $VM_ID --ide2 $STORAGE:cloudinit |     qm set $vm_id --scsihw virtio-scsi-pci --scsi0 ${STORAGE}:$vm_id/vm-$vm_id-disk-0.raw | ||||||
| check_command "Adding cloud init drive" |     check_command "Attaching disk to VM" | ||||||
| 
 | 
 | ||||||
| echo "Making cloud init drive bootable and restricting BIOS..." |     echo "Adding cloud init drive..." | ||||||
| qm set $VM_ID --boot c --bootdisk scsi0 |     qm set $vm_id --ide2 $STORAGE:cloudinit | ||||||
| check_command "Setting boot options" |     check_command "Adding cloud init drive" | ||||||
| 
 | 
 | ||||||
| echo "Adding serial console..." |     echo "Making cloud init drive bootable and restricting BIOS..." | ||||||
| qm set $VM_ID --serial0 socket --vga serial0 |     qm set $vm_id --boot c --bootdisk scsi0 | ||||||
| check_command "Adding serial console" |     check_command "Setting boot options" | ||||||
| 
 | 
 | ||||||
| echo "Suggested command for creating a template:" |     echo "Adding serial console..." | ||||||
| echo "qm template $VM_ID" |     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 "VM $vm_name ($vm_id) with $memory MB RAM created successfully!" | ||||||
| echo "qm template $VM_ID" | 
 | ||||||
|  |     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!" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue