-
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
10
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.
+100
−0
Open
Changes from 7 commits
Commits
Show all changes
10 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 12e5aa6
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,38 @@ | ||
| 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/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)) | ||
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,45 @@ | ||
| #!/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() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would pass
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added two functions |
||
| logger -t "auto-timezone" "$*" | ||
| } | ||
|
|
||
| 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})" | ||
|
pprindeville marked this conversation as resolved.
Outdated
|
||
| 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}" | ||
|
pprindeville marked this conversation as resolved.
Outdated
|
||
| 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.
Could this be made more clear?
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 updated the description on the expected response from the endpoint in 1dbe849. Please let me know if you expect something else.