meta-google: network-sh: Fix shellcheck issues
Change-Id: I796cbc8794af790d09ba967b7ec07ceb2d0431c7
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/network-sh/lib.sh b/meta-google/recipes-google/networking/network-sh/lib.sh
index ebd74c5..3e32db0 100644
--- a/meta-google/recipes-google/networking/network-sh/lib.sh
+++ b/meta-google/recipes-google/networking/network-sh/lib.sh
@@ -27,7 +27,7 @@
IFS=:
local byte
for byte in $str; do
- bytes+=(0x$byte)
+ bytes+=("0x$byte")
done
IFS="$oldifs"
}
@@ -46,12 +46,13 @@
# Using EUI-64 conversion rules, create the suffix bytes from MAC bytes
# Invert bit-1 of the first byte, and insert 0xfffe in the middle.
+ # shellcheck disable=SC2034
local suffix_bytes=(
0 0 0 0 0 0 0 0
$((mac_bytes[0] ^ 2))
- ${mac_bytes[@]:1:2}
+ "${mac_bytes[@]:1:2}"
$((0xff)) $((0xfe))
- ${mac_bytes[@]:3:3}
+ "${mac_bytes[@]:3:3}"
)
# Return the EUI-64 bytes in the IPv6 format
@@ -84,7 +85,7 @@
IFS="$oldifs"
return 1
fi
- bytes+=($v)
+ bytes+=("$v")
done
# IPv4 addresses must have all 4 bytes present
if (( "${#bytes[@]}" != 4 )); then
@@ -151,10 +152,12 @@
fi
IFS="$oldifs"
+ # shellcheck disable=SC2034
bytes_out=("${bytes[@]}")
}
ip_bytes_to_str() {
+ # shellcheck disable=SC2178
local -n bytes="$1"
if (( "${#bytes[@]}" == 4 )); then
@@ -172,7 +175,7 @@
for (( i=0; i<=16; i+=2 )); do
# Terminate the run of zeros if we are at the end of the array or
# have a non-zero hextet
- if (( i == 16 || bytes[$i] != 0 || bytes[$((i+1))] != 0 )); then
+ if (( i == 16 || bytes[i] != 0 || bytes[$((i+1))] != 0 )); then
local s=$((i - first_zero))
if (( s >= longest_s )); then
longest_i=$first_zero
@@ -198,7 +201,7 @@
if (( i != 0 )); then
printf ':'
fi
- printf '%x' $(( (bytes[$i]<<8) | bytes[$(($i+1))]))
+ printf '%x' $(( (bytes[i]<<8) | bytes[$((i+1))]))
fi
done
printf '\n'
@@ -239,7 +242,7 @@
local i
# Check the rest of the whole bytes to make sure they are empty
for (( i=cidr/8+1; i<${#pfx_bytes[@]}; i++ )); do
- if (( pfx_bytes[$i] != 0 )); then
+ if (( pfx_bytes[i] != 0 )); then
echo "Byte $i not 0: $pfx" >&2
return 1
fi
@@ -264,7 +267,7 @@
local i
# Check the bytes before the CIDR for emptiness to ensure they don't overlap
for (( i=0; i<cidr/8; i++ )); do
- if (( sfx_bytes[$i] != 0 )); then
+ if (( sfx_bytes[i] != 0 )); then
echo "Byte $i not 0: $sfx" >&2
return 1
fi
@@ -272,7 +275,7 @@
out_bytes=()
for (( i=0; i<${#pfx_bytes[@]}; i++ )); do
- out_bytes+=($(( pfx_bytes[$i] | sfx_bytes[$i] )))
+ out_bytes+=($(( pfx_bytes[i] | sfx_bytes[i] )))
done
echo "$(ip_bytes_to_str out_bytes)/$cidr"
}
@@ -283,6 +286,7 @@
}
normalize_ip() {
+ # shellcheck disable=SC2034
local ip_bytes=()
ip_to_bytes ip_bytes "$1" || return
ip_bytes_to_str ip_bytes
diff --git a/meta-google/recipes-google/networking/network-sh/test.sh b/meta-google/recipes-google/networking/network-sh/test.sh
index 409514f..bcb882e 100755
--- a/meta-google/recipes-google/networking/network-sh/test.sh
+++ b/meta-google/recipes-google/networking/network-sh/test.sh
@@ -13,12 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cd "$(dirname "$0")"
+cd "$(dirname "$0")" || exit
if [ -e ../network-sh.bb ]; then
+ # shellcheck source=meta-google/recipes-google/test/test-sh/lib.sh
source '../../test/test-sh/lib.sh'
else
+ # shellcheck source=meta-google/recipes-google/test/test-sh/lib.sh
source "$SYSROOT/usr/share/test/lib.sh"
fi
+# shellcheck source=meta-google/recipes-google/networking/network-sh/lib.sh
source lib.sh
expect_array_numeq() {
@@ -111,6 +114,7 @@
expect_err 0 ip_to_bytes out '1:2:3:4:5:6:7:8'
expected=(0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8)
expect_array_numeq out expected
+ # shellcheck disable=SC2034
out=()
}
@@ -139,6 +143,7 @@
in=(0xfd 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1)
str="$(ip_bytes_to_str in)" || fail
expect_streq "$str" 'fd01:0:0:1:1::1'
+ # shellcheck disable=SC2034
in=(0 1 0 1 0xdd 0xdd 0 1 0 1 0 1 0 1 0 1)
str="$(ip_bytes_to_str in)" || fail
expect_streq "$str" '1:1:dddd:1:1:1:1:1'