From fe38f6fdf6066ee2d388afdd09b4e8c7bf9c25a8 Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Fri, 24 Apr 2026 23:46:50 +0000 Subject: [PATCH 1/7] auto-timezone: add new package A hotplug script to auto set the timezone based on the IP address Signed-off-by: Renn Akaza --- utils/auto-timezone/Makefile | 38 ++++++++++++++++ utils/auto-timezone/files/99-auto-timezone | 45 +++++++++++++++++++ .../auto-timezone/files/auto-timezone.config | 1 + 3 files changed, 84 insertions(+) create mode 100644 utils/auto-timezone/Makefile create mode 100644 utils/auto-timezone/files/99-auto-timezone create mode 100644 utils/auto-timezone/files/auto-timezone.config diff --git a/utils/auto-timezone/Makefile b/utils/auto-timezone/Makefile new file mode 100644 index 00000000000000..e4849d5b1cf058 --- /dev/null +++ b/utils/auto-timezone/Makefile @@ -0,0 +1,38 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=auto-timezone +PKG_VERSION:=1.0.0 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Renn Akaza +PKG_LICENSE:=GPL-3.0-or-later + +include $(INCLUDE_DIR)/package.mk + +define Package/auto-timezone + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Auto set timezone by IP + PKGARCH:=all + DEPENDS:=+zoneinfo-all +endef + +define Package/auto-timezone/description +Hotplug script to automatically configure the timezone UCI settings based on the IP address. + +The user needs to set their own endpoint to get the IANA timezone string, e.g.: + uci set auto-timezone.config.endpoint="https://domain.tld/json" + uci commit +endef + +define Build/Compile +endef + +define Package/auto-timezone/install + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/ + $(INSTALL_DATA) ./files/99-auto-timezone $(1)/etc/hotplug.d/iface/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) ./files/auto-timezone.config $(1)/etc/config/auto-timezone +endef + +$(eval $(call BuildPackage,auto-timezone)) diff --git a/utils/auto-timezone/files/99-auto-timezone b/utils/auto-timezone/files/99-auto-timezone new file mode 100644 index 00000000000000..5b0610d5a44558 --- /dev/null +++ b/utils/auto-timezone/files/99-auto-timezone @@ -0,0 +1,45 @@ +#!/bin/sh + +log() { + logger -t "auto-timezone" "$*" +} + +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 + +endpoint="$(uci -q get auto-timezone.config.endpoint)" +if [ $? -ne 0 ]; then + log "Endpoint not set" + exit 1 +fi + +for i in {1..5}; do + timezone_iana="$(wget --timeout=5 -qO- "${endpoint}")" && break || sleep 1 +done + +if [ -z "$timezone_iana" ]; then + log "Failed to get timezone" + exit 1 +fi + +timezone_posix="$(tail -n1 /usr/share/zoneinfo/${timezone_iana})" +if [ $? -ne 0 ]; then + log "Invalid timezone" + exit 1 +fi + +if [ "${timezone_iana}" != "$(uci get system.@system[0].zonename)" ] || [ "${timezone_posix}" != "$(uci get system.@system[0].timezone)" ]; then + log "Updating timezone, IANA: ${timezone_iana}, POSIX: ${timezone_posix}" + uci set system.@system[0].zonename="${timezone_iana}" + uci set system.@system[0].timezone="${timezone_posix}" + uci commit system + /etc/init.d/system reload + /etc/init.d/cron restart +fi diff --git a/utils/auto-timezone/files/auto-timezone.config b/utils/auto-timezone/files/auto-timezone.config new file mode 100644 index 00000000000000..21552dd7a97c39 --- /dev/null +++ b/utils/auto-timezone/files/auto-timezone.config @@ -0,0 +1 @@ +config auto-timezone 'config' From e059021613f5687572ea9b0d98d19c5733557fff Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Fri, 24 Apr 2026 23:55:46 +0000 Subject: [PATCH 2/7] auto-timezone: add new package fix indentation Signed-off-by: Renn Akaza --- utils/auto-timezone/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/auto-timezone/Makefile b/utils/auto-timezone/Makefile index e4849d5b1cf058..46457d03aa9da1 100644 --- a/utils/auto-timezone/Makefile +++ b/utils/auto-timezone/Makefile @@ -13,7 +13,7 @@ define Package/auto-timezone SECTION:=utils CATEGORY:=Utilities TITLE:=Auto set timezone by IP - PKGARCH:=all + PKGARCH:=all DEPENDS:=+zoneinfo-all endef From 5f190f408acf8231b887c588fee994609b5ab0a8 Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Fri, 24 Apr 2026 23:58:43 +0000 Subject: [PATCH 3/7] auto-timezone: add new package update makefile indentation Signed-off-by: Renn Akaza --- utils/auto-timezone/Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/utils/auto-timezone/Makefile b/utils/auto-timezone/Makefile index 46457d03aa9da1..83be57baaf3909 100644 --- a/utils/auto-timezone/Makefile +++ b/utils/auto-timezone/Makefile @@ -10,29 +10,29 @@ PKG_LICENSE:=GPL-3.0-or-later include $(INCLUDE_DIR)/package.mk define Package/auto-timezone - SECTION:=utils - CATEGORY:=Utilities - TITLE:=Auto set timezone by IP - PKGARCH:=all - DEPENDS:=+zoneinfo-all + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Auto set timezone by IP + PKGARCH:=all + DEPENDS:=+zoneinfo-all endef define Package/auto-timezone/description Hotplug script to automatically configure the timezone UCI settings based on the IP address. The user needs to set their own endpoint to get the IANA timezone string, e.g.: - uci set auto-timezone.config.endpoint="https://domain.tld/json" - uci commit + uci set auto-timezone.config.endpoint="https://domain.tld/json" + uci commit endef define Build/Compile endef define Package/auto-timezone/install - $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/ - $(INSTALL_DATA) ./files/99-auto-timezone $(1)/etc/hotplug.d/iface/ - $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_CONF) ./files/auto-timezone.config $(1)/etc/config/auto-timezone + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/ + $(INSTALL_DATA) ./files/99-auto-timezone $(1)/etc/hotplug.d/iface/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) ./files/auto-timezone.config $(1)/etc/config/auto-timezone endef $(eval $(call BuildPackage,auto-timezone)) From d4af4009ce633648757dc4c5aa4a4eaf24361bcb Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Sat, 25 Apr 2026 00:04:26 +0000 Subject: [PATCH 4/7] auto-timezone: add new package revert makefile's indentation Signed-off-by: Renn Akaza --- utils/auto-timezone/Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/utils/auto-timezone/Makefile b/utils/auto-timezone/Makefile index 83be57baaf3909..46457d03aa9da1 100644 --- a/utils/auto-timezone/Makefile +++ b/utils/auto-timezone/Makefile @@ -10,29 +10,29 @@ PKG_LICENSE:=GPL-3.0-or-later include $(INCLUDE_DIR)/package.mk define Package/auto-timezone - SECTION:=utils - CATEGORY:=Utilities - TITLE:=Auto set timezone by IP - PKGARCH:=all - DEPENDS:=+zoneinfo-all + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Auto set timezone by IP + PKGARCH:=all + DEPENDS:=+zoneinfo-all endef define Package/auto-timezone/description Hotplug script to automatically configure the timezone UCI settings based on the IP address. The user needs to set their own endpoint to get the IANA timezone string, e.g.: - uci set auto-timezone.config.endpoint="https://domain.tld/json" - uci commit + uci set auto-timezone.config.endpoint="https://domain.tld/json" + uci commit endef define Build/Compile endef define Package/auto-timezone/install - $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/ - $(INSTALL_DATA) ./files/99-auto-timezone $(1)/etc/hotplug.d/iface/ - $(INSTALL_DIR) $(1)/etc/config - $(INSTALL_CONF) ./files/auto-timezone.config $(1)/etc/config/auto-timezone + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface/ + $(INSTALL_DATA) ./files/99-auto-timezone $(1)/etc/hotplug.d/iface/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) ./files/auto-timezone.config $(1)/etc/config/auto-timezone endef $(eval $(call BuildPackage,auto-timezone)) From 0db4d54f6c1bb09ca16ee8065b8da0081a2bffb5 Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Sat, 25 Apr 2026 00:06:32 +0000 Subject: [PATCH 5/7] auto-timezone: add new package minor formatting on the script Signed-off-by: Renn Akaza --- utils/auto-timezone/files/99-auto-timezone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/auto-timezone/files/99-auto-timezone b/utils/auto-timezone/files/99-auto-timezone index 5b0610d5a44558..631ec154bdfaa9 100644 --- a/utils/auto-timezone/files/99-auto-timezone +++ b/utils/auto-timezone/files/99-auto-timezone @@ -24,7 +24,7 @@ for i in {1..5}; do timezone_iana="$(wget --timeout=5 -qO- "${endpoint}")" && break || sleep 1 done -if [ -z "$timezone_iana" ]; then +if [ -z "${timezone_iana}" ]; then log "Failed to get timezone" exit 1 fi From bc5ca298d94fda25fe64d9d54b4c7eb7d1bb7e7f Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Sat, 25 Apr 2026 00:07:52 +0000 Subject: [PATCH 6/7] auto-timezone: add new package avoid creating new functions unnecessarily Signed-off-by: Renn Akaza --- utils/auto-timezone/files/99-auto-timezone | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/auto-timezone/files/99-auto-timezone b/utils/auto-timezone/files/99-auto-timezone index 631ec154bdfaa9..0e6c858d3a9be4 100644 --- a/utils/auto-timezone/files/99-auto-timezone +++ b/utils/auto-timezone/files/99-auto-timezone @@ -1,9 +1,5 @@ #!/bin/sh -log() { - logger -t "auto-timezone" "$*" -} - if [ "${INTERFACE}" = "loopback" ]; then exit 0 fi @@ -14,6 +10,10 @@ if [ "${ACTION}" = "ifupdate" ] && [ -z "${IFUPDATE_ADDRESSES}" ] && [ -z "${IFU exit 0 fi +log() { + logger -t "auto-timezone" "$*" +} + endpoint="$(uci -q get auto-timezone.config.endpoint)" if [ $? -ne 0 ]; then log "Endpoint not set" From 6332727c7776b7b4447699714f9c585b2187340c Mon Sep 17 00:00:00 2001 From: Renn Akaza Date: Sun, 26 Apr 2026 22:01:34 +0000 Subject: [PATCH 7/7] auto-timezone: add new package address comments. 1. add log info/error 2. wrap posix timezone convertion in a function 3. update package description Signed-off-by: Renn Akaza --- utils/auto-timezone/Makefile | 7 ++++-- utils/auto-timezone/files/99-auto-timezone | 25 ++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/utils/auto-timezone/Makefile b/utils/auto-timezone/Makefile index 46457d03aa9da1..9b26408ae121a3 100644 --- a/utils/auto-timezone/Makefile +++ b/utils/auto-timezone/Makefile @@ -21,8 +21,11 @@ define Package/auto-timezone/description Hotplug script to automatically configure the timezone UCI settings based on the IP address. The user needs to set their own endpoint to get the IANA timezone string, e.g.: - uci set auto-timezone.config.endpoint="https://domain.tld/json" - uci commit + uci set auto-timezone.config.endpoint="https://domain.tld/timezone" + uci commit auto-timezone + +The endpoint is expected to respond GET requests by a plaintext one-line IANA timezone string, e.g. "Europe/London". +The endpoint can be verified by directly accessing the its URL from a browser by the address bar. endef define Build/Compile diff --git a/utils/auto-timezone/files/99-auto-timezone b/utils/auto-timezone/files/99-auto-timezone index 0e6c858d3a9be4..eed7668acf860c 100644 --- a/utils/auto-timezone/files/99-auto-timezone +++ b/utils/auto-timezone/files/99-auto-timezone @@ -11,12 +11,25 @@ if [ "${ACTION}" = "ifupdate" ] && [ -z "${IFUPDATE_ADDRESSES}" ] && [ -z "${IFU fi log() { - logger -t "auto-timezone" "$*" + logger -t "auto-timezone" "$@" +} + +log_info() { + log -p user.info "$*" +} + +log_error() { + log -p user.err "$*" +} + +get_posix_timezone() { + iana_timezone=$1 + tail -n1 /usr/share/zoneinfo/${iana_timezone} } endpoint="$(uci -q get auto-timezone.config.endpoint)" if [ $? -ne 0 ]; then - log "Endpoint not set" + log_error "Endpoint not set" exit 1 fi @@ -25,18 +38,18 @@ for i in {1..5}; do done if [ -z "${timezone_iana}" ]; then - log "Failed to get timezone" + log_error "Failed to get timezone" exit 1 fi -timezone_posix="$(tail -n1 /usr/share/zoneinfo/${timezone_iana})" +timezone_posix="$(get_posix_timezone ${timezone_iana})" if [ $? -ne 0 ]; then - log "Invalid timezone" + log_error "Invalid timezone" exit 1 fi if [ "${timezone_iana}" != "$(uci get system.@system[0].zonename)" ] || [ "${timezone_posix}" != "$(uci get system.@system[0].timezone)" ]; then - log "Updating timezone, IANA: ${timezone_iana}, POSIX: ${timezone_posix}" + log_info "Updating timezone, IANA: ${timezone_iana}, POSIX: ${timezone_posix}" uci set system.@system[0].zonename="${timezone_iana}" uci set system.@system[0].timezone="${timezone_posix}" uci commit system