From 942845fbc7cdd270f01da0f28fdf189a01c5a0ee Mon Sep 17 00:00:00 2001
From: jotaen4tinypilot <83721279+jotaen4tinypilot@users.noreply.github.com>
Date: Fri, 5 Apr 2024 16:54:53 +0200
Subject: [PATCH] Use arithmetic bash comparisons (#1776)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
As discussed in
https://github.com/tiny-pilot/style-guides/issues/19#issuecomment-2036381414,
and in eager compliance with the [Google bash style
guide](https://google.github.io/styleguide/shellguide.html#s6.9-arithmetic),
we can replace all instances of `[[ -gt ]]` or `[[ -lt ]]` with
arithmetic expressions (`(( > ))` or `(( < ))`).
I’ve briefly tested all scripts, so from my side a double-check on the
code would be enough as review.
Co-authored-by: Jan Heuermann
---
bundler/verify-bundle | 2 +-
debian-pkg/opt/tinypilot-privileged/scripts/configure-janus | 2 +-
.../opt/tinypilot-privileged/scripts/strip-marker-sections | 2 +-
dev-scripts/run-e2e-tests | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bundler/verify-bundle b/bundler/verify-bundle
index d9f2bea65..be715ce03 100755
--- a/bundler/verify-bundle
+++ b/bundler/verify-bundle
@@ -22,7 +22,7 @@ if [[ "${BUNDLE_SIZE_BYTES}" -eq 0 ]]; then
>&2 echo 'Bundle size is zero.'
exit 1
fi
-if [[ "${BUNDLE_SIZE_BYTES}" -gt 10000000 ]]; then
+if (( "${BUNDLE_SIZE_BYTES}" > 10000000 )); then
>&2 echo 'Bundle size is larger than 10mb.'
exit 1
fi
diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/configure-janus b/debian-pkg/opt/tinypilot-privileged/scripts/configure-janus
index 195ff6b39..440aed150 100755
--- a/debian-pkg/opt/tinypilot-privileged/scripts/configure-janus
+++ b/debian-pkg/opt/tinypilot-privileged/scripts/configure-janus
@@ -20,7 +20,7 @@ EOF
}
# Parse command-line arguments.
-while [[ "$#" -gt 0 ]]; do
+while (( "$#" > 0 )); do
case "$1" in
--help)
print_help
diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/strip-marker-sections b/debian-pkg/opt/tinypilot-privileged/scripts/strip-marker-sections
index 0925419ea..9832145a5 100755
--- a/debian-pkg/opt/tinypilot-privileged/scripts/strip-marker-sections
+++ b/debian-pkg/opt/tinypilot-privileged/scripts/strip-marker-sections
@@ -34,7 +34,7 @@ EOF
# Parse command-line arguments.
TARGET_FILE=''
-while [[ "$#" -gt 0 ]]; do
+while (( "$#" > 0 )); do
case "$1" in
--help)
print_help
diff --git a/dev-scripts/run-e2e-tests b/dev-scripts/run-e2e-tests
index c79972401..4d5118ede 100755
--- a/dev-scripts/run-e2e-tests
+++ b/dev-scripts/run-e2e-tests
@@ -28,14 +28,14 @@ EOF
# Parse command-line arguments.
E2E_BASE_URL=''
PLAYWRIGHT_ARGS=()
-while [[ "$#" -gt 0 ]]; do
+while (( "$#" > 0 )); do
case "$1" in
--help)
print_help
exit
;;
--base-url)
- if [[ "$#" -lt 2 ]]; then
+ if (( "$#" < 2 )); then
shift;
break;
fi