-
Notifications
You must be signed in to change notification settings - Fork 3.9k
auto-timezone: add new package #29233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AkazaRenn
wants to merge
9
commits into
openwrt:master
Choose a base branch
from
AkazaRenn:auto-timezone
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c6ef02
auto-timezone: add new package
7f0186f
auto-timezone: add new package
68b0a81
auto-timezone: add new package
3b65b06
auto-timezone: add new package
65b0686
auto-timezone: add new package
d8736c7
auto-timezone: add new package
fb28b00
Merge branch 'master' into auto-timezone
AkazaRenn 1dbe849
auto-timezone: add new package
651325f
Merge branch 'master' into auto-timezone
AkazaRenn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| include $(TOPDIR)/rules.mk | ||
|
|
||
| PKG_NAME:=auto-timezone | ||
| PKG_VERSION:=1.0.0 | ||
| PKG_RELEASE:=1 | ||
|
|
||
| PKG_MAINTAINER:=Renn Akaza <openwrt.org-auto-timezone@akaza.ren> | ||
| 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/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 | ||
| 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)) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/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 | ||
|
|
||
| log() { | ||
| 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_error "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_error "Failed to get timezone" | ||
| exit 1 | ||
| fi | ||
|
|
||
| timezone_posix="$(get_posix_timezone ${timezone_iana})" | ||
| if [ $? -ne 0 ]; then | ||
| 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_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 | ||
| /etc/init.d/system reload | ||
| /etc/init.d/cron restart | ||
| fi | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| config auto-timezone 'config' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would pass
priorityas well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added two functions
log_infoandlog_errorto handle the priorities in 1dbe849.