From 604e7e546a7307c66c7a4b4c45fcf187521f214a Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sun, 23 Mar 2025 00:15:24 +0100
Subject: [PATCH] treewide: fix previously disabled shellcheck warnings

Warnings are either fixed properly, or disabled in a more fine-grained
manner.
---
 .../files/usr/lib/autoupdater/abort.d/60gluon-alfred  |  2 +-
 .../usr/lib/autoupdater/download.d/40gluon-alfred     |  2 +-
 .../usr/lib/autoupdater/abort.d/90gluon-autoupdater   |  1 +
 .../lib/autoupdater/download.d/10gluon-autoupdater    |  1 +
 package/gluon-core/files/lib/gluon/label_mac.sh       |  2 ++
 .../gluon-core/files/lib/netifd/proto/gluon_mesh.sh   |  2 ++
 .../gluon-core/files/lib/netifd/proto/gluon_wired.sh  |  8 ++++++--
 .../usr/lib/autoupdater/abort.d/15start-arp-limiter   |  1 +
 .../usr/lib/autoupdater/upgrade.d/05stop-arp-limiter  |  1 +
 .../files/lib/netifd/proto/gluon_bat0.sh              | 11 ++++++++---
 .../files/usr/lib/autoupdater/abort.d/10start-network |  1 +
 .../usr/lib/autoupdater/upgrade.d/10stop-network      |  1 +
 .../files/usr/lib/autoupdater/abort.d/10olsrd         |  1 +
 .../files/usr/lib/autoupdater/upgrade.d/10olsrd       |  1 +
 .../files/lib/gluon/mesh-vpn/wireguard_pubkey.sh      |  2 ++
 .../files/lib/netifd/proto/gluon_wireguard.sh         |  5 +++++
 .../files/usr/lib/autoupdater/abort.d/80gluon-radvd   |  2 +-
 .../usr/lib/autoupdater/download.d/20gluon-radvd      |  2 +-
 .../usr/lib/autoupdater/abort.d/50gluon-respondd      |  1 +
 .../usr/lib/autoupdater/download.d/50gluon-respondd   |  2 +-
 .../gluon-setup-mode/files/lib/preinit/90_setup_mode  |  5 +++--
 .../usr/lib/autoupdater/abort.d/70gluon-status-page   |  1 +
 .../lib/autoupdater/download.d/30gluon-status-page    |  1 +
 23 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/package/gluon-alfred/files/usr/lib/autoupdater/abort.d/60gluon-alfred b/package/gluon-alfred/files/usr/lib/autoupdater/abort.d/60gluon-alfred
index 621c09a09..504fff52f 100755
--- a/package/gluon-alfred/files/usr/lib/autoupdater/abort.d/60gluon-alfred
+++ b/package/gluon-alfred/files/usr/lib/autoupdater/abort.d/60gluon-alfred
@@ -1,6 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
-
 start_enabled alfred
diff --git a/package/gluon-alfred/files/usr/lib/autoupdater/download.d/40gluon-alfred b/package/gluon-alfred/files/usr/lib/autoupdater/download.d/40gluon-alfred
index 19427620d..eb465e16e 100755
--- a/package/gluon-alfred/files/usr/lib/autoupdater/download.d/40gluon-alfred
+++ b/package/gluon-alfred/files/usr/lib/autoupdater/download.d/40gluon-alfred
@@ -1,6 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
-
 stop alfred
diff --git a/package/gluon-autoupdater/files/usr/lib/autoupdater/abort.d/90gluon-autoupdater b/package/gluon-autoupdater/files/usr/lib/autoupdater/abort.d/90gluon-autoupdater
index 63a37cca8..783b59d52 100755
--- a/package/gluon-autoupdater/files/usr/lib/autoupdater/abort.d/90gluon-autoupdater
+++ b/package/gluon-autoupdater/files/usr/lib/autoupdater/abort.d/90gluon-autoupdater
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-autoupdater/files/usr/lib/autoupdater/download.d/10gluon-autoupdater b/package/gluon-autoupdater/files/usr/lib/autoupdater/download.d/10gluon-autoupdater
index 28197921f..5f752558b 100755
--- a/package/gluon-autoupdater/files/usr/lib/autoupdater/download.d/10gluon-autoupdater
+++ b/package/gluon-autoupdater/files/usr/lib/autoupdater/download.d/10gluon-autoupdater
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-core/files/lib/gluon/label_mac.sh b/package/gluon-core/files/lib/gluon/label_mac.sh
index 3479324bc..431efe98b 100755
--- a/package/gluon-core/files/lib/gluon/label_mac.sh
+++ b/package/gluon-core/files/lib/gluon/label_mac.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091
+
 . /lib/functions/system.sh
 
 get_mac_label
