Skip to content

Commit

Permalink
internet reverse reorder and keep unique (fixes #2137)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLKwong committed Mar 26, 2021
1 parent d40cbb7 commit 3986e26
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions modules/internet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ function internet {
log_and_exit1 "Error: no internet found"
fi
info="$(curl -s ipinfo.io | grep -o '"[^"]*"\s*:\s*"[^"]*"')"
echo "$info" | grep -E '"(ip)"'
echo "$info" | grep -E '"(org)"'
echo "1"
echo "$info" | grep -E '"(country)"' | grep -E '"(city)"' | grep -E '"(postal)"'
echo "2"
ip=$(echo "$info" | grep -E '"(ip)"')
org=$(echo "$info" | grep -E '"(org)"')
country=$(echo "$info" | grep -E '"(country)"')
city=$(echo $info | grep -E '"(city)"'
postal=$(echo $postal | grep -E '"(postal)"')
timezone=$(echo $postal | grep -E '"(timezone)"')
echo "$ip"
echo "$org"
if ! echo "$info" | grep -E 'postal'; then
echo "$info" | grep -E '"(country|city)"' | tr '\n' ',' | sed 's/,$/, "postal": "n\/a"\n/' | sed 's/\",\"/\", \"/g'
echo "$country, $city, \"postal\": \"n/a\""
else
echo "$info" | grep -E '"(country|city|postal)"' | tr '\n' ',' | sed 's/,$/\n/' | sed 's/\",\"/\", \"/g'
echo "$country, $city, $postal"
fi
echo "$info" | grep -E '"(timezone)"'
echo "$timezone"
;;
*)
log_help_and_exit1 "ERROR: incorrect command" internet
Expand Down

0 comments on commit 3986e26

Please sign in to comment.