.dotfiles/.bin/autostart-manage

128 lines
2.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2022-10-13 14:08:14 +00:00
2023-02-02 18:55:18 +00:00
_systemctl () {
systemctl --user "${@:2}" "autostart@$1.service"
2022-10-13 14:08:14 +00:00
}
2023-02-02 18:55:18 +00:00
_dasel () {
dasel -f "$HOME/.config/autostart.toml" -r toml "${@}"
2022-10-13 14:08:14 +00:00
}
2022-10-13 21:50:13 +00:00
_list () {
2023-02-02 18:55:18 +00:00
part_root='all().filter(not(equal(type(),object))).key()'
part_host='all().filter(equal(type(),object)).all().key()'
arg="merge($part_host,$part_root).all()"
_dasel "$arg" \
| sort \
| uniq
#systemctl --user list-unit-files \
# | grep "autostart-" \
# | awk '{print $1}' \
# | sed -e 's/^autostart-//' -e 's/.service$//'
2022-10-13 21:50:13 +00:00
}
2022-10-13 14:08:14 +00:00
_echo_table () {
for unit in "$@"
do
2023-02-02 18:55:18 +00:00
printf "%s\t%s\t%s\n" \
2022-10-13 14:08:14 +00:00
"$unit" \
2022-12-16 20:46:19 +00:00
"$(_systemctl "$unit" is-enabled)" \
"$(_systemctl "$unit" is-active)"
2022-10-13 14:08:14 +00:00
done
}
_autostart_manage_list () {
2022-10-13 21:50:13 +00:00
_list
2022-10-13 14:08:14 +00:00
}
_autostart_manage_info () {
2022-10-17 16:49:58 +00:00
autostart_units=()
while IFS='' read -r line
do
autostart_units+=("$line")
done < <(_list)
2023-02-02 18:55:18 +00:00
_echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?'
2022-10-13 14:08:14 +00:00
}
2022-10-13 21:50:13 +00:00
_autostart_manage_enable_all () {
2022-10-17 16:49:58 +00:00
autostart_units=()
while IFS='' read -r line
do
autostart_units+=("$line")
done < <(_list)
2022-10-13 21:50:13 +00:00
for unit in "${autostart_units[@]}"
do
_systemctl "$unit" add-wants autostart.target
done
2022-10-13 14:08:14 +00:00
}
2023-02-02 18:55:18 +00:00
_get_autostart_cmd () {
hostname=$(cat /proc/sys/kernel/hostname)
2023-02-02 18:55:18 +00:00
selector_base="all()"
selector_host="all().filter(equal(type(),object)).filter(equal(key(),$hostname)).all()"
2023-02-02 18:55:18 +00:00
selector_entry="filter(not(equal(type(),object))).filter(equal(key(),$1))"
cmd=$(_dasel "$selector_base.$selector_entry")
cmd_local=$(_dasel "$selector_host.$selector_entry")
if [ -n "$cmd_local" ]; then
if [ "$cmd_local" = "false" ]; then
cmd=""
else
cmd="$cmd_local"
fi
fi
echo "$cmd"
}
_autostart_manage_exec () {
cmd=$(_get_autostart_cmd "$1")
bash -c "$cmd"
2022-10-13 14:08:14 +00:00
}
2022-12-29 13:46:34 +00:00
_autostart_run_xorg () {
feh --bg-fill "$XDG_PICTURES_DIR/wallpaper/active_wallpaper"
"$HOME/.config/polybar/launch.sh" &
"$HOME/.config/bspwm/focus-voip.py" &
numlockx on
2023-02-02 18:55:18 +00:00
xsetroot -cursor_name left_ptr
2022-12-29 13:46:34 +00:00
xrdb "$HOME/.Xresources"
2023-02-02 18:55:18 +00:00
#pkill sxhkd; sxhkd &
#pgrep -x xcompmgr > /dev/null || xcompmgr -cnfFn -D3 &
2022-12-29 13:46:34 +00:00
start-audio pipewire
wait-for-service "network-online.target"
if ! pgrep -x keepassxc
then
pass x
(pass keepass | head -n 1 | keepassxc --pw-stdin ~/sync/passwords.kdbx) &
fi
autoinstall graphical
autostart-manage run
}
2022-10-13 14:08:14 +00:00
case $1 in
list) _autostart_manage_list ;;
info) _autostart_manage_info ;;
2022-10-13 21:50:13 +00:00
enable-all) _autostart_manage_enable_all "$2" ;;
enable) _systemctl "$2" add-wants autostart.target ;;
2022-10-27 13:55:18 +00:00
disable) _systemctl "$2" disable ;;
2022-12-16 20:46:19 +00:00
restart) _systemctl "${2:-*}" restart;;
start) _systemctl "${2:-*}" start;;
2022-10-24 14:57:31 +00:00
status) _systemctl "${2:-*}" status ;;
2022-12-16 20:46:19 +00:00
stop) _systemctl "${2:-*}" stop ;;
run) systemctl --user start autostart.target ;;
2022-12-29 13:46:34 +00:00
run-xorg) _autostart_run_xorg ;;
2023-02-02 18:55:18 +00:00
exec) _autostart_manage_exec "$2" ;;
2022-10-13 14:08:14 +00:00
*) echo "'$1' is not valid" ;;
esac