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-gw-src.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-gw-src.sh
index 6085240..dd153ab 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-gw-src.sh
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-gw-src.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[ -n "${gbmc_br_gw_src_lib-}" ] && return
+[[ -n ${gbmc_br_gw_src_lib-} ]] && return
+# shellcheck source=meta-google/recipes-google/networking/network-sh/lib.sh
source /usr/share/network/lib.sh || exit
gbmc_br_gw_src_ip_stateful=
@@ -25,16 +27,16 @@
local defgw=
local route
for route in "${!gbmc_br_gw_src_routes[@]}"; do
- if [[ "$route" != *' dev gbmcbr '* ]]; then
+ if [[ $route != *' dev gbmcbr '* ]]; then
defgw=1
break
fi
done
- [ "$defgw" = "$gbmc_br_gw_defgw" ] && return
+ [[ $defgw == "$gbmc_br_gw_defgw" ]] && return
gbmc_br_gw_defgw="$defgw"
local files=(/run/systemd/network/{00,}-bmc-gbmcbr.network.d/50-defgw.conf)
- if [ -n "$defgw" ]; then
+ if [[ -n $defgw ]]; then
local file
for file in "${files[@]}"; do
mkdir -p "$(dirname "$file")"
@@ -44,19 +46,20 @@
rm -f "${files[@]}"
fi
- if [ "$(systemctl is-active systemd-networkd)" != 'inactive' ]; then
+ if [[ $(systemctl is-active systemd-networkd) != inactive ]]; then
networkctl reload && networkctl reconfigure gbmcbr
fi
}
gbmc_br_gw_src_update() {
local gbmc_br_gw_src_ip="${gbmc_br_gw_src_ip_stateful:-$gbmc_br_gw_src_ip_stateless}"
- [ -n "$gbmc_br_gw_src_ip" ] || return
+ [[ -n $gbmc_br_gw_src_ip ]] || return
local route
for route in "${!gbmc_br_gw_src_routes[@]}"; do
- [[ "$route" != *" src $gbmc_br_gw_src_ip "* ]] || continue
+ [[ $route != *" src $gbmc_br_gw_src_ip "* ]] || continue
echo "gBMC Bridge Updating GW source [$gbmc_br_gw_src_ip]: $route" >&2
+ # shellcheck disable=SC2086
ip route change $route src "$gbmc_br_gw_src_ip" && \
unset 'gbmc_br_gw_src_routes[$route]'
done
@@ -66,15 +69,16 @@
# We only want to match default gateway routes that are dynamic
# (have an expiration time). These will be updated with our preferred
# source.
- if [[ "$change" == 'route' && "$route" == 'default '*':'* ]]; then
- if [[ "$route" =~ ^(.*)( +expires +[^ ]+)(.*)$ ]]; then
+ # shellcheck disable=SC2154
+ if [[ $change == route && $route == 'default '*':'* ]]; then
+ if [[ $route =~ ^(.*)( +expires +[^ ]+)(.*)$ ]]; then
route="${BASH_REMATCH[1]}${BASH_REMATCH[3]}"
fi
- if [ "$action" = 'add' -a -z "${gbmc_br_gw_src_routes["$route"]}" ]; then
+ if [[ $action == add && -z ${gbmc_br_gw_src_routes["$route"]} ]]; then
gbmc_br_gw_src_routes["$route"]=1
gbmc_br_gw_src_update
gbmc_br_set_router
- elif [ "$action" = 'del' -a -n "${gbmc_br_gw_src_routes["$route"]}" ]; then
+ elif [[ $action == del && -n "${gbmc_br_gw_src_routes["$route"]}" ]]; then
unset 'gbmc_br_gw_src_routes[$route]'
gbmc_br_gw_src_update
gbmc_br_set_router
@@ -82,8 +86,8 @@
# Match only global IP addresses on the bridge that match the BMC stateless
# prefix (<mpfx>:fd00:). So 2002:af4:3480:2248:fd00:6345:3069:9186 would be
# matched as the preferred source IP for outoging traffic.
- elif [ "$change" = 'addr' -a "$intf" = 'gbmcbr' -a "$scope" = 'global' ] &&
- [[ "$fam" == 'inet6' && "$flags" != *tentative* ]]; then
+ elif [[ $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 Ensure RA Invalid IP: $ip" >&2
@@ -98,11 +102,11 @@
else
local -n gbmc_br_gw_src_ip=gbmc_br_gw_src_ip_stateless
fi
- if [ "$action" = 'add' -a "$ip" != "$gbmc_br_gw_src_ip" ]; then
+ if [[ $action == add && $ip != "$gbmc_br_gw_src_ip" ]]; then
gbmc_br_gw_src_ip="$ip"
gbmc_br_gw_src_update
fi
- if [ "$action" = 'del' -a "$ip" = "$gbmc_br_gw_src_ip" ]; then
+ if [[ $action == del && $ip == "$gbmc_br_gw_src_ip" ]]; then
gbmc_br_gw_src_ip=
fi
fi