-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-script-gen
executable file
·76 lines (69 loc) · 2.08 KB
/
vm-script-gen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
SCRIPT_NAME="vm-script-gen"
AURTHOR="Neo_Chen <[email protected]>"
LICENSE="GPLv3 or Newer"
# usage() is important
usage()
{
cat <<EOF
Usage: $SCRIPT_NAME [-ah] [-n Name] [-c cputype] [-m mem] [-d file] [-s num] [-b bridge] [-e file] [-o file] [-v vga]
-n VM Name
-v Be Verbose
-c CPU type
-m Memory (in MiB)
-d Disk File (QCOW2 format)
-s Number of CPUs
-b Bridge Interface to use (If not specified, we use user network)
-e Enable EFI, and specify where the ROM is
-q QEMU
-a Enable Audio
EOF
}
# Get command line aruguments
while getopts "hn:c:m:d:s:b:r:e:q:v:a" OPTION ; do
case $OPTION in
h) usage
exit 1;;
o) OUTFILE=$OPTARG;;
v) flag="${flag}"
VGA="$OPTARG";;
n) flag="${flag}n"
NAME="$OPTARG";;
c) flag="${flag}c"
CPU="$OPTARG";;
m) flag="${flag}m"
MEM="$OPTARG";;
s) flag="${flag}s"
SMP="$OPTARG";;
d) flag="${flag}d"
DISK="$OPTARG";;
b) flag="${flag}b"
BRIDGE="$OPTARG";;
e) flag="${flag}e"
EFI="$OPTARG";;
q) flag="${flag}q"
QEMU="$OPTARG";;
a) flag="${flag}a";;
*) echo "${SCRIPT_NAME}: Invaild argument: ${OPTARG}"
exit 8;;
esac
done
[[ "$flag" == *q* ]] && echo "nice -n 19 chrt -vi 0 ${QEMU} -accel kvm -balloon virtio \\" || echo "nice -n 19 chrt -vi 0 qemu-system-x86_64 -accel kvm -balloon virtio \\"
[[ "$flag" == *n* ]] && echo "-name ${NAME} \\"
[[ "$flag" == *c* ]] && echo "-cpu ${CPU} \\" || echo "-cpu host \\"
[[ "$flag" == *m* ]] && echo "-m ${MEM} \\" || echo "-m 512M \\"
[[ "$flag" == *s* ]] && echo "-smp ${SMP} \\"
[[ "$flag" == *d* ]] && echo "-blockdev driver=qcow2,node-name=hda,discard=unmap,cache.direct=on,detect-zeroes=unmap,file.driver=file,file.filename=\"${DISK}\" \\" && \
echo '-device virtio-blk-pci,drive=hda \'
[[ "$flag" == *b* ]] && echo "-net nic,model=virtio -net bridge,br=${BRIDGE} \\"
[[ "$flag" == *e* ]] && echo "-pflash ${EFI} \\"
if [[ "$flag" == *v* ]] ;then
if [[ "$VGA" == "virtio" ]] ; then
echo '-device virtio-vga,virgl=on -display sdl,gl=on \'
else
echo "-vga ${VGA} \\"
fi
fi
[[ "$flag" == *a* ]] && echo "-soundhw hda \\"
echo '"$@"'
# vim: set tabstop=8:softtabstop=8:shiftwidth=8