#!/bin/bash
set -euo pipefail
: ${STORAGE:="blockbridge"}
: ${VMID:="2000"}
: ${MYDISK:="vm-$VMID-disk-0"}
: ${DEVICE:="scsi0"}
: ${NAME:="vm$VMID"}
: ${OSIMAGE:="cirros-0.5.1-x86_64-disk.img"}
ISO="/mnt/pve/bbnas/template/iso"
qm create $VMID --memory 512 --name $NAME --socket 1 --onboot no
qm importdisk $VMID $ISO/$OSIMAGE $STORAGE --format raw
qm set $VMID --scsihw virtio-scsi-pci --$DEVICE $STORAGE:$MYDISK
qm set $VMID -net0 virtio,bridge=vmbr0,firewall=1
qm set $VMID --ide2 $STORAGE:cloudinit
qm set $VMID --serial1 socket --vga serial1
qm set $VMID -args "-chardev file,id=char0,mux=on,path=/tmp/serial.$VMID.log,signal=off -serial chardev:char0"
qm set $VMID --boot c --bootdisk $DEVICE
qm set $VMID -ipconfig0 ip=dhcp
qm set $VMID --cipassword testpassword --ciuser ubuntu
qm set $VMID -sshkeys ~/.ssh/id_rsa.pub