fix(ipstack-vpn): do not err on wrong JSON from API

This commit is contained in:
Pavel Korytov 2021-10-28 15:48:50 +03:00
parent 770a2421a6
commit 0dc4420ecc
2 changed files with 10 additions and 2 deletions

View file

@ -993,9 +993,13 @@ if [[ -z $ip || $ip == *"timed out"* ]]; then
fi
ip_info=$(curl -s http://api.ipstack.com/${ip}?access_key=${API_KEY})
# emoji=$(echo $ip_info | jq -r '.location.country_flag_emoji')
code=$(echo $ip_info | jq -r '.country_code')
code=$(echo $ip_info | jq -r '.country_code' 2> /dev/null)
vpn=$(pgrep -a openvpn$ | head -n 1 | awk '{print $NF }' | cut -d '.' -f 1)
if [[ -z $code ]]; then
code="??"
fi
if [ -n "$vpn" ]; then
echo "%{u<<get-color(name="blue")>>}%{+u}  $code %{u-}"
else

View file

@ -9,9 +9,13 @@ if [[ -z $ip || $ip == *"timed out"* ]]; then
fi
ip_info=$(curl -s http://api.ipstack.com/${ip}?access_key=${API_KEY})
# emoji=$(echo $ip_info | jq -r '.location.country_flag_emoji')
code=$(echo $ip_info | jq -r '.country_code')
code=$(echo $ip_info | jq -r '.country_code' 2> /dev/null)
vpn=$(pgrep -a openvpn$ | head -n 1 | awk '{print $NF }' | cut -d '.' -f 1)
if [[ -z $code ]]; then
code="??"
fi
if [ -n "$vpn" ]; then
echo "%{u#82aaff}%{+u}  $code %{u-}"
else