blob: 2317256014858c197147cdaf7603ef2d19b6000b (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/bin/sh
# Waybar custom/update: gentle reminder that the system hasn't been
# upgraded recently. Source of truth is /var/log/pacman.log — the last
# "[PACMAN] starting full system upgrade" entry. No daemon, no -Sy
# polling, no opinion about *which* updates are pending; this only
# tracks whether you've run `paru -Syu` (or equivalent) lately.
#
# States, by hours since last full upgrade:
# < 24h empty (hidden via :empty rule in style.css)
# 24h – 168h warn → yellow icon + normal-urgency mako once/24h
# ≥ 168h (7d) critical → red icon + critical mako once/24h
#
# The mako notification is throttled by a stamp file in $XDG_RUNTIME_DIR
# so reboots reset it (post-reboot is a fine moment to be reminded).
set -eu
LOG=/var/log/pacman.log
STATE=${XDG_RUNTIME_DIR:-/tmp}/waybar-update-notified
emit_empty() {
printf '{"text":"","class":"fresh","tooltip":""}\n'
exit 0
}
[ -r "$LOG" ] || emit_empty
# Pacman log lines look like: [2026-05-07T08:30:00+0000] [PACMAN] starting full system upgrade
last=$(grep -F '[PACMAN] starting full system upgrade' "$LOG" |
tail -n1 |
sed -n 's/^\[\([^]]*\)\].*/\1/p')
[ -n "$last" ] || emit_empty
last_epoch=$(date -d "$last" +%s 2>/dev/null) || emit_empty
now=$(date +%s)
elapsed=$((now - last_epoch))
hours=$((elapsed / 3600))
days=$((hours / 24))
[ "$hours" -lt 24 ] && emit_empty
# Tier + human-friendly duration
if [ "$days" -ge 7 ]; then
state=critical
urgency=critical
else
state=warn
urgency=normal
fi
if [ "$days" -ge 2 ]; then
ago="${days}d"
elif [ "$days" -ge 1 ]; then
ago="1d"
else
ago="${hours}h"
fi
text=" ${ago}"
tooltip="System upgrade last ran ${ago} ago — click to run \`just update\`"
printf '{"text":"%s","class":"%s","tooltip":"%s"}\n' "$text" "$state" "$tooltip"
# Throttle mako: at most one reminder per 24h.
last_notified=0
if [ -f "$STATE" ]; then
last_notified=$(cat "$STATE" 2>/dev/null || printf 0)
case "$last_notified" in
'' | *[!0-9]*) last_notified=0 ;;
esac
fi
if [ $((now - last_notified)) -ge 86400 ] &&
command -v notify-send >/dev/null 2>&1; then
notify-send \
--app-name=system-update \
--urgency="$urgency" \
--icon=system-software-update \
"System upgrade reminder" \
"Last upgrade: ${ago} ago. Run \`just update\` when convenient."
printf '%s\n' "$now" >"$STATE"
fi
|