fix: resolve shellcheck SC2002 and SC2207

https://www.shellcheck.net/wiki/SC2002
https://www.shellcheck.net/wiki/SC2207
This commit is contained in:
Martin Wimpress 2024-05-09 11:56:11 +01:00 committed by Martin Wimpress
parent 16adb86372
commit 013413ee8c
1 changed files with 21 additions and 19 deletions

View File

@ -1469,28 +1469,30 @@ function viewer_param_check() {
function parse_ports_from_file { function parse_ports_from_file {
local FILE="${VMDIR}/${VMNAME}.ports" local FILE="${VMDIR}/${VMNAME}.ports"
local host_name=""
local port_name=""
local port_number=""
# parse ports # Loop over each line in the file
# shellcheck disable=SC2207 while IFS= read -r CONF || [ -n "${CONF}" ]; do
local port_name=( $(cat "${FILE}" | cut -d',' -f 1) ) echo "Processing line: ${CONF}"
# shellcheck disable=SC2207 # parse ports
local port_number=( $(cat "${FILE}" | cut -d',' -f 2) ) port_name=$(echo "${CONF}" | cut -d',' -f 1)
# shellcheck disable=SC2207 port_number=$(echo "${CONF}" | cut -d',' -f 2)
local host_name=( $(cat "${FILE}" | gawk 'FS="," {print $3,"."}') ) host_name=$(echo "${CONF}" | awk 'FS="," {print $3,"."}')
for ((i=0; i<${#port_name[@]}; i++)); do if [ "${port_name}" == "ssh" ]; then
if [ "${port_name[$i]}" == "ssh" ]; then SSH_PORT="${port_number}"
SSH_PORT="${port_number[$i]}" elif [ "${port_name}" == "spice" ]; then
elif [ "${port_name[$i]}" == "spice" ]; then SPICE_PORT="${port_number}"
SPICE_PORT="${port_number[$i]}" elif [ "${port_name}" == "monitor-telnet" ]; then
elif [ "${port_name[$i]}" == "monitor-telnet" ]; then MONITOR_TELNET_PORT="${port_number}"
MONITOR_TELNET_PORT="${port_number[$i]}" MONITOR_TELNET_HOST="${host_name}"
MONITOR_TELNET_HOST="${host_name[$i]}" elif [ "${port_name}" == "serial-telnet" ]; then
elif [ "${port_name[$i]}" == "serial-telnet" ]; then SERIAL_TELNET_PORT="${port_number}"
SERIAL_TELNET_PORT="${port_number[$i]}" SERIAL_TELNET_HOST="${host_name}"
SERIAL_TELNET_HOST="${host_name[$i]}"
fi fi
done done < "${FILE}"
} }
function is_numeric { function is_numeric {