1
0
Fork 0
mirror of https://github.com/foxlet/macOS-Simple-KVM.git synced 2024-11-24 03:59:41 +01:00
macOS-Simple-KVM/make.sh
2020-06-23 10:23:46 +02:00

39 lines
813 B
Bash
Executable file

#!/bin/bash
# make.sh: Generate customized libvirt XML.
# by Foxlet <foxlet@furcode.co>
VMDIR=$PWD
MACHINE="$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | grep -Eoe ".*-[0-9.]+" | sort -rV | head -1)"
OUT="template.xml"
print_usage() {
echo
echo "Usage: $0"
echo
echo " -a, --add Add XML to virsh (uses sudo)."
echo
}
error() {
local error_message="$*"
echo "${error_message}" 1>&2;
}
generate(){
UUID=$( cat /proc/sys/kernel/random/uuid )
sed -e "s|VMDIR|$VMDIR|g" -e "s|UUID|$UUID|g" -e "s|MACHINE|$MACHINE|g" tools/template.xml.in > $OUT
echo "$OUT has been generated in $VMDIR"
}
generate
argument="$1"
case $argument in
-a|--add)
virsh -c qemu:///session define $OUT
;;
-h|--help)
print_usage
;;
esac