mirror of
https://github.com/oSoWoSo/DistroHopper.git
synced 2024-08-14 22:46:53 +00:00
Refactor to improve stdout presentation
This commit is contained in:
parent
47da9ca28b
commit
79eb15e7c8
2 changed files with 49 additions and 35 deletions
|
@ -79,6 +79,6 @@ You can also pass optional parameters
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] Make display configuration more robust
|
- [x] Make display configuration more robust
|
||||||
- [ ] Improve stdout presentation
|
- [x] Improve stdout presentation
|
||||||
- [x] Make disk image optionally size configurable
|
- [x] Make disk image optionally size configurable
|
||||||
- [ ] Improve snapshot management
|
- [ ] Improve snapshot management
|
82
quickemu.sh
82
quickemu.sh
|
@ -3,7 +3,7 @@
|
||||||
function vm_delete() {
|
function vm_delete() {
|
||||||
if [ -f "${disk_img}" ]; then
|
if [ -f "${disk_img}" ]; then
|
||||||
rm "${disk_img}"
|
rm "${disk_img}"
|
||||||
echo "Deleted ${disk_img}"
|
echo "SUCCESS! Deleted ${disk_img}"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ function vm_restore() {
|
||||||
if [ -f "${disk_img_snapshot}" ]; then
|
if [ -f "${disk_img_snapshot}" ]; then
|
||||||
mv "${disk_img_snapshot}" "${disk_img}"
|
mv "${disk_img_snapshot}" "${disk_img}"
|
||||||
fi
|
fi
|
||||||
echo "Restored ${disk_img_snapshot}"
|
echo "SUCCESS! Restored ${disk_img_snapshot}"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,16 +20,45 @@ function vm_snapshot() {
|
||||||
if [ -f "${disk_img_snapshot}" ]; then
|
if [ -f "${disk_img_snapshot}" ]; then
|
||||||
mv "${disk_img_snapshot}" "${disk_img_snapshot}.old"
|
mv "${disk_img_snapshot}" "${disk_img_snapshot}.old"
|
||||||
fi
|
fi
|
||||||
qemu-img create -b "${disk_img}" -f qcow2 "${disk_img_snapshot}"
|
qemu-img create -b "${disk_img}" -f qcow2 "${disk_img_snapshot}" -q
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Created ${disk_img_snapshot}"
|
echo "SUCCESS! Created ${disk_img_snapshot}"
|
||||||
else
|
else
|
||||||
echo "Failed to create ${disk_img_snapshot}"
|
echo "ERROR! Failed to create ${disk_img_snapshot}"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function vm_boot() {
|
function vm_boot() {
|
||||||
|
local BIOS=""
|
||||||
|
if [ ${ENABLE_EFI} -eq 1 ]; then
|
||||||
|
if [ "${ENGINE}" == "virgil" ] && [ -e /snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd ] ; then
|
||||||
|
BIOS="-drive if=pflash,format=raw,readonly,file=/snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd"
|
||||||
|
elif [ -e /usr/share/qemu/OVMF.fd ]; then
|
||||||
|
BIOS="-drive if=pflash,format=raw,readonly,file=/usr/share/qemu/OVMF.fd"
|
||||||
|
else
|
||||||
|
echo " - EFI: Booting requested but no EFI firmware found."
|
||||||
|
echo " Booting from Legacy BIOS."
|
||||||
|
fi
|
||||||
|
echo " - BIOS: ${BIOS}"
|
||||||
|
else
|
||||||
|
echo " - BIOS: Legacy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " - Disk: ${disk_img}"
|
||||||
|
echo " - Size: ${disk}"
|
||||||
|
if [ ! -f "${disk_img}" ]; then
|
||||||
|
# If there is no disk image, create a new image.
|
||||||
|
qemu-img create -q -f qcow2 "${disk_img}" "${disk}"
|
||||||
|
echo " - ISO: ${iso}"
|
||||||
|
else
|
||||||
|
# If there is a disk image, do not boot from the iso
|
||||||
|
iso=""
|
||||||
|
fi
|
||||||
|
if [ -e ${disk_img_snapshot} ]; then
|
||||||
|
echo " - Snapshot: ${disk_img_snapshot}"
|
||||||
|
fi
|
||||||
|
|
||||||
local cores="1"
|
local cores="1"
|
||||||
local allcores=$(nproc --all)
|
local allcores=$(nproc --all)
|
||||||
if [ ${allcores} -ge 8 ]; then
|
if [ ${allcores} -ge 8 ]; then
|
||||||
|
@ -37,6 +66,7 @@ function vm_boot() {
|
||||||
elif [ ${allcores} -ge 4 ]; then
|
elif [ ${allcores} -ge 4 ]; then
|
||||||
cores="2"
|
cores="2"
|
||||||
fi
|
fi
|
||||||
|
echo " - CPU: ${cores} Core(s)"
|
||||||
|
|
||||||
local ram="2G"
|
local ram="2G"
|
||||||
local allram=$(free --mega -h | grep Mem | cut -d':' -f2 | cut -d'G' -f1 | sed 's/ //g')
|
local allram=$(free --mega -h | grep Mem | cut -d':' -f2 | cut -d'G' -f1 | sed 's/ //g')
|
||||||
|
@ -45,15 +75,7 @@ function vm_boot() {
|
||||||
elif [ ${allram} -ge 16 ]; then
|
elif [ ${allram} -ge 16 ]; then
|
||||||
ram="3G"
|
ram="3G"
|
||||||
fi
|
fi
|
||||||
|
echo " - RAM: ${ram}"
|
||||||
|
|
||||||
if [ ! -f "${disk_img}" ]; then
|
|
||||||
# If there is no disk image, create a new image.
|
|
||||||
qemu-img create -f qcow2 "${disk_img}" "${disk}"
|
|
||||||
else
|
|
||||||
# If there is a disk image, do not boot from the iso
|
|
||||||
iso=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Determine what display to use
|
# Determine what display to use
|
||||||
local display="-display gtk,grab-on-hover=on"
|
local display="-display gtk,grab-on-hover=on"
|
||||||
|
@ -88,17 +110,8 @@ function vm_boot() {
|
||||||
yres=648
|
yres=648
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local BIOS=""
|
if [ "${ENGINE}" == "virgil" ]; then
|
||||||
if [ ${ENABLE_EFI} -eq 1 ]; then
|
echo " - Monitor: ${xres}x${yres}"
|
||||||
if [ "${ENGINE}" == "virgil" ] && [ -e /snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd ] ; then
|
|
||||||
BIOS="-drive if=pflash,format=raw,readonly,file=/snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd"
|
|
||||||
elif [ -e /usr/share/qemu/OVMF.fd ]; then
|
|
||||||
BIOS="-drive if=pflash,format=raw,readonly,file=/usr/share/qemu/OVMF.fd"
|
|
||||||
else
|
|
||||||
echo "WARNING! EFI booting requested but no EFI firmware found."
|
|
||||||
echo " Booting from Legacy BIOS."
|
|
||||||
fi
|
|
||||||
echo "${BIOS}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local SAMBA=""
|
local SAMBA=""
|
||||||
|
@ -110,11 +123,12 @@ function vm_boot() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${SAMBA}" ]; then
|
if [ -n "${SAMBA}" ]; then
|
||||||
echo "NOTE! ${HOME} will be available on the guest via smb://10.0.2.4/qemu"
|
echo " - smbd: ${HOME} will be exported to the guest via smb://10.0.2.4/qemu"
|
||||||
else
|
else
|
||||||
echo "NOTE! %{HOME} will not be available in the guest. 'smbd' not found."
|
echo " - smbd: %{HOME} will not be exported to the guest. 'smbd' not found."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#echo " - QEMU: qemu-${ENGINE}"
|
||||||
# Boot the iso image
|
# Boot the iso image
|
||||||
qemu-${ENGINE} ${BIOS} \
|
qemu-${ENGINE} ${BIOS} \
|
||||||
-cdrom "${iso}" \
|
-cdrom "${iso}" \
|
||||||
|
@ -134,7 +148,7 @@ function vm_boot() {
|
||||||
-device qemu-xhci \
|
-device qemu-xhci \
|
||||||
-device virtio-vga,virgl=on,xres=${xres},yres=${yres} \
|
-device virtio-vga,virgl=on,xres=${xres},yres=${yres} \
|
||||||
${display} \
|
${display} \
|
||||||
"$@"
|
"$@" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
|
@ -190,19 +204,19 @@ while [ $# -gt 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "${VM}" ] || [ ! -e "${VM}" ]; then
|
if [ -n "${VM}" ] || [ -e "${VM}" ]; then
|
||||||
echo "ERROR! VM not found."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
source "${VM}"
|
source "${VM}"
|
||||||
|
echo Starting "${VM}"
|
||||||
if [ -n "${disk_img}" ]; then
|
if [ -n "${disk_img}" ]; then
|
||||||
disk_img_snapshot="${disk_img}.snapshot"
|
disk_img_snapshot="${disk_img}.snapshot"
|
||||||
echo "${disk_img}"
|
|
||||||
echo "${disk_img_snapshot}"
|
|
||||||
else
|
else
|
||||||
echo "ERROR! No disk_img defined."
|
echo "ERROR! No disk_img defined."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "ERROR! VM not found."
|
||||||
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${DELETE} -eq 1 ]; then
|
if [ ${DELETE} -eq 1 ]; then
|
||||||
|
|
Loading…
Reference in a new issue