-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreload
More file actions
executable file
·115 lines (93 loc) · 2.85 KB
/
reload
File metadata and controls
executable file
·115 lines (93 loc) · 2.85 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/sh
# @author nate zhou
# @since 2025,2026
# reload - generic script to reload stuff
# This script has completions: `.config/{z,ba}sh/completions/_scripts.{z,ba}sh`
usage() {
cat << _EOF_
USAGE
$(basename $0) [OPTION]...
Without any options, default to reloading cronjobs
OPTIONS
-c,--cronjobs reload cronjob scripts(default)
-f,--damblocks-fifo
reload damblocks (fifo)
-x,--damblocks-xsetroot
reload damblocks (xsetroot)
-m,--module [module]...
reload kernel modules
-k,--kwm reload kwm under river
-h,--help print this usage manual
_EOF_
exit 0
}
reload_cronjobs() {
pids=""
notify-send -r 55 "$(basename $0) ($(date +'%H:%M'))" "Running resume hooks"
cleanup() {
trap - EXIT INT TERM # reset traps
[ -n "$pids" ] && kill $pids 2>/dev/null # kill bg jobs
# Don't use `kill -- -$$`:
# man 1 kill:
# > When an argument of the form '-n' is given, and it is
# > meant to denote a process group, either a signal must be
# > specified first, or the argument must be preceded by a '--'
# > option, otherwise it will be taken as the signal to send.
# because it kills the whole process group, including the parent shell;
# when the shell receives SIGTERM from cleanup(), it re-triggers the
# trap, therefore the shell gets a segmentation fault (core dumped).
# Instead, collect individual PIDs of background jobs and only kill the
# specific PIDs in `cleanup()`.
}
trap cleanup INT TERM EXIT
${HOME}/.local/bin/lucia -d
${HOME}/.local/bin/updw >/dev/null 2>&1 &
pids="$pids $!"
${HOME}/.local/bin/checkupdates-cron >/dev/null 2>&1 --now &
pids="$pids $!"
${HOME}/.local/bin/newsboat-update-cron >/dev/null 2>&1 --now &
pids="$pids $!"
${HOME}/.local/bin/calcurse-num-cron >/dev/null 2>&1 --now &
pids="$pids $!"
${HOME}/.local/bin/mbs >/dev/null 2>&1 &
pids="$pids $!"
wait
}
reload_damblocks() {
killall damblocks
${HOME}/.local/bin/damblocks "$1" &
killall -q mpc
${HOME}/.local/bin/damblocks-mpdd &
}
reload_module() {
sudo modprobe -r $@ && sudo modprobe $@
}
reload_kwm() {
pkill -x kwm
nohup kwm >/dev/null &
}
[ -z "$1" ] && reload_cronjobs
while [ -n "$1" ]; do
case "$1" in
-c|--cronjobs)
reload_cronjobs
;;
-f|--damblocks-fifo)
reload_damblocks --fifo
;;
-x|--damblocks-xsetroot)
reload_damblocks --xsetroot
;;
-m|--module)
shift
reload_module $@
;;
-k|--kwm)
reload_kwm
;;
-h|--help)
usage
;;
esac
shift
done