-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandrocontrol-notify
More file actions
executable file
·38 lines (36 loc) · 1.62 KB
/
Copy pathandrocontrol-notify
File metadata and controls
executable file
·38 lines (36 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
# androcontrol-notify — desktop notifications for AndroControl connect/disconnect.
#
# The AndroControl server runs sandboxed as a dedicated system user and can't reach a
# graphical session, so notifications are delivered from the user's side: this script
# tails the service journal and pops a libnotify desktop notification on each
# connect/disconnect. Run it as a systemd --user service inside your graphical session.
#
# Requirements: systemd-journald, libnotify (notify-send), and a running notification
# daemon. Your user must be able to read the service journal (member of the
# systemd-journal / wheel / adm group).
#
# Install (any systemd distro):
# install -Dm755 androcontrol-notify ~/.local/bin/androcontrol-notify
# install -Dm644 androcontrol-notify.service ~/.config/systemd/user/androcontrol-notify.service
# systemctl --user daemon-reload
# systemctl --user enable --now androcontrol-notify
#
# Env:
# ANDROCONTROL_UNIT systemd unit to watch (default: androcontrol)
set -u
UNIT="${ANDROCONTROL_UNIT:-androcontrol}"
journalctl -u "$UNIT" -f -n0 -o cat | while IFS= read -r line; do
case "$line" in
*"[AUDIT] auth_ok "*|*"[AUDIT] pair_ok "*)
dev=$(printf '%s' "$line" | sed -n 's/.*device="\([^"]*\)".*/\1/p')
[ -n "$dev" ] || dev="New device"
ip=$(printf '%s' "$line" | sed -n 's/.*ip=\([0-9.]*\).*/\1/p')
notify-send -a AndroControl "Device connected" "$dev ($ip)" || true
;;
*"[AUDIT] disconnect "*)
dev=$(printf '%s' "$line" | sed -n 's/.*device="\([^"]*\)".*/\1/p')
notify-send -a AndroControl "Device disconnected" "$dev" || true
;;
esac
done