Last active
April 24, 2026 02:25
-
-
Save AkazaRenn/bdb645315fd43dc1ec6178ced11b8d40 to your computer and use it in GitHub Desktop.
OpenWrt script to update timezone by IP, should be stored in /etc/hotplug.d/iface/, requires zoneinfo-all
This file contains hidden or 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/sh | |
| if [ "${INTERFACE}" = "loopback" ]; then | |
| exit 0 | |
| fi | |
| if [ "${ACTION}" != "ifup" ] && [ "${ACTION}" != "ifupdate" ]; then | |
| exit 0 | |
| fi | |
| if [ "${ACTION}" = "ifupdate" ] && [ -z "${IFUPDATE_ADDRESSES}" ] && [ -z "${IFUPDATE_DATA}" ]; then | |
| exit 0 | |
| fi | |
| timezone=$(wget -qO- https://ipinfo.io/timezone) | |
| if [ $? -eq 0 ] && [ -n "${timezone}" ] && [ "${timezone}" != "$(uci get system.@system[0].zonename)" ]; then | |
| uci set system.@system[0].zonename="${timezone}" | |
| uci set system.@system[0].timezone="$(tail -n1 /usr/share/zoneinfo/${timezone})" | |
| uci commit system | |
| /etc/init.d/system reload | |
| /etc/init.d/cron restart | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment