Skip to content

Commit

Permalink
refine code (fixes #2137)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLKwong committed Mar 26, 2021
1 parent c977222 commit 0cf44a2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions modules/internet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function internet {
if ! nc -w 10 -z 8.8.8.8 53 >/dev/null 1>&2; then
log_and_exit1 "Error: no internet found"
fi
# I can't even
info="$(curl -s ipinfo.io | grep -o '"[^"]*"\s*:\s*"[^"]*"')"
ip=$(echo "$info" | grep -e '"ip": "')
org=$(echo "$info" | grep -e '"org": "')
Expand All @@ -22,13 +21,13 @@ function internet {
postal=$(echo $info | grep -o '"postal": "[^;]*' | cut -d '"' -f 4)
timezone=$(echo $info | grep -o '"timezone": "[^;]*' | cut -d '"' -f 4)

echo "$ip"
echo "$org"
if [ -z "$postal" ]; then
echo "$country, \"city\": \"$city\", \"postal\": \"n/a\""
else
echo "$country, \"city\": \"$city\", \"postal\": \"$postal\""
postal="n/a"
fi

echo "$ip"
echo "$org"
echo "$country, \"city\": \"$city\", \"postal\": \"$postal\""
echo "\"timezone\": \"$timezone\""
;;
*)
Expand Down

0 comments on commit 0cf44a2

Please sign in to comment.