Skip to content

Commit

Permalink
fix: quickemu shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
zen0bit committed Apr 14, 2024
1 parent b966993 commit a747d58
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions quickemu
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
#shellcheck disable=SC2054,SC2140
export LC_ALL=C

if ((BASH_VERSINFO[0] < 4)); then
Expand Down Expand Up @@ -962,7 +963,7 @@ function vm_boot() {

# Only enable SPICE is using SPICE display
if [ "${OUTPUT}" == "none" ] || [ "${OUTPUT}" == "spice" ] || [ "${OUTPUT}" == "spice-app" ]; then
args+=(-spice ${SPICE}
args+=(-spice "${SPICE}"
-device virtio-serial-pci
-chardev socket,id=agent0,path="${VMDIR}/${VMNAME}-agent.sock",server=on,wait=off
-device virtserialport,chardev=agent0,name=org.qemu.guest_agent.0
Expand All @@ -974,7 +975,7 @@ function vm_boot() {

args+=(-device virtio-rng-pci,rng=rng0
-object rng-random,id=rng0,filename=/dev/urandom
-device ${USB_HOST_PASSTHROUGH_CONTROLLER},id=spicepass
-device "${USB_HOST_PASSTHROUGH_CONTROLLER}",id=spicepass
-chardev spicevmc,id=usbredirchardev1,name=usbredir
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1
-chardev spicevmc,id=usbredirchardev2,name=usbredir
Expand Down Expand Up @@ -1023,7 +1024,7 @@ function vm_boot() {
# @INFO: When using the VNC display, you must use the -k parameter to set the keyboard layout if you are not using en-us.
[ -z "${KEYBOARD_LAYOUT}" ] && KEYBOARD_LAYOUT="$keyboard_layout"
if [ -n "${KEYBOARD_LAYOUT}" ]; then
args+=(-k ${KEYBOARD_LAYOUT})
args+=(-k "${KEYBOARD_LAYOUT}")
fi

# FIXME: Check for device availability. qemu will fail to start otherwise
Expand Down Expand Up @@ -1159,8 +1160,7 @@ function vm_boot() {
args+=(-drive if=ide,index=0,media=disk,file="${disk_img}")

elif [ "${guest_os}" == "windows-server" ]; then
args+=(-device ide-hd,drive=SystemDisk
-drive id=SystemDisk,if=none,format=qcow2,file="${disk_img}" ${STATUS_QUO})
mapfile -t args < <(echo "-device ide-hd,drive=SystemDisk" "-drive id=SystemDisk,if=none,format=qcow2,file=${disk_img}" ${STATUS_QUO})

else
# shellcheck disable=SC2054,SC2206
Expand Down Expand Up @@ -1209,17 +1209,18 @@ function vm_boot() {
echo " - Monitor: (off)"
elif [ "${MONITOR}" == "telnet" ]; then
# Find a free port to expose monitor-telnet to the guest
local temp_port="$(get_port ${MONITOR_TELNET_PORT} 9)"
local temp_port=""
temp_port="$(get_port "${MONITOR_TELNET_PORT}" 9)"
if [ -z "${temp_port}" ]; then
echo " - Monitor: All Monitor-Telnet ports have been exhausted."
else
MONITOR_TELNET_PORT="${temp_port}"
args+=(-monitor telnet:${MONITOR_TELNET_HOST}:${MONITOR_TELNET_PORT},server,nowait)
args+=(-monitor telnet:"${MONITOR_TELNET_HOST}":"${MONITOR_TELNET_PORT}",server,nowait)
echo " - Monitor: On host: telnet ${MONITOR_TELNET_HOST} ${MONITOR_TELNET_PORT}"
echo "monitor-telnet,${MONITOR_TELNET_PORT},${MONITOR_TELNET_HOST}" >> "${VMDIR}/${VMNAME}.ports"
fi
elif [ "${MONITOR}" == "socket" ]; then
args+=(-monitor unix:${VM_MONITOR_SOCKETPATH},server,nowait)
args+=(-monitor unix:"${VM_MONITOR_SOCKETPATH}",server,nowait)
echo " - Monitor: On host: nc -U \"${VM_MONITOR_SOCKETPATH}\""
echo " or : socat -,echo=0,icanon=0 unix-connect:${VM_MONITOR_SOCKETPATH}"
else
Expand All @@ -1246,17 +1247,18 @@ function vm_boot() {
args+=(-serial none)
elif [ "${SERIAL}" == "telnet" ]; then
# Find a free port to expose serial-telnet to the guest
local temp_port="$(get_port ${SERIAL_TELNET_PORT} 9)"
local temp_port=""
temp_port="$(get_port "${SERIAL_TELNET_PORT}" 9)"
if [ -z "${temp_port}" ]; then
echo " - Serial: All Serial-Telnet ports have been exhausted."
else
SERIAL_TELNET_PORT="${temp_port}"
args+=(-serial telnet:${SERIAL_TELNET_HOST}:${SERIAL_TELNET_PORT},server,nowait)
args+=(-serial telnet:"${SERIAL_TELNET_HOST}":"${SERIAL_TELNET_PORT}",server,nowait)
echo " - Serial: On host: telnet ${SERIAL_TELNET_HOST} ${SERIAL_TELNET_PORT}"
echo "serial-telnet,${SERIAL_TELNET_PORT},${SERIAL_TELNET_HOST}" >> "${VMDIR}/${VMNAME}.ports"
fi
elif [ "${SERIAL}" == "socket" ]; then
args+=(-serial unix:${VM_SERIAL_SOCKETPATH},server,nowait)
args+=(-serial unix:"${VM_SERIAL_SOCKETPATH}",server,nowait)
echo " - Serial: On host: nc -U \"${VM_SERIAL_SOCKETPATH}\""
echo " or : socat -,echo=0,icanon=0 unix-connect:${VM_SERIAL_SOCKETPATH}"
else
Expand All @@ -1267,8 +1269,12 @@ function vm_boot() {
if [ -z "${EXTRA_ARGS}" ]; then
EXTRA_ARGS="${extra_args}"
fi
#if [ -n "${EXTRA_ARGS}" ]; then
# args+=(${EXTRA_ARGS})
#fi
if [ -n "${EXTRA_ARGS}" ]; then
args+=(${EXTRA_ARGS})
mapfile -t extra_args_array < <(echo "${EXTRA_ARGS}")
args+=("${extra_args_array[@]}")
fi

# The OSK parameter contains parenthesis, they need to be escaped in the shell
Expand Down Expand Up @@ -1428,9 +1434,9 @@ function parse_ports_from_file {
local FILE="${VMDIR}/${VMNAME}.ports"

# parse ports
local port_name=( $(cat "$FILE" | cut -d, -f1) )
local port_number=( $(cat "$FILE" | cut -d, -f2) )
local host_name=( $(cat "$FILE" | gawk 'FS="," {print $3,"."}') )
local port_name=( "$(cat "$FILE" | cut -d, -f1)" )
local port_number=( "$(cat "$FILE" | cut -d, -f2)" )
local host_name=( "$(cat "$FILE" | gawk 'FS="," {print $3,"."}')" )

for ((i=0; i<${#port_name[@]}; i++)); do
if [ "${port_name[$i]}" == "ssh" ]; then
Expand Down Expand Up @@ -1784,7 +1790,7 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
VM_MONITOR_SOCKETPATH="${VMDIR}/${VMNAME}-monitor.socket"
VM_SERIAL_SOCKETPATH="${VMDIR}/${VMNAME}-serial.socket"
if [ ! -f "${disk_img}" ]; then
cd "${VMPATH}"
cd "${VMPATH}" || echo "ERROR: VM path not exist!"
fi

# Backwards compatibility for ${driver_iso}
Expand Down

0 comments on commit a747d58

Please sign in to comment.