85 lines
1.6 KiB
Bash
Executable file
85 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
base_dir="$HOME/.config/systemd/user/"
|
|
|
|
_filename () {
|
|
echo "autostart-$1.service"
|
|
}
|
|
|
|
_systemctl () {
|
|
systemctl --user "${@:2}" "$(_filename "$1")"
|
|
}
|
|
|
|
_list () {
|
|
systemctl --user list-unit-files \
|
|
| grep "autostart-" \
|
|
| awk '{print $1}' \
|
|
| sed -e 's/^autostart-//' -e 's/.service$//'
|
|
}
|
|
|
|
_echo_table () {
|
|
printf "Unit\tFilename\tStatus\n"
|
|
for unit in "$@"
|
|
do
|
|
printf "%s\t%s\t%s\n" \
|
|
"$unit" \
|
|
"$(_filename "$unit")" \
|
|
"$(_systemctl "$unit" is-enabled)"
|
|
done
|
|
}
|
|
|
|
_autostart_manage_add () {
|
|
cat <<EOF >"$base_dir$(_filename "$1")"
|
|
[Unit]
|
|
Description=$1
|
|
|
|
[Service]
|
|
ExecStart=$2
|
|
EOF
|
|
}
|
|
|
|
_autostart_manage_list () {
|
|
_list
|
|
}
|
|
|
|
_autostart_manage_info () {
|
|
autostart_units=()
|
|
while IFS='' read -r line
|
|
do
|
|
autostart_units+=("$line")
|
|
done < <(_list)
|
|
|
|
_echo_table "${autostart_units[@]}" | column -t -s$'\t'
|
|
}
|
|
|
|
_autostart_manage_enable_all () {
|
|
autostart_units=()
|
|
while IFS='' read -r line
|
|
do
|
|
autostart_units+=("$line")
|
|
done < <(_list)
|
|
|
|
for unit in "${autostart_units[@]}"
|
|
do
|
|
_systemctl "$unit" add-wants autostart.target
|
|
done
|
|
}
|
|
|
|
_autostart_manage_rm () {
|
|
rm "$base_dir$(_filename "$1")"
|
|
}
|
|
|
|
case $1 in
|
|
list) _autostart_manage_list ;;
|
|
info) _autostart_manage_info ;;
|
|
add) _autostart_manage_add "$2" "$3" ;;
|
|
rm) _autostart_manage_rm "$2" ;;
|
|
enable-all) _autostart_manage_enable_all "$2" ;;
|
|
show) _systemctl "$2" cat ;;
|
|
edit) _systemctl "$2" edit --full ;;
|
|
enable) _systemctl "$2" add-wants autostart.target ;;
|
|
disable) _systemctl "$2" disable ;;
|
|
status) _systemctl "${2:-*}" status ;;
|
|
start) systemctl --user start autostart.target ;;
|
|
*) echo "'$1' is not valid" ;;
|
|
esac
|