-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
195 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,52 @@ | ||
#!/bin/sh | ||
|
||
if [ "$2" = "up" ]; then | ||
TIMEZONE=$(tzupdate -p) | ||
SYS_TZ=$(tzupdate --print-sys) | ||
|
||
if [ "$TIMEZONE" = "$SYS_TZ" ]; then | ||
echo "Timezone unchanged" | ||
exit | ||
fi | ||
|
||
GDBUS_DEST="org.freedesktop.Notifications" | ||
GDBUS_OBJ_PATH="/org/freedesktop/Notifications" | ||
GDBUS_ARGS="--session --dest $GDBUS_DEST --object-path $GDBUS_OBJ_PATH" | ||
|
||
NOTIFY_METHOD="--method org.freedesktop.Notifications.Notify" | ||
NOTIF_SUMMARY="'Change timezone to $TIMEZONE ?'" | ||
NOTIF_ACTIONS="'[\"changetz\", \"Yes\"]'" | ||
NOTIF_HINTS="'{\"urgency\": <byte 1>}'" | ||
NOTIF_ARGS="tzupdate 0 '' $NOTIF_SUMMARY '' $NOTIF_ACTIONS $NOTIF_HINTS 'int32 -1'" | ||
SEND_NOTIF="gdbus call $GDBUS_ARGS $NOTIFY_METHOD $NOTIF_ARGS" | ||
|
||
RECIEVE_ACTION="gdbus monitor $GDBUS_ARGS" | ||
NOTIF_REGEXP="^$GDBUS_OBJ_PATH: $GDBUS_DEST.\\(.*\\)$" | ||
|
||
GDBUS_MONITOR_PID=$(mktemp) | ||
|
||
USER=$(who | awk -v vt=tty"$(fgconsole)" '$0 ~ vt {print $1}') | ||
DISPLAY=$(w --from "$USER" | awk -F ' +' 'END{print $2}') | ||
XAUTHORITY=$(eval echo ~"$USER"/.Xauthority) | ||
|
||
export DISPLAY | ||
export XAUTHORITY | ||
eval "$(dbus-launch --auto-syntax)" | ||
|
||
NOTIF_ID=$(eval "$SEND_NOTIF" | sed 's/(uint32 \([0-9]\+\),)/\1/g') | ||
NOTIF_CLOSE_REGEXP="^NotificationClosed (uint32 $NOTIF_ID, uint32 [0-9]\+)$" | ||
|
||
( $RECIEVE_ACTION & echo $! >&3 ) 3>"$GDBUS_MONITOR_PID" | while read -r signal | ||
do | ||
recv="$(printf '%s' "$signal" | sed "s~$NOTIF_REGEXP~\\1~")" | ||
if printf '%s' "$recv" | grep "$NOTIF_CLOSE_REGEXP" >/dev/null 2>&1; then | ||
break | ||
fi | ||
if [ "$recv" = "ActionInvoked (uint32 $NOTIF_ID, 'changetz')" ]; then | ||
tzupdate -t "$TIMEZONE" | ||
break | ||
fi | ||
done | ||
kill "$(cat "$GDBUS_MONITOR_PID")" | ||
rm -f "$GDBUS_MONITOR_PID" | ||
fi |
This file contains 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,9 @@ | ||
Automatic timezone change detection with NetworkManager | ||
======================================================= | ||
|
||
The ``09-timezone`` script can be placed in the | ||
``/etc/NetworkManager/dispatcher.d/`` folder. This script will automatically | ||
launch tzupdate upon network connection. The user will therefore be prompted to | ||
change the system timezone whenever the system connects to a network in a | ||
different timezone. You also need a notification server with action support | ||
like ``xfce4-notifyd`` for instance. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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