2019-05-06 11:40:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# make.sh: Generate customized libvirt XML.
|
|
|
|
# by Foxlet <foxlet@furcode.co>
|
|
|
|
|
|
|
|
VMDIR=$PWD
|
2019-07-19 21:44:21 +02:00
|
|
|
MACHINE="$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | grep -Eoe ".*-[0-9.]+" | sort -rV | head -1)"
|
2020-11-14 17:22:20 +01:00
|
|
|
VMNAME="macOS-Simple-KVM"
|
|
|
|
VMUUID="d06d502a-904a-4b34-847d-debf1a3d76c7"
|
|
|
|
VMCPUS=4
|
|
|
|
VMMEM=2097152
|
2019-05-06 11:40:00 +02:00
|
|
|
OUT="template.xml"
|
|
|
|
|
|
|
|
print_usage() {
|
2019-06-07 01:36:52 +02:00
|
|
|
echo
|
|
|
|
echo "Usage: $0"
|
|
|
|
echo
|
2020-11-14 17:22:20 +01:00
|
|
|
echo " -a, --add Add XML to virsh (uses sudo)."
|
|
|
|
echo " -n, --name <str> Name of the VM (default 'macOS-Simple-KVM')"
|
|
|
|
echo " -u, --uuid Generates a new UUID for the VM"
|
|
|
|
echo " -c, --cpu <int> VM CPU count (default 4)"
|
|
|
|
echo " -m, --mem <int> VM memory in KiB (default 2097152)"
|
2019-06-07 01:36:52 +02:00
|
|
|
echo
|
2019-05-06 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
2019-07-19 21:44:21 +02:00
|
|
|
local error_message="$*"
|
2019-06-07 01:36:52 +02:00
|
|
|
echo "${error_message}" 1>&2;
|
2019-05-06 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
generate(){
|
2020-11-14 17:22:20 +01:00
|
|
|
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
|
2019-05-06 11:40:00 +02:00
|
|
|
echo "$OUT has been generated in $VMDIR"
|
|
|
|
}
|
|
|
|
|
2020-11-14 17:22:20 +01:00
|
|
|
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
|
|
|
|
|
2019-05-06 11:40:00 +02:00
|
|
|
generate
|
|
|
|
|
2020-11-14 17:22:20 +01:00
|
|
|
if [[ $ADD -eq 1 ]]; then
|
|
|
|
sudo virsh define $OUT
|
|
|
|
fi
|