meta-google: gbmc-bridge: Fix shellcheck issues

Change-Id: Ib19746fffaad5f62293fc3479dee7d557a226734
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
index ca4e15a..7aa2158 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 # Copyright 2021 Google LLC
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,11 +13,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-[ -z "${gbmc_br_nft_lib-}" ] || return
+[[ -n ${gbmc_br_nft_lib-} ]] && return
 
+# shellcheck source=meta-google/recipes-google/networking/network-sh/lib.sh
 source /usr/share/network/lib.sh || exit
 
-gbmc_br_nft_init=
 gbmc_br_nft_pfx=
 
 gbmc_br_nft_update() {
@@ -26,7 +27,7 @@
   local contents=
   contents+='table inet filter {'$'\n'
   contents+='    chain gbmc_br_int_input {'$'\n'
-  if [ -n "${gbmc_br_nft_pfx-}" ]; then
+  if [[ -n ${gbmc_br_nft_pfx-} ]]; then
     contents+="        ip6 saddr $gbmc_br_nft_pfx"
     contents+=" ip6 daddr $gbmc_br_nft_pfx accept"$'\n'
   fi
@@ -34,21 +35,20 @@
   contents+='}'$'\n'
 
   local rfile=/run/nftables/40-gbmc-br-int.rules
-  mkdir -p -m 755 "$(dirname "$rfile")"
+  mkdir -p "$(dirname "$rfile")"
   printf '%s' "$contents" >"$rfile"
 
+  # shellcheck disable=SC2015
   systemctl reset-failed nftables && systemctl --no-block reload-or-restart nftables || true
 }
 
 gbmc_br_nft_hook() {
-  if [ "$change" = 'init' ]; then
-    gbmc_br_nft_init=1
-    gbmc_br_nft_update
   # Match only global IP addresses on the bridge that match the BMC prefix
   # (<mpfx>:fdxx:). So 2002:af4:3480:2248:fd02:6345:3069:9186 would become
   # a 2002:af4:3480:2248:fd00/76 rule.
-  elif [ "$change" = 'addr' -a "$intf" = 'gbmcbr' -a "$scope" = 'global' ] &&
-       [[ "$fam" == 'inet6' && "$flags" != *tentative* ]]; then
+  # shellcheck disable=SC2154
+  if [[ $change == addr && $intf == gbmcbr && $scope == global ]] &&
+       [[ $fam == inet6 && $flags != *tentative* ]]; then
     local ip_bytes=()
     if ! ip_to_bytes ip_bytes "$ip"; then
       echo "gBMC Bridge NFT Invalid IP: $ip" >&2
@@ -59,10 +59,10 @@
     fi
     local i
     for (( i=9; i<16; i++ )); do
-      ip_bytes[$i]=0
+      ip_bytes["$i"]=0
     done
     pfx="$(ip_bytes_to_str ip_bytes)/76"
-    if [ "$action" = "add" -a "$pfx" != "$gbmc_br_nft_pfx" ]; then
+    if [[ $action == add && $pfx != "$gbmc_br_nft_pfx" ]]; then
       gbmc_br_nft_pfx="$pfx"
       gbmc_br_nft_update
     fi