From 9047a51ca1166c74ecbd5c660fc39f8ca45ea5e7 Mon Sep 17 00:00:00 2001 From: George Cave Date: Sat, 14 Nov 2020 11:22:20 -0500 Subject: [PATCH] [TOOLS] More options for defining VM templates The make script now contains more command-line options when generating the VM template, including defining a different name, fresh UUID, and CPU/memory count. --- make.sh | 57 ++++++++++++++++++++++++++++++++++--------- tools/template.xml.in | 8 +++--- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/make.sh b/make.sh index 8495561..6a23447 100755 --- a/make.sh +++ b/make.sh @@ -5,13 +5,21 @@ VMDIR=$PWD MACHINE="$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | grep -Eoe ".*-[0-9.]+" | sort -rV | head -1)" +VMNAME="macOS-Simple-KVM" +VMUUID="d06d502a-904a-4b34-847d-debf1a3d76c7" +VMCPUS=4 +VMMEM=2097152 OUT="template.xml" print_usage() { echo echo "Usage: $0" echo - echo " -a, --add Add XML to virsh (uses sudo)." + echo " -a, --add Add XML to virsh (uses sudo)." + echo " -n, --name Name of the VM (default 'macOS-Simple-KVM')" + echo " -u, --uuid Generates a new UUID for the VM" + echo " -c, --cpu VM CPU count (default 4)" + echo " -m, --mem VM memory in KiB (default 2097152)" echo } @@ -21,18 +29,45 @@ error() { } generate(){ - sed -e "s|VMDIR|$VMDIR|g" -e "s|MACHINE|$MACHINE|g" tools/template.xml.in > $OUT + sed -e "s|macOS-Simple-KVM|$VMNAME|g" -e "s|d06d502a-904a-4b34-847d-debf1a3d76c7|$VMUUID|g" -e "s|VMCPUS|$VMCPUS|g" -e "s|VMMEM|$VMMEM|g" -e "s|VMDIR|$VMDIR|g" -e "s|MACHINE|$MACHINE|g" tools/template.xml.in > $OUT echo "$OUT has been generated in $VMDIR" } +while [[ $# -gt 0 ]]; do + argument="$1" + case $argument in + -a|--add) + ADD=1 + shift + ;; + -n|--name) + VMNAME="$2" + shift + shift + ;; + -u|--uuid) + VMUUID="$(uuidgen)" + shift + ;; + -c|--cpu) + VMCPUS=$2 + shift + shift + ;; + -m|--mem) + VMMEM=$2 + shift + shift + ;; + -h|--help) + print_usage + shift + ;; + esac +done + generate -argument="$1" -case $argument in - -a|--add) - sudo virsh define $OUT - ;; - -h|--help) - print_usage - ;; -esac +if [[ $ADD -eq 1 ]]; then + sudo virsh define $OUT +fi \ No newline at end of file diff --git a/tools/template.xml.in b/tools/template.xml.in index 321552f..9f7a68d 100644 --- a/tools/template.xml.in +++ b/tools/template.xml.in @@ -1,9 +1,9 @@ macOS-Simple-KVM d06d502a-904a-4b34-847d-debf1a3d76c7 - 2097152 - 2097152 - 4 + VMMEM + VMMEM + VMCPUS hvm VMDIR/firmware/OVMF_CODE.fd @@ -16,7 +16,7 @@ - +