2019-05-06 11:40:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# make.sh: Generate customized libvirt XML.
|
|
|
|
# by Foxlet <foxlet@furcode.co>
|
|
|
|
|
|
|
|
VMDIR=$PWD
|
2019-06-21 20:29:30 +02:00
|
|
|
MACHINE=$(qemu-system-x86_64 --machine help | grep q35 | cut -d" " -f1 | egrep -oe ".*-[0-9.]+" | sort -rV | head -1)
|
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
|
|
|
|
echo " -a, --add Add XML to virsh (uses sudo)."
|
|
|
|
echo
|
2019-05-06 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
2019-06-07 01:36:52 +02:00
|
|
|
local error_message="$@"
|
|
|
|
echo "${error_message}" 1>&2;
|
2019-05-06 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
generate(){
|
2019-06-21 20:29:30 +02:00
|
|
|
sed -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"
|
|
|
|
}
|
|
|
|
|
|
|
|
generate
|
|
|
|
|
|
|
|
argument="$1"
|
|
|
|
case $argument in
|
|
|
|
-a|--add)
|
|
|
|
sudo virsh define $OUT
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
print_usage
|
|
|
|
;;
|
|
|
|
esac
|