Improve autostart script

This commit is contained in:
Tobias Reisinger 2023-07-01 16:34:53 +02:00
parent 32a6ce75bd
commit cf24c298e1
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 43 additions and 24 deletions

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash
hostname=$(cat /proc/sys/kernel/hostname)
_systemctl () {
systemctl --user "${@:2}" "autostart@$1.service"
}
@ -10,15 +12,19 @@ _dasel () {
_list () {
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" \
part_host="all().filter(equal(type(),object)).filter(equal(key(),$hostname)).all().key()"
query="merge($part_host,$part_root).all()"
programs=$(_dasel "$query" \
| sort \
| uniq
#systemctl --user list-unit-files \
# | grep "autostart-" \
# | awk '{print $1}' \
# | sed -e 's/^autostart-//' -e 's/.service$//'
| uniq)
for program in $programs
do
cmd=$(_get_autostart_cmd "$program")
if [ -n "$cmd" ]; then
echo "$program"
fi
done
}
_echo_table () {
@ -49,7 +55,9 @@ _autostart_manage_log () {
journalctl --user -fu "autostart@$1.service"
}
_autostart_manage_enable_all () {
_autostart_manage_sync () {
rm "$HOME/.config/systemd/user/autostart.target.wants/"*
autostart_units=()
while IFS='' read -r line
do
@ -63,8 +71,6 @@ _autostart_manage_enable_all () {
}
_get_autostart_cmd () {
hostname=$(cat /proc/sys/kernel/hostname)
selector_base="all()"
selector_host="all().filter(equal(type(),object)).filter(equal(key(),$hostname)).all()"
selector_entry="filter(not(equal(type(),object))).filter(equal(key(),$1))"
@ -126,7 +132,7 @@ _autostart_run_xorg () {
case $1 in
list) _autostart_manage_list ;;
info) _autostart_manage_info ;;
enable-all) _autostart_manage_enable_all "$2" ;;
sync) _autostart_manage_sync ;;
enable) _systemctl "$2" add-wants autostart.target ;;
disable) _systemctl "$2" disable ;;
restart) _systemctl "${2:-*}" restart;;