Skip to content

Instantly share code, notes, and snippets.

@AkazaRenn
Last active April 24, 2026 02:25
Show Gist options
  • Select an option

  • Save AkazaRenn/bdb645315fd43dc1ec6178ced11b8d40 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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