Last active
January 7, 2020 15:25
-
-
Save viviag/9d483fe37884461af1894d06a5e659e9 to your computer and use it in GitHub Desktop.
Update system timezone based on IP geolocation, established under Linux Munt 18.3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# crontab: | |
# */10 * * * * tzupdate.sh | |
# @reboot doesn't fit because of network connection delay. | |
# Get external IP | |
IP=$(curl ifconfig.me) | |
# Request to geolocation web service (https://ipgeolocation.io/documentation/timezone-api.html). | |
REQ="https://api.ipgeolocation.io/timezone?apiKey=$GEOTOKEN&ip=$IP" | |
data=$(curl $REQ) | |
# Naively parse responce - under assumption of uniqueness of "timezone" field in, which accords with docs. | |
tz=$(echo $data | grep -Po "(?<=\"timezone\":\")[^\"]*?(?=\")") | |
# Set system timezone. | |
timedatectl set-timezone "$tz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment