1

I recently installed system indicator monitor by fossfreedom (https://github.com/fossfreedom/indicator-sysmonitor) and I am able to add a custom shell command.

Since I VPN to many different servers around the world, I would like to have this monitor show a flag icon based on location. Currently, I configured it to show two letter country code (e.g. US, UK, BR, etc.), but I want it to replace this with the location of a flag icon in my directories.

I installed a series of flag icons from famfamfam-flag-png, which installs 16x11 flag pngs here: /usr/share/flags/countries/16x11/

So using the 'indicator-sysmonitor' I thought I can add a custom script ($HOME/scripts/checklocation) such as: curl ipv4.icanhazip.com | curl ipinfo.io | grep country | awk '{print $2}' | sed 's/,//g' | sed 's/"//g'

which reports the two letter country code, then I can replace it with the path to the appropriate icon. But I am not sure how to do this... Need help configuring my custom script above to report the appropriate flag icon and then to make it work so it would replace 'LOC: BR' with just the flag for BR in my panel.

1 Answer 1

1

You're currently using this long chain of commands to get your country code:

$ curl ipv4.icanhazip.com | curl ipinfo.io | grep country | awk '{print $2}' | sed 's/,//g' | sed 's/"//g'
US

You can simplify that whole thing to a single http://ipinfo.io lookup:

$ curl ipinfo.io/country
US

You can combined that with the flag image path like this:

$ country=$(curl -s ipinfo.io/country)
$ flag="/usr/share/flags/countries/16x11/${country}.png"
$ echo $flag
/usr/share/flags/countries/16x11/US.png
3
  • Thank you Ben. Now I have a problem, ipinfo.io has a limit of 1000 queries per day. Now I have to wait 24 hours to reset. In the meantime, I found another solution. But I am not very good with bash, so how can I pipe this into a variable like flag (similar to what you did). whois $(curl ifconfig.me) | flag=$(awk 'tolower($1) ~ /^country:/ { print $2 }')
    – labrazil
    Sep 9, 2015 at 23:26
  • Whois also has a rate limit, and the country information isn't included for every IP. Your best bet is to use ipinfo.io. If you need more than 1000 req a day (which seems unlikely in this scenario) you can pay for more at ipinfo.io/pricing Sep 10, 2015 at 1:54
  • Or I can set my checks to 1 every 90 seconds, this should take me under the 1000 hit rate. Thanks!
    – labrazil
    Sep 10, 2015 at 2:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .