arm-autonomy/xenguest: Fix issues raised by shellcheck
PATCH 1/1 arm-autonomy/xenguest: Fix issues raised by shellcheck
From: Peter Hoyes <[email protected]>
Ignore issues in xenguest-manager and xenguest-mkimage as these will soon be rewritten.
Issue-Id: SCM-1526
Signed-off-by Peter Hoyes <[email protected]>
Change-Id I733b4bfaaa5002f7a64c577e16548af62c425ebf
--- .../xenguest/files/kea-restore-default-config | 2 +- .../xenguest/files/network-bridge.sh.in | 4 ++-- .../xenguest/files/xenguest-init | 22 +++++++++---------- .../xenguest/files/xenguest-network-bridge.in | 2 +- .../files/xenguest-network-init-post.sh | 11 +++++----- 5 files changed, 21 insertions(+), 20 deletions(-)
meta-arm-autonomy/recipes-extended/xenguest/files/kea-restore-default-config +1 -1
@@ -22,7 +22,7 @@ case "$1" in *) # do not advertise unreasonable commands that there is no reason # to use with this device - echo $"Usage: $0 {start|stop|status|restart|force-reload}" + echo "Usage: $0 {start|stop|status|restart|force-reload}" exit 1 esac
meta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in +2 -2
@@ -10,11 +10,11 @@ BRIDGE_NAME="###BRIDGE_NAME###" case "${XENGUEST_NETWORK_TYPE:=}" in nat) - echo "vif = ['script=vif-nat']" >> ${guestcfgfile} + echo "vif = ['script=vif-nat']" >> "${guestcfgfile:?}" log info "Network type is NAT" ;; bridge) - echo "vif = ['script=vif-bridge,bridge=${BRIDGE_NAME}']" >> ${guestcfgfile} + echo "vif = ['script=vif-bridge,bridge=${BRIDGE_NAME}']" >> "${guestcfgfile:?}" log info "Network type is bridge: ${BRIDGE_NAME}" ;; *)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-init +11 -11
@@ -25,19 +25,19 @@ case "$1" in echo "Starting xenguest" # Create unconfigured guests - if [ -d ${XENGUEST_GUEST_DIR} ]; then - for f in $(find ${XENGUEST_GUEST_DIR} -name "*.xenguest" \ - -exec basename {} .xenguest \;); do - if [ ! -f ${XENGUEST_CONF_BASE}/guests/${f}/guest.cfg ]; then + if [ -d "${XENGUEST_GUEST_DIR}" ]; then + shopt -s nullglob + for path in "${XENGUEST_GUEST_DIR}"/*.xenguest; do + f=$(basename "${path}" .xenguest) + if [ ! -f "${XENGUEST_CONF_BASE}/guests/${f}/guest.cfg" ]; then # Check if this guest should be auto booted autoboot=$(/usr/bin/xenguest-mkimage dump-paramsconfig \ - ${XENGUEST_GUEST_DIR}/${f}.xenguest | \ + "${path}" | \ grep GUEST_AUTOBOOT | sed -e "s,.*=,," | tr -d '"') if [ "$autoboot" = "0" ]; then echo "Do not create $f, autoboot disabled" else - /usr/bin/xenguest-manager create \ - ${XENGUEST_GUEST_DIR}/${f}.xenguest + /usr/bin/xenguest-manager create "${path}" # Update guestlist if [ $? -eq 0 ]; then guestlist="${guestlist} ${f}"
@@ -49,11 +49,11 @@ case "$1" in if [ -n "${guestlist}" ]; then for f in ${guestlist}; do GUEST_AUTOBOOT="1" - if [ -f ${XENGUEST_CONF_BASE}/guests/${f}/params.cfg ]; then - source ${XENGUEST_CONF_BASE}/guests/${f}/params.cfg + if [ -f "${XENGUEST_CONF_BASE}/guests/${f}/params.cfg" ]; then + source "${XENGUEST_CONF_BASE}/guests/${f}/params.cfg" fi if [ "${GUEST_AUTOBOOT}" = "1" ]; then - /usr/bin/xenguest-manager start ${f} + /usr/bin/xenguest-manager start "${f}" fi done else
@@ -68,7 +68,7 @@ case "$1" in # update guest list guestlist=$(xenguest-manager status | grep Running | cut -d ":" -f1) for f in ${guestlist}; do - xenguest-manager shutdown ${f} --kill + xenguest-manager shutdown "${f}" --kill done ;; reload)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in +1 -1
@@ -36,7 +36,7 @@ case "$1" in *) # do not advertise unreasonable commands that there is no reason # to use with this device - echo $"Usage: $0 {start|stop|status|restart|force-reload}" + echo "Usage: $0 {start|stop|status|restart|force-reload}" exit 1 esac
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-init-post.sh +6 -5
@@ -11,19 +11,20 @@ set +u # check_if_vif_is_ready() { - ret=($(xl network-list "${guestname}" | grep "${1}")) - # ${ret[4]} is network interface status value + ret=$(xl network-list "${guestname:?}" | grep "${1}" \ + | tr -s ' ' | cut -d' ' -f5) + # ${ret} is network interface status value # 1 means vif is not ready # 4 means vif is ready - [ "${ret[4]}" = "4" ] && return 0 + [ "${ret}" = "4" ] && return 0 return 1 } case "${XENGUEST_NETWORK_TYPE:-}" in nat) - vif_name="$(xl network-list ${guestname} | grep -o vif.*)" + vif_name="$(xl network-list "${guestname:?}" | grep -o "vif.*")" - for try in {1..20} + for try in $(seq 20) do if check_if_vif_is_ready "${vif_name}"; then claim_lock "vif-nat-kea"
Signature · 1 line
2.25.1
Jon Mason
AppliedQuoted 9 lines · Peter Hoyes
From: Peter Hoyes <[email protected]>
Ignore issues in xenguest-manager and xenguest-mkimage as these will soon be rewritten.
Issue-Id: SCM-1526
Signed-off-by Peter Hoyes <[email protected]>Change-Id I733b4bfaaa5002f7a64c577e16548af62c425ebf---
Applied to master.
Thanks,
Jon
Quoted 143 lines
.../xenguest/files/kea-restore-default-config | 2 +- .../xenguest/files/network-bridge.sh.in | 4 ++-- .../xenguest/files/xenguest-init | 22 +++++++++---------- .../xenguest/files/xenguest-network-bridge.in | 2 +- .../files/xenguest-network-init-post.sh | 11 +++++----- 5 files changed, 21 insertions(+), 20 deletions(-)meta-arm-autonomy/recipes-extended/xenguest/files/kea-restore-default-config +1
-1@@ -22,7 +22,7 @@ case "$1" in *) # do not advertise unreasonable commands that there is no reason # to use with this device - echo $"Usage: $0 {start|stop|status|restart|force-reload}" + echo "Usage: $0 {start|stop|status|restart|force-reload}" exit 1 esacmeta-arm-autonomy/recipes-extended/xenguest/files/network-bridge.sh.in +2
-2@@ -10,11 +10,11 @@ BRIDGE_NAME="###BRIDGE_NAME###" case "${XENGUEST_NETWORK_TYPE:=}" in nat) - echo "vif = ['script=vif-nat']" >> ${guestcfgfile} + echo "vif = ['script=vif-nat']" >> "${guestcfgfile:?}" log info "Network type is NAT" ;; bridge) - echo "vif = ['script=vif-bridge,bridge=${BRIDGE_NAME}']" >> ${guestcfgfile} + echo "vif = ['script=vif-bridge,bridge=${BRIDGE_NAME}']" >> "${guestcfgfile:?}" log info "Network type is bridge: ${BRIDGE_NAME}" ;; *)meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-init +11
-11@@ -25,19 +25,19 @@ case "$1" in echo "Starting xenguest" # Create unconfigured guests - if [ -d ${XENGUEST_GUEST_DIR} ]; then - for f in $(find ${XENGUEST_GUEST_DIR} -name "*.xenguest" \ - -exec basename {} .xenguest \;); do - if [ ! -f ${XENGUEST_CONF_BASE}/guests/${f}/guest.cfg ]; then + if [ -d "${XENGUEST_GUEST_DIR}" ]; then + shopt -s nullglob + for path in "${XENGUEST_GUEST_DIR}"/*.xenguest; do + f=$(basename "${path}" .xenguest) + if [ ! -f "${XENGUEST_CONF_BASE}/guests/${f}/guest.cfg" ]; then # Check if this guest should be auto booted autoboot=$(/usr/bin/xenguest-mkimage dump-paramsconfig \ - ${XENGUEST_GUEST_DIR}/${f}.xenguest | \ + "${path}" | \ grep GUEST_AUTOBOOT | sed -e "s,.*=,," | tr -d '"') if [ "$autoboot" = "0" ]; then echo "Do not create $f, autoboot disabled" else - /usr/bin/xenguest-manager create \ - ${XENGUEST_GUEST_DIR}/${f}.xenguest + /usr/bin/xenguest-manager create "${path}" # Update guestlist if [ $? -eq 0 ]; then guestlist="${guestlist} ${f}"@@ -49,11 +49,11 @@ case "$1" in if [ -n "${guestlist}" ]; then for f in ${guestlist}; do GUEST_AUTOBOOT="1" - if [ -f ${XENGUEST_CONF_BASE}/guests/${f}/params.cfg ]; then - source ${XENGUEST_CONF_BASE}/guests/${f}/params.cfg + if [ -f "${XENGUEST_CONF_BASE}/guests/${f}/params.cfg" ]; then + source "${XENGUEST_CONF_BASE}/guests/${f}/params.cfg" fi if [ "${GUEST_AUTOBOOT}" = "1" ]; then - /usr/bin/xenguest-manager start ${f} + /usr/bin/xenguest-manager start "${f}" fi done else@@ -68,7 +68,7 @@ case "$1" in # update guest list guestlist=$(xenguest-manager status | grep Running | cut -d ":" -f1) for f in ${guestlist}; do - xenguest-manager shutdown ${f} --kill + xenguest-manager shutdown "${f}" --kill done ;; reload)meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-bridge.in +1
-1@@ -36,7 +36,7 @@ case "$1" in *) # do not advertise unreasonable commands that there is no reason # to use with this device - echo $"Usage: $0 {start|stop|status|restart|force-reload}" + echo "Usage: $0 {start|stop|status|restart|force-reload}" exit 1 esacmeta-arm-autonomy/recipes-extended/xenguest/files/xenguest-network-init-post.sh +6
-5@@ -11,19 +11,20 @@ set +u # check_if_vif_is_ready() { - ret=($(xl network-list "${guestname}" | grep "${1}")) - # ${ret[4]} is network interface status value + ret=$(xl network-list "${guestname:?}" | grep "${1}" \ + | tr -s ' ' | cut -d' ' -f5) + # ${ret} is network interface status value # 1 means vif is not ready # 4 means vif is ready - [ "${ret[4]}" = "4" ] && return 0 + [ "${ret}" = "4" ] && return 0 return 1 } case "${XENGUEST_NETWORK_TYPE:-}" in nat) - vif_name="$(xl network-list ${guestname} | grep -o vif.*)" + vif_name="$(xl network-list "${guestname:?}" | grep -o "vif.*")" - for try in {1..20} + for try in $(seq 20) do if check_if_vif_is_ready "${vif_name}"; then claim_lock "vif-nat-kea"Signature · 1 line
2.25.1