diff --git a/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh b/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh
index 52d6abec7..fc3d3acf6 100755
--- a/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh
+++ b/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091
+
 . /lib/functions.sh
 . ../netifd-proto.sh
 init_proto "$@"
diff --git a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh
index d33c8a274..954fef97d 100755
--- a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh
+++ b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091
+
 . /lib/functions.sh
 . ../netifd-proto.sh
 init_proto "$@"
@@ -17,7 +19,8 @@ xor2() {
 }
 
 is_layer3_device () {
-	local addrlen="$(cat "/sys/class/net/$1/addr_len")"
+	local addrlen
+	addrlen="$(cat "/sys/class/net/$1/addr_len")"
 	test "$addrlen" -eq 0
 }
 
@@ -34,7 +37,8 @@ interface_linklocal() {
 		return
 	fi
 
-	local macaddr="$(ubus call network.device status '{"name": "'"$1"'"}' | jsonfilter -e '@.macaddr')"
+	local macaddr
+	macaddr="$(ubus call network.device status '{"name": "'"$1"'"}' | jsonfilter -e '@.macaddr')"
 	local oldIFS="$IFS"; IFS=':'; set -- $macaddr; IFS="$oldIFS"
 
 	echo "fe80::$(xor2 "$1")$2:$3ff:fe$4:$5$6"
diff --git a/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/abort.d/15start-arp-limiter b/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/abort.d/15start-arp-limiter
index 982629c4f..5a022b331 100755
--- a/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/abort.d/15start-arp-limiter
+++ b/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/abort.d/15start-arp-limiter
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 # Start after network
diff --git a/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/upgrade.d/05stop-arp-limiter b/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/upgrade.d/05stop-arp-limiter
index f9fdbd5c4..04e6b0a90 100755
--- a/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/upgrade.d/05stop-arp-limiter
+++ b/package/gluon-ebtables-limit-arp/files/usr/lib/autoupdater/upgrade.d/05stop-arp-limiter
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 # Stop before network
diff --git a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
index 91ea0d356..feeacfd7d 100755
--- a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
+++ b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091,SC2034
+
 . /lib/functions.sh
 . ../netifd-proto.sh
 init_proto "$@"
@@ -37,7 +39,8 @@ proto_gluon_bat0_renew() {
 proto_gluon_bat0_setup() {
 	local config="$1"
 
-	local routing_algo="$(lookup_site 'mesh.batman_adv.routing_algo' 'BATMAN_IV')"
+	local routing_algo
+	routing_algo="$(lookup_site 'mesh.batman_adv.routing_algo' 'BATMAN_IV')"
 
 	local gw_mode
 	json_get_vars gw_mode
@@ -54,7 +57,8 @@ proto_gluon_bat0_setup() {
 			batctl gw_mode "server"
 		;;
 		client)
-			local gw_sel_class="$(lookup_site 'mesh.batman_adv.gw_sel_class')"
+			local gw_sel_class
+			gw_sel_class="$(lookup_site 'mesh.batman_adv.gw_sel_class')"
 			if [ -n "$gw_sel_class" ]; then
 				batctl gw_mode "client" "$gw_sel_class"
 			else
@@ -67,7 +71,8 @@ proto_gluon_bat0_setup() {
 	esac
 
 
-	local primary0_mac="$(lua -e 'print(require("gluon.util").generate_mac(3))')"
+	local primary0_mac
+	primary0_mac="$(lua -e 'print(require("gluon.util").generate_mac(3))')"
 
 	ip link add primary0 type dummy
 	echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6
diff --git a/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/abort.d/10start-network b/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/abort.d/10start-network
index f04d55cc7..87530d212 100755
--- a/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/abort.d/10start-network
+++ b/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/abort.d/10start-network
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 pidof netifd >/dev/null || start_enabled network
diff --git a/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/upgrade.d/10stop-network b/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/upgrade.d/10stop-network
index b02580a32..518040736 100755
--- a/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/upgrade.d/10stop-network
+++ b/package/gluon-mesh-batman-adv/files/usr/lib/autoupdater/upgrade.d/10stop-network
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 wifi down
diff --git a/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/abort.d/10olsrd b/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/abort.d/10olsrd
index 8f39df994..daefd2503 100755
--- a/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/abort.d/10olsrd
+++ b/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/abort.d/10olsrd
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/upgrade.d/10olsrd b/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/upgrade.d/10olsrd
index c9cd9a8cc..9ad18a163 100755
--- a/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/upgrade.d/10olsrd
+++ b/package/gluon-mesh-olsrd/files/usr/lib/autoupdater/upgrade.d/10olsrd
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-mesh-vpn-wireguard/files/lib/gluon/mesh-vpn/wireguard_pubkey.sh b/package/gluon-mesh-vpn-wireguard/files/lib/gluon/mesh-vpn/wireguard_pubkey.sh
index bbcba5717..24c096578 100755
--- a/package/gluon-mesh-vpn-wireguard/files/lib/gluon/mesh-vpn/wireguard_pubkey.sh
+++ b/package/gluon-mesh-vpn-wireguard/files/lib/gluon/mesh-vpn/wireguard_pubkey.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091,SC2034
+
 INCLUDE_ONLY=1
 . /lib/netifd/proto/wireguard.sh
 
diff --git a/package/gluon-mesh-vpn-wireguard/files/lib/netifd/proto/gluon_wireguard.sh b/package/gluon-mesh-vpn-wireguard/files/lib/netifd/proto/gluon_wireguard.sh
index 05eaad535..580276aba 100755
--- a/package/gluon-mesh-vpn-wireguard/files/lib/netifd/proto/gluon_wireguard.sh
+++ b/package/gluon-mesh-vpn-wireguard/files/lib/netifd/proto/gluon_wireguard.sh
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+# shellcheck disable=SC1091
+
+# FIXME: The following lints should not need to be disabled
+# shellcheck disable=SC2034,SC2155
+
 PROTO_DEBUG=1
 
 . /lib/functions.sh
diff --git a/package/gluon-radvd/files/usr/lib/autoupdater/abort.d/80gluon-radvd b/package/gluon-radvd/files/usr/lib/autoupdater/abort.d/80gluon-radvd
index 5784fa5fc..32814a733 100755
--- a/package/gluon-radvd/files/usr/lib/autoupdater/abort.d/80gluon-radvd
+++ b/package/gluon-radvd/files/usr/lib/autoupdater/abort.d/80gluon-radvd
@@ -1,6 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
-
 start_enabled gluon-radvd
diff --git a/package/gluon-radvd/files/usr/lib/autoupdater/download.d/20gluon-radvd b/package/gluon-radvd/files/usr/lib/autoupdater/download.d/20gluon-radvd
index ade506166..18f2c668e 100755
--- a/package/gluon-radvd/files/usr/lib/autoupdater/download.d/20gluon-radvd
+++ b/package/gluon-radvd/files/usr/lib/autoupdater/download.d/20gluon-radvd
@@ -1,6 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
-
 stop gluon-radvd
diff --git a/package/gluon-respondd/files/usr/lib/autoupdater/abort.d/50gluon-respondd b/package/gluon-respondd/files/usr/lib/autoupdater/abort.d/50gluon-respondd
index d29af306a..45f5ffeed 100755
--- a/package/gluon-respondd/files/usr/lib/autoupdater/abort.d/50gluon-respondd
+++ b/package/gluon-respondd/files/usr/lib/autoupdater/abort.d/50gluon-respondd
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-respondd/files/usr/lib/autoupdater/download.d/50gluon-respondd b/package/gluon-respondd/files/usr/lib/autoupdater/download.d/50gluon-respondd
index 3edd5f1d6..54559b6ec 100755
--- a/package/gluon-respondd/files/usr/lib/autoupdater/download.d/50gluon-respondd
+++ b/package/gluon-respondd/files/usr/lib/autoupdater/download.d/50gluon-respondd
@@ -1,6 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
-
 stop gluon-respondd
diff --git a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode
index b9365be1e..1ec3bd551 100644
--- a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode
+++ b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode
@@ -2,8 +2,9 @@
 
 
 setup_mode_enable() {
-	local enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')"
-	local configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')"
+	local enabled configured
+	enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')"
+	configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')"
 
 	if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then
 		echo '/lib/gluon/setup-mode/rc.d' > /tmp/rc_d_path
diff --git a/package/gluon-status-page/files/usr/lib/autoupdater/abort.d/70gluon-status-page b/package/gluon-status-page/files/usr/lib/autoupdater/abort.d/70gluon-status-page
index 9afbeec5c..747b4a8ab 100755
--- a/package/gluon-status-page/files/usr/lib/autoupdater/abort.d/70gluon-status-page
+++ b/package/gluon-status-page/files/usr/lib/autoupdater/abort.d/70gluon-status-page
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
diff --git a/package/gluon-status-page/files/usr/lib/autoupdater/download.d/30gluon-status-page b/package/gluon-status-page/files/usr/lib/autoupdater/download.d/30gluon-status-page
index 7db1d6b7d..a688474bb 100755
--- a/package/gluon-status-page/files/usr/lib/autoupdater/download.d/30gluon-status-page
+++ b/package/gluon-status-page/files/usr/lib/autoupdater/download.d/30gluon-status-page
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+# shellcheck source=package/gluon-autoupdater/files/lib/gluon/autoupdater/lib.sh
 . /lib/gluon/autoupdater/lib.sh
 
 
-- 
GitLab