#!/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