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.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")