meta-google: gbmc-ip-monitor: Fix shellcheck issues

Change-Id: I3bcdbb94553a8d3f181ccb109a99bf2e2a4dfe2b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh b/meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh
index 7c39f59..c5e82d3 100755
--- a/meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh
+++ b/meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+# shellcheck disable=SC2317
 # Copyright 2021 Google LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,13 +14,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-cd "$(dirname "$0")"
-source gbmc-ip-monitor.sh
+cd "$(dirname "$0")" || exit
 if [ -e ../gbmc-ip-monitor.bb ]; then
+  # shellcheck source=meta-google/recipes-google/test/test-sh/lib.sh
   source '../../test/test-sh/lib.sh'
 else
+  # shellcheck source=meta-google/recipes-google/test/test-sh/lib.sh
   source "$SYSROOT/usr/share/test/lib.sh"
 fi
+# shellcheck source=meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh
+source gbmc-ip-monitor.sh
 
 test_init_empty() {
   ip() {
@@ -86,12 +90,12 @@
 
 test_init_route_populated() {
   ip() {
-    if [ "$1" = "-4" -a "${2-}" = 'route' ]; then
+    if [[ "$1" == "-4" && "${2-}" == 'route' ]]; then
       cat <<EOF
 default via 192.168.243.254 dev eno2 proto dhcp metric 100
 192.168.242.0/23 dev eno2 proto kernel scope link src 192.168.242.57 metric 100
 EOF
-    elif [ "$1" = "-6" -a "${2-}" = 'route' ]; then
+    elif [[ "$1" == "-6" && "${2-}" == 'route' ]]; then
       cat <<EOF
 ::1 dev lo proto kernel metric 256 pref medium
 fd01:ff2:5687:4::/64 dev eno2 proto ra metric 100 pref medium
diff --git a/meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh b/meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh
index 90986e3..74df6aa 100755
--- a/meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh
+++ b/meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh
@@ -1,4 +1,6 @@
 #!/bin/bash
+# shellcheck disable=SC2034
+# shellcheck disable=SC2317
 # Copyright 2021 Google LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +23,7 @@
 # hooks that are executed after each event.
 shopt -s nullglob
 for conf in /usr/share/gbmc-ip-monitor/*.sh; do
+  # shellcheck source=/dev/null
   source "$conf"
 done
 
@@ -35,7 +38,7 @@
   ip link | sed 's,^[^ ],[LINK]\0,'
   local intf=
   local line
-  while read line; do
+  while read -r line; do
     [[ "$line" =~ ^([0-9]+:[[:space:]][^:]+) ]] && intf="${BASH_REMATCH[1]}"
     [[ "$line" =~ ^[[:space:]]*inet ]] && echo "[ADDR]$intf $line"
   done < <(ip addr)
@@ -47,7 +50,7 @@
 GBMC_IP_MONITOR_DEFER_OUTSTANDING=
 gbmc_ip_monitor_defer_() {
   sleep 1
-  printf '[DEFER]\n' >&$GBMC_IP_MONITOR_DEFER
+  printf '[DEFER]\n' >&"$GBMC_IP_MONITOR_DEFER"
 }
 gbmc_ip_monitor_defer() {
   [ -z "$GBMC_IP_MONITOR_DEFER_OUTSTANDING" ] || return 0
@@ -96,7 +99,7 @@
     fi
     route="${BASH_REMATCH[2]}"
   elif [[ "$line" == '[LINK]'* ]]; then
-    change=link
+    change='link'
     action=add
     pfx_re='^\[LINK\](Deleted )?[0-9]+:[[:space:]]*'
     intf_re='([^:]+):[[:space:]]+'
@@ -108,8 +111,7 @@
       action=del
     fi
     intf="${BASH_REMATCH[2]}"
-    read line || break
-    data=($line)
+    read -ra data || return
     mac="${data[1]}"
   elif [[ "$line" == '[DEFER]'* ]]; then
     GBMC_IP_MONITOR_DEFER_OUTSTANDING=
@@ -125,7 +127,7 @@
   local st="$?"
   trap - HUP INT QUIT ABRT TERM EXIT
   jobs -l -p | xargs -r kill || true
-  exit $st
+  exit "$st"
 }
 trap cleanup HUP INT QUIT ABRT TERM EXIT
 
@@ -134,10 +136,10 @@
 exec {GBMC_IP_MONITOR_DEFER}<>"$FIFODIR"/fifo
 rm -rf "$FIFODIR"
 
-while read line; do
+while read -r line; do
   gbmc_ip_monitor_parse_line "$line" || continue
   gbmc_ip_monitor_run_hooks || continue
   if [ "$change" = 'init' ]; then
     systemd-notify --ready
   fi
-done < <(gbmc_ip_monitor_generate_init; ip monitor link addr route label & cat <&$GBMC_IP_MONITOR_DEFER)
+done < <(gbmc_ip_monitor_generate_init; ip monitor link addr route label & cat <&"$GBMC_IP_MONITOR_DEFER")