Skip to contentSkip to conversation

arm-autonomy/xenguest: Fix issues raised by shellcheck

PATCH Applied Peter Hoyes 2 participants 2 messages Mar 1, 2021 – Mar 2, 2021

lore
Share & tools
lore
#0 lore raw

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

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
index 424fd0a..9776ddf 100755
@@ -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
index 3f87b76..e697f7e 100755
@@ -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
index c6b0c83..5862cb9 100755
@@ -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
index 2278b80..54b5a2f 100755
@@ -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
index ce5e6de..b63c6a2 100755
@@ -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
Applied
#1 lore raw
Quoted 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

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
index 424fd0a..9776ddf 100755
@@ -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
index 3f87b76..e697f7e 100755
@@ -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
index c6b0c83..5862cb9 100755
@@ -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
index 2278b80..54b5a2f 100755
@@ -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
index ce5e6de..b63c6a2 100755
@@ -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