diff options
author | William A. Kennington III <wak@google.com> | 2023-06-06 00:35:17 +0300 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2023-06-06 03:00:45 +0300 |
commit | b06ae50426a746aeb768b6c250c70087c78ead0d (patch) | |
tree | 4230edf26775e11b60063151e11fc288f4f8c00c /meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh | |
parent | 4372aabadb2ce97a3a4a3e38fe2edcf76ed46257 (diff) | |
download | openbmc-b06ae50426a746aeb768b6c250c70087c78ead0d.tar.xz |
meta-google: gbmc-ip-monitor: Fix shellcheck issues
Change-Id: I3bcdbb94553a8d3f181ccb109a99bf2e2a4dfe2b
Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh')
-rwxr-xr-x | meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh | 18 |
1 files changed, 10 insertions, 8 deletions
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 90986e3068..74df6aa38b 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 @@ GBMC_IP_MONITOR_HOOKS=() # 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 @@ gbmc_ip_monitor_generate_init() { 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_generate_init() { 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 @@ gbmc_ip_monitor_parse_line() { 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 @@ gbmc_ip_monitor_parse_line() { 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 @@ cleanup() { 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 @@ mkfifo "$FIFODIR"/fifo 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") |