Skip to content

Commit

Permalink
speed: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavid committed Nov 12, 2023
1 parent 873e00a commit 7fa7e23
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions app/speed
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# shellcheck disable=SC1091,SC2034 # File not following, appears unused.
set -- "$@" --quiet
readonly \
BASE_APP_VERSION=0.9.20230604 \
BASE_APP_VERSION=0.9.20231112 \
BASE_MIN_VERSION=0.9.20230505
. base.sh

Expand All @@ -21,6 +21,7 @@ main() {
while :; do
[ $((i % 30)) -eq 0 ] && title
test_speed
sleep 1
i=$((i + 1))
done
}
Expand All @@ -30,31 +31,29 @@ main() {
test_speed() {
url_exists google.com >/dev/null || {
loge Check internet connection.
sleep 1
return 0
}
local down host out up
if out="$(speedtest-cli 2>&1)"; then
down="$(
printf %s "$out" |
grep -E '^Download: ' |
gawk '{print $2}'
)"
up="$(
printf %s "$out" |
grep -E '^Upload: ' |
gawk '{print $2}'
)"
host="$(
printf %s "$out" |
grep -E '^Hosted by ' |
cut -c11-
)"
tsout "| $(printf %6s "$down") | $(printf %6s "$up") | $host"
else
local out
out="$(speedtest-cli 2>&1)" || {
loge "$(printf %s "$out" | xargs)"
sleep 1
fi
return 0
}
local down
down="$(printf %s "$out" | grep -E '^Download: ' | gawk '{print $2}')" || {
loge "$out: $down"
return 0
}
local up
up="$(printf %s "$out" | grep -E '^Upload: ' | gawk '{print $2}' )" || {
loge "$out: $up"
return 0
}
local host
host="$(printf %s "$out" | grep -E '^Hosted by ' | cut -c11- )" || {
loge "$out: $host"
return 0
}
tsout "| $(printf %6s "$down") | $(printf %6s "$up") | $host"
}

# Prints top title.
Expand Down

0 comments on commit 7fa7e23

Please sign in to comment.