This repository was archived by the owner on Mar 14, 2021. It is now read-only.
forked from quickemu-project/quickemu
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyfastemu
More file actions
595 lines (537 loc) · 18.2 KB
/
myfastemu
File metadata and controls
595 lines (537 loc) · 18.2 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/usr/bin/env bash
export LC_ALL=C
function shortcut_delete() {
local SHORTCUT_DIR="/home/${USER}/.local/share/applications"
if [ -e ~/.local/share/applications/${VMNAME}.desktop ]; then
rm "${SHORTCUT_DIR}/${VMNAME}.desktop"
echo " - Deleted the desktop shortcut of the current VM."
fi
}
function shortcut_create() {
shortcut_delete
local filename="/home/${USER}/.local/share/applications/${VMNAME}.desktop"
cat << EOF > ${filename}
[Desktop Entry]
Name=${VMNAME}
Comment=Launch QEMU VM ${VMNAME}
Exec=${LAUNCHER_DIR}/${LAUNCHER} -vm ${LAUNCHER_DIR}/${VM}
Icon=${VIRGIL_PATH}/meta/gui/icon.png
Terminal=true
Type=Application
Version=1.0
EOF
echo " - Created a desktop shortcut for the current VM."
}
function snapshot_apply() {
local snapshot_tag="${1}"
if [ -z "${snapshot_tag}" ]; then
echo " - ERROR! No snapshot tag provided."
exit
fi
if [ -e "${disk_img}" ]; then
${QEMU_IMG} snapshot -q -a "${snapshot_tag}" "${disk_img}"
if [ $? -eq 0 ]; then
echo " - SUCCESS! Applied snapshot ${snapshot_tag} to ${disk_img}."
else
echo " - ERROR! Failed to apply snapshot ${snapshot_id} to ${disk_img}."
fi
else
echo " - ERROR! ${disk_img} not found. Doing nothing."
fi
}
function snapshot_create() {
local snapshot_tag="${1}"
if [ -z "${snapshot_tag}" ]; then
echo " - ERROR! No snapshot tag provided."
exit
fi
if [ -e "${disk_img}" ]; then
${QEMU_IMG} snapshot -q -c "${snapshot_tag}" "${disk_img}"
if [ $? -eq 0 ]; then
echo " - SUCCESS! Created snapshot ${snapshot_tag} of ${disk_img}."
else
echo " - ERROR! Failed to create snapshot ${snapshot_id} of ${disk_img}."
fi
else
echo " - ERROR! ${disk_img} not found. Doing nothing."
fi
}
function snapshot_delete() {
local snapshot_tag="${1}"
if [ -z "${snapshot_tag}" ]; then
echo " - ERROR! No snapshot tag provided."
exit
fi
if [ -e "${disk_img}" ]; then
${QEMU_IMG} snapshot -q -d "${snapshot_tag}" "${disk_img}"
if [ $? -eq 0 ]; then
echo " - SUCCESS! Deleted snapshot ${snapshot_tag} of ${disk_img}."
else
echo " - ERROR! Failed to delete snapshot ${snapshot_id} of ${disk_img}."
fi
else
echo " - ERROR! ${disk_img} not found. Doing nothing."
fi
}
function snapshot_info() {
if [ -e "${disk_img}" ]; then
${QEMU_IMG} info "${disk_img}"
fi
}
function get_port() {
local PORT_START=22220
local PORT_RANGE=9
while true; do
local CANDIDATE=$[${PORT_START} + (${RANDOM} % ${PORT_RANGE})]
(echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1
if [ $? -ne 0 ]; then
break
fi
done
}
function enable_usb_passthrough() {
local DEVICE=""
local USB_BUS=""
local USB_DEV=""
local USB_NAME=""
local VENDOR_ID=""
local PRODUCT_ID=""
local TEMP_SCRIPT=$(mktemp)
local EXEC_SCRIPT=0
# Have any USB devices been requested for pass-through?
if (( ${#usb_devices[@]} )); then
echo " - USB: Device pass-through requested:"
echo "#!/usr/bin/env bash" > "${TEMP_SCRIPT}"
for DEVICE in "${usb_devices[@]}"; do
VENDOR_ID=$(echo ${DEVICE} | cut -d':' -f1)
PRODUCT_ID=$(echo ${DEVICE} | cut -d':' -f2)
USB_BUS=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f2)
USB_DEV=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f4 | cut -d':' -f1)
USB_NAME=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f7-)
echo " - ${USB_NAME}"
USB_PASSTHROUGH="${USB_PASSTHROUGH} -device usb-host,vendorid=0x${VENDOR_ID},productid=0x${PRODUCT_ID},bus=xhci.0"
if [ ! -w /dev/bus/usb/${USB_BUS}/${USB_DEV} ]; then
local EXEC_SCRIPT=1
echo "chown root:${USER} /dev/bus/usb/${USB_BUS}/${USB_DEV}" >> "${TEMP_SCRIPT}"
fi
done
if [ ${EXEC_SCRIPT} -eq 1 ]; then
chmod +x "${TEMP_SCRIPT}"
echo " - Requested USB device(s) are NOT accessible."
echo " - ${TEMP_SCRIPT} will be executed to enable access:"
echo
cat ${TEMP_SCRIPT}
echo
sudo "${TEMP_SCRIPT}"
if [ $? -ne 0 ]; then
echo " - WARNING! Enabling USB device access failed."
fi
else
echo " - Requested USB device(s) are accessible."
fi
rm -f "${TEMP_SCRIPT}"
fi
}
function vm_boot() {
echo
echo " ----------------------------------------------------------------------"
echo " |--aaaaaa--aaa-aaaa-||||||--MyFastEmulator--||||||-aaaaaa--aaa-aaaa--|"
echo " |--a-aa-a--a---aaa--||||||--MyFastEmulator--||||||-a-aa-a--a---aaa---|"
echo " |--a-aa-a--aa--aaa--||||||--MyFastEmulator--||||||-a-aa-a--aa--aaa---|"
echo " |--a----a--a---aaaa-|||||||----------------|||||||-a----a--a---aaaa--|"
echo " -------------------------||| Loading... |||-------------------------"
echo
local VMDIR=""
if [ -f "${disk_img}" ]; then
VMDIR=$(dirname "${disk_img}")
fi
local BIOS=""
local GL="on"
local VIRGL="off"
local UI="gtk"
local QEMU_VER=$(${QEMU} -version | head -n1 | cut -d' ' -f4 | cut -d'(' -f1)
echo " - Initializing \"${VM}\"'s settings."
echo " - QEMU: ${QEMU} v${QEMU_VER}"
# Fix KVM "permission denied" error (https://bugzilla.redhat.com/show_bug.cgi?id=1479558)
# Comment this line if you don't have any error related to this.
# sudo chown $USER /dev/kvm | OR | sudo chmod 666 /dev/kvm | OR | sudo chmod 777 -R /dev/kvm
if [ ! -z "${guest_ui}" ]; then
UI="${guest_ui}"
echo " - UI: ${UI} (choosed by user)"
else
echo " - UI: ${UI}"
fi
local output_extra=""
if [ "${UI}" == "gtk" ]; then
output_extra=",grab-on-hover=on,zoom-to-fit=on"
if [ "${GL}" == "on" ]; then
echo " - GTK UI is currently not compatible with GL. Turning GL off."
GL="off"
fi
fi
if [ "${UI}" == "spice-app" ] && [ "${GL}" == "on" ]; then
echo " - spice-app UI is currently not compatible with GL. Turning GL off."
GL="off"
fi
if [ ! -z "${guest_gl}" ]; then
GL="${guest_gl}"
echo " - GL: ${GL} (choosed by user)"
else
echo " - GL: ${GL}"
fi
if [ ! -z "${guest_virgl}" ]; then
VIRGL="${guest_virgl}"
echo " - VIRGL (Virgil3D): ${VIRGL} (choosed by user)"
else
echo " - VIRGL (Virgil3D): ${VIRGL}"
fi
local EFI_VARS=""
if [ ! -z "${efi_bios}" ] && [ "${efi_bios}" -eq 1 ]; then
if [ -e "${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd" ] ; then
local EFI_CODE="${VIRGIL_PATH}/usr/share/qemu/edk2-x86_64-code.fd"
EFI_VARS="${VMNAME}-vars.fd"
if [ ! -e "${EFI_VARS}" ]; then
cp "${VIRGIL_PATH}/usr/share/qemu/edk2-i386-vars.fd" "${EFI_VARS}"
fi
BIOS="-drive if=pflash,format=raw,readonly,file=${EFI_CODE} -drive if=pflash,format=raw,file=${EFI_VARS}"
echo " - BIOS: EFI"
else
echo " - BIOS: Booting requested from EFI but no EFI firmware found. Booting from Legacy BIOS."
fi
else
echo " - BIOS: Legacy"
fi
local hdd=""
local hdd2=""
# Has the no hdd option been requested?
if [ ! -z "${no_hdd}" ] && [ "${no_hdd}" -eq 1 ]; then
echo " - No HDD option has been enabled, no hdd will be created."
else
if [ ! -f "${disk_img}" ]; then
# If there is no disk image, create a new image.
touch "${disk_img}"
${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}"
if [ $? -ne 0 ]; then
echo " - ERROR! Failed to create ${disk_img} of ${disk}. Stopping here."
exit 1
fi
echo " - Just created a new image, booting from ${iso}."
if [ -z "${disk}" ]; then
echo " - Disk size not found, setting default value."
disk="64G"
fi
else
# Check if there isn't already a process attached to the disk image.
QEMU_LOCK_TEST=$(${QEMU_IMG} info "${disk_img}" 2>/dev/null)
if [ $? -ne 0 ]; then
echo " - Failed to get \"write\" lock. Is another process using the disk?"
exit 1
fi
local disk_curr_size=$(stat -c%s "${disk_img}")
if [ ! ${disk_curr_size} -le ${DISK_MIN_SIZE} ]; then
# If there is a disk image AND there is an install on it, do not boot from the iso
iso=""
else
if [ -z "${iso}" ]; then
echo " - ERROR! You haven't specified an ISO image to boot from."
exit 1
fi
fi
fi
# This line is for VirtIO disk support.
# hdd="-drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file=${disk_img} -device virtio-blk-pci,drive=drive0,scsi=off"
if [ ! -z ${emulate_disk_aio} ]; then
hdd="-drive if=none,id=drive0,cache=directsync,aio=${emulate_disk_aio},format=qcow2,file=${disk_img} -device ahci,id=ahci -device ide-hd,drive=drive0,bus=ahci.0"
echo " - Disk: ${disk_img} (${disk}). I/O is ${emulate_disk_aio} (choosed by user)."
else
hdd="-drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file=${disk_img} -device ahci,id=ahci -device ide-hd,drive=drive0,bus=ahci.0"
echo " - Disk: ${disk_img} (${disk}). I/O is native."
fi
fi
if [ ! -z ${disk_img_snapshot} ]; then
echo " - Snapshot: ${disk_img_snapshot}"
fi
# Has the status QUO option been requested?
if [ ! -z ${status_quo} ] && [ ${status_quo} -eq 1 ]; then
STATUSQUO="-snapshot"
echo " - Status QUO option has been enabled, no changes to the disk/snapshot will be made."
fi
# Check if there is a boot ISO
if [ -n "${iso}" ] && [ -e "${iso}" ]; then
echo " - Boot ISO: ${iso}"
iso="-drive media=cdrom,file="${iso}",index=0"
fi
# Check if there is a second ISO
if [ -n "${second_iso}" ] && [ -e "${second_iso}" ]; then
echo " - Second ISO: ${second_iso}"
second_iso="-drive media=cdrom,file="${second_iso}",index=1"
fi
# Since we can have more cores than the host CPU, let's just put all
# the host's CPU cores by default
local cores=$(nproc --all)
if [ ! -z "${total_cores}" ]; then
cores="${total_cores}"
echo " - CPU Cores: ${cores} Core(s) (choosed by user)"
else
echo " - CPU Cores: ${cores} Core(s)"
fi
local ccpu="host"
if [ ! -z "${emulated_cpu}" ]; then
ccpu="${emulated_cpu}"
echo " - Emulated CPU: ${ccpu} (choosed by user)"
else
echo " - Emulated CPU: ${ccpu}"
fi
ccpu="-cpu ${ccpu},kvm=on"
local guest_tweaks=""
local vga_adapter="virtio-vga"
if [ ! -z ${system_optimization} ]; then
if [ ${system_optimization} -eq 1 ]; then
echo " - Windows optimization option enabled. Lemme optimize it real quick!"
guest_tweaks=",hv_time -no-hpet -no-fd-bootchk"
vga_adapter="qxl-vga"
elif [ ${system_optimization} -eq 2 ]; then
echo " - Mac OS optimization option enabled. Lemme optimize it real quick!"
echo " - WARNING! This feature might not work as expected yet."
ccpu="-cpu Penryn,vendor=GenuineIntel,kvm=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc"
guest_tweaks=" -device isa-applesmc,osk=\"ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc\""
else
echo " - Linux optimization option enabled. No optimization needed!"
fi
else
echo " - No optimization option enabled."
fi
if [ ! -z ${force_classic_vga} ] && [ ${force_classic_vga} -eq 1 ]; then
vga_adapter="VGA"
fi
local ram="2G"
local host_ram=$(free --mega -h | grep Mem | cut -d':' -f2 | cut -d'G' -f1 | sed 's/ //g')
# Round up : https://github.com/wimpysworld/quickemu/issues/11
host_ram=$(printf '%.*f\n' 0 ${host_ram})
if [ ${host_ram} -ge 64 ] || [ ${host_ram} -ge 32 ]; then
ram="16G"
elif [ ${host_ram} -ge 16 ] || [ ${host_ram} -ge 8 ]; then
ram="4G"
fi
if [ ! -z "${ram_gb}" ]; then
ram="${ram_gb}"
echo " - RAM: ${ram} (choosed by user)"
else
echo " - RAM: ${ram}"
fi
local xres=1152
local yres=648
if [ "${XDG_SESSION_TYPE}" == "x11" ]; then
local LOWEST_WIDTH=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f1 | sort | head -n1)
if [ ${LOWEST_WIDTH} -ge 3840 ]; then
xres=3200
yres=1800
elif [ ${LOWEST_WIDTH} -ge 2560 ]; then
xres=2048
yres=1152
elif [ ${LOWEST_WIDTH} -ge 1920 ]; then
xres=1664
yres=936
elif [ ${LOWEST_WIDTH} -ge 1280 ]; then
xres=1152
yres=648
fi
fi
# Guest's max screen resolution
if [ ! -z "${guest_xres}" ]; then
xres=${guest_xres}
echo " - Width resolution: ${xres} (choosed by user)"
else
echo " - Width resolution: ${xres}"
fi
if [ ! -z "${guest_yres}" ]; then
yres=${guest_yres}
echo " - Height resolution: ${yres} (choosed by user)"
else
echo " - Height resolution: ${yres}"
fi
# Determine what display to use
local display=""
if [ "${vga_adapter}" == "virtio-vga" ]; then
display="-device ${vga_adapter},virgl=${VIRGL},xres=${xres},yres=${yres}"
echo " - Video: ${vga_adapter}"
elif [ "${vga_adapter}" == "qxl-vga" ]; then
echo " - Warning : ${vga_adapter} will have no support for VirGL."
display="-device ${vga_adapter},xres=${xres},yres=${yres}"
echo " - Video: ${vga_adapter}"
else
echo " - Warning : ${vga_adapter} will have no support for VirGL."
display="-device ${vga_adapter},vgamem_mb=${vga_memory},xres=${xres},yres=${yres}"
echo " - Video: ${vga_adapter} with ${vga_memory} MB (choosed by user)"
fi
# Set the hostname of the VM
local NET="user,hostname=${VMNAME}"
# If smbd is available, export $HOME to the guest via samba
if [ -e "${VIRGIL_PATH}/usr/sbin/smbd" ]; then
NET="${NET},smb=${HOME}"
fi
if [[ ${NET} == *"smb"* ]]; then
echo " - smbd: ${HOME} will be exported to the guest via smb://10.0.2.4/qemu"
else
echo " - smbd: ${HOME} will not be exported to the guest. \"smbd\" not found."
fi
# Find a free port to expose ssh to the guest
local PORT=$(get_port)
if [ -n "${PORT}" ]; then
NET="${NET},hostfwd=tcp::${PORT}-:22"
echo " - ssh: ${PORT}/tcp is connected. Login via 'ssh user@localhost -p ${PORT}'"
else
echo " - ssh: All ports for exposing ssh have been exhausted."
fi
# Has virtualization been requested?
local virtualization=""
if [ ! -z "${enable_iommu}" ]; then
if [ "${enable_iommu}" -eq 1 ]; then
virtualization="-device intel-iommu"
else
virtualization="-device amd-iommu"
fi
fi
enable_usb_passthrough
# Boot the VM
echo " - Launching \"${VM}\" with requested settings."
${QEMU} \
-name ${VMNAME},process=${VMNAME} \
-enable-kvm -accel kvm,thread=multi -machine q35,vmport=off,kernel_irqchip=on ${BIOS} \
-smbios type=2,manufacturer=AnErrupTion,product=MyFastEmulator \
${ccpu}${guest_tweaks} -smp cores=${cores} \
-m ${ram} -device virtio-balloon \
${hdd} ${STATUSQUO} \
${iso} ${second_iso} \
${display} -display ${UI},gl=${GL}${output_extra} \
-usb -device qemu-xhci,id=xhci,p2=8,p3=8 ${USB_PASSTHROUGH} \
-device virtio-keyboard -device virtio-tablet \
-device rtl8139,netdev=nic -netdev ${NET},id=nic \
-audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \
-device intel-hda -device hda-duplex,audiodev=pa,mixer=off \
-rtc base=localtime,clock=host \
-object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0 \
${virtualization} -show-cursor -seed $(($RANDOM * $RANDOM)) \
-spice port=5930,disable-ticketing,gl=${GL} \
-device virtio-serial-pci \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-chardev spicevmc,id=spicechannel0,name=vdagent \
"$@"
echo " - The VM has been shut down."
if [ -e "${EFI_VARS}" ]; then
rm "${EFI_VARS}"
fi
}
function usage() {
echo
echo "Usage"
echo " ${LAUNCHER} --vm CONFIG_FILE.conf"
echo
echo "You can also pass optional parameters :"
echo " --delete : Delete the desktop shortcut."
echo " --shortcut : Create a desktop shortcut."
echo " --snapshot apply <tag> : Apply/restore a snapshot."
echo " --snapshot create <tag> : Create a snapshot."
echo " --snapshot delete <tag> : Delete a snapshot."
echo " --snapshot info : Show disk/snapshot info."
exit 1
}
readonly QEMU="/snap/bin/qemu-virgil"
readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img"
readonly LAUNCHER=$(basename "${0}")
readonly DISK_MIN_SIZE=$((197632 * 8))
readonly VIRGIL_PATH="/snap/qemu-virgil/current"
readonly LAUNCHER_DIR="$(dirname "$(realpath "$0")")"
VMNAME=""
SNAPSHOT_ACTION=""
SNAPSHOT_TAG=""
SNAPSHOT=0
STATUSQUO=""
USB_PASSTHROUGH=""
VM=""
SHORTCUT=0
DELETE=0
while [ $# -gt 0 ]; do
case "${1}" in
-snapshot|--snapshot)
SNAPSHOT_ACTION="${2}"
if [ -z "${SNAPSHOT_ACTION}" ]; then
echo " - ERROR! No snapshot action provided."
exit 1
fi
shift
SNAPSHOT_TAG="${2}"
if [ -z "${SNAPSHOT_TAG}" ] && [ "${SNAPSHOT_ACTION}" != "info" ]; then
echo " - ERROR! No snapshot tag provided."
exit 1
fi
SNAPSHOT=1
shift
shift;;
-vm|--vm)
VM="${2}"
VMNAME=$(basename "${VM}" .conf)
shift
shift;;
-shortcut|--shortcut)
SHORTCUT=1
shift;;
-delete|--delete)
DELETE=1
shift;;
-h|--h|-help|--help)
usage;;
*)
echo " - ERROR! \"${1}\" is not a supported parameter."
usage;;
esac
done
# Check we have qemu-virgil available
if [ ! -e "${QEMU}" ] && [ ! -e "${QEMU_IMG}" ]; then
echo " - ERROR! qemu-virgil not found. Please install the qemu-virgil snap."
echo " https://snapcraft.io/qemu-virgil"
exit 1
fi
if [ -n "${VM}" ] && [ -e "${VM}" ]; then
source "${VM}"
if [ -z "${disk_img}" ] && [ -f "${no_hdd}" ]; then
echo " - ERROR! No disk_img defined."
exit 1
fi
else
echo " - ERROR! Virtual machine configuration not found."
usage
fi
if [ ${SNAPSHOT} -eq 1 ]; then
if [ -n "${SNAPSHOT_ACTION}" ]; then
case ${SNAPSHOT_ACTION} in
apply)
snapshot_apply "${SNAPSHOT_TAG}"
snapshot_info
exit;;
create)
snapshot_create "${SNAPSHOT_TAG}"
snapshot_info
exit;;
delete)
snapshot_delete "${SNAPSHOT_TAG}"
snapshot_info
exit;;
info)
snapshot_info
exit;;
*)
echo " - ERROR! \"${SNAPSHOT_ACTION}\" is not a supported snapshot action."
usage;;
esac
fi
fi
if [ ${DELETE} -eq 1 ]; then
shortcut_delete
exit
fi
if [ ${SHORTCUT} -eq 1 ]; then
shortcut_create
exit
fi
vm_boot