-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaxos-reboot-required
More file actions
95 lines (80 loc) · 2.61 KB
/
axos-reboot-required
File metadata and controls
95 lines (80 loc) · 2.61 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
## Copyright (C) 2024 Ardox
# Avoid unnecessary reboots: don't notify if an updated package is
# - not currently running (e.g. alternative kernel)
# - not in use (e.g. alternative driver)
## Colors ----------------------------
# Text Reset
Color_Off='\033[0m'
# Bold Colors
BBlack='\033[1;30m' BRed='\033[1;31m' BGreen='\033[1;32m' BYellow='\033[1;33m'
BBlue='\033[1;34m' BPurple='\033[1;35m' BCyan='\033[1;36m' BWhite='\033[1;37m'
## -----------------------------------
_notify_reboot_required() {
local xx
for xx in "$XDG_CURRENT_DESKTOP"; do
if [[ -n "$xx" ]] ; then
break
fi
done
if [[ -n "$xx" ]] ; then
local user userid cmd
for user in $(/usr/bin/users) ; do
userid=$(/usr/bin/id -u $user)
cmd=(DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$userid/bus /usr/bin/notify-send)
cmd+=(--icon=system-reboot --urgency=critical)
cmd+=("\"Core system package upgraded, You need to reboot the machine.\"")
/usr/bin/su $user -c "${cmd[*]}"
done
else
# at TTY
echo -e ${BRed}"\n[AxOS] Core system package upgraded, You need to reboot the machine.\n"${Color_Off} >&2
fi
}
RunningKernel() {
cat /proc/cmdline | sed 's|.*/vmlinuz-\(linux[a-z0-9-]*\) .*|\1|'
}
main() {
local targets=$(tee /dev/null) # targets from the hook (stdin)
local target
local notify=no
local runningKernel="$(RunningKernel)"
for target in $targets ; do
case "$target" in
linux | linux-lts | linux-zen | linux-hardened | linux-lts?? | linux-lts???)
# Note: only official and older LTS kernels are checked.
if [[ "$target" = "$runningKernel" ]] ; then
notify=yes
break
fi
;;
nvidia)
if [[ "$runningKernel" = "linux" ]] ; then
notify=yes
break
fi
;;
nvidia-lts)
if [[ "$runningKernel" = "linux-lts" ]] ; then
notify=yes
break
fi
;;
btrfs-progs)
if [[ -n "$(/usr/bin/df -hT | awk '{print $2}' | grep -w btrfs)" ]] ; then
notify=yes
break
fi
;;
*)
notify=yes
break
;;
esac
done
if [[ "$notify" = "yes" ]] ; then
_notify_reboot_required
unset -f _notify_reboot_required
fi
}
main "$@"