Use persistent systemd units for autostart
This commit is contained in:
@@ -1,166 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o nounset
|
||||
# set -x
|
||||
|
||||
selective=0
|
||||
if (( $# > 0 )) ; then
|
||||
selective=1
|
||||
services=("${@}")
|
||||
fi
|
||||
|
||||
do_run() {
|
||||
name="$1"
|
||||
shift
|
||||
|
||||
run=0
|
||||
if (( $selective )) ; then
|
||||
for s in "${services[@]}" ; do
|
||||
if [[ "$s" == "$name" ]] ; then
|
||||
run=1
|
||||
fi
|
||||
done
|
||||
else
|
||||
run=1
|
||||
fi
|
||||
|
||||
return $(( ! $run ))
|
||||
}
|
||||
|
||||
get_unit_name() {
|
||||
name="$1" ; shift
|
||||
printf 'user:%s' "${name}"
|
||||
}
|
||||
|
||||
run_raw() {
|
||||
name="$1"
|
||||
shift
|
||||
|
||||
do_run "$name" || return
|
||||
|
||||
systemd-run \
|
||||
--user \
|
||||
--unit "$(get_unit_name "${name}")" \
|
||||
--no-block \
|
||||
--remain-after-exit \
|
||||
--setenv=DISPLAY=${DISPLAY} \
|
||||
"${@}"
|
||||
}
|
||||
|
||||
run() {
|
||||
name="$1"
|
||||
shift
|
||||
|
||||
run_raw "$name" --property=Restart=always "${@}"
|
||||
}
|
||||
|
||||
run_oneshot_multiple() {
|
||||
name="$1"
|
||||
shift
|
||||
|
||||
cmd=()
|
||||
# hacky way to start two processes in oneshot mode
|
||||
for c in "${@}" ; do
|
||||
cmd+=(--property "ExecStart=/usr/bin/env ${c}")
|
||||
done
|
||||
cmd+=(true)
|
||||
|
||||
run_oneshot "$name" "${cmd[@]}"
|
||||
}
|
||||
|
||||
run_oneshot() {
|
||||
name="$1"
|
||||
shift
|
||||
|
||||
run_raw "$name" --service-type=oneshot "${@}"
|
||||
}
|
||||
|
||||
schedule() {
|
||||
name="$1"; shift
|
||||
do_run "$name" || return
|
||||
systemd-run \
|
||||
--user \
|
||||
--unit "$(get_unit_name "${name}")" \
|
||||
--no-block \
|
||||
--setenv=DISPLAY=${DISPLAY} \
|
||||
"${@}"
|
||||
}
|
||||
|
||||
|
||||
# wallpaper config
|
||||
wallpaper="$LIBDIR/wallpaper/current"
|
||||
|
||||
# keyboard settings
|
||||
keyboard_layout=de
|
||||
keyboard_variant=nodeadkeys
|
||||
keyboard_repeat_delay=150
|
||||
keyboard_repeat_speed=50
|
||||
|
||||
run_oneshot acpi bash -c 'grep "^${ACPI_LID_NAME}.*enabled" /proc/acpi/wakeup && echo " ${ACPI_LID_NAME}" | sudo tee /proc/acpi/wakeup'
|
||||
|
||||
run_oneshot xresources xrdb -merge -I${HOME} ~/.Xresources
|
||||
|
||||
run_oneshot_multiple keyboard \
|
||||
"setxkbmap -layout $keyboard_layout -variant $keyboard_variant" \
|
||||
"xset r rate $keyboard_repeat_delay $keyboard_repeat_speed"
|
||||
|
||||
if [[ "${MACHINE_HAS_TOUCHPAD}" == "true" ]] ; then
|
||||
run_oneshot_multiple touchpad \
|
||||
"synclient VertEdgeScroll=0" \
|
||||
"synclient VertTwoFingerScroll=1" \
|
||||
"synclient MaxSpeed=2.2" \
|
||||
"synclient AccelFactor=0.08" \
|
||||
"synclient TapButton1=1" \
|
||||
"synclient CoastingSpeed=0" \
|
||||
"synclient PalmDetect=1" \
|
||||
"synclient PalmMinWidth=20" \
|
||||
"synclient PalmMinZ=180"
|
||||
fi
|
||||
|
||||
run gpg-agent gpg-agent --homedir "$HOME/.gnupg" --no-detach --daemon
|
||||
|
||||
# run gnome-keyring_user gnome-keyring-daemon --start --components pkcs11,secrets --foreground
|
||||
run kwallet kwalletd5
|
||||
|
||||
# a service called dunst already exists and conflicts
|
||||
run dunst dunst -config ~/.config/dunstrc
|
||||
|
||||
# disabled due to firefox flicker
|
||||
# run compton compton --backend glx --vsync opengl --no-dock-shadow --no-dnd-shadow
|
||||
|
||||
schedule wallpaper --on-active=1s --on-calendar hourly \
|
||||
setrandom --recursive --onlylarge --mode=stretch /usr/share/wallpapers
|
||||
|
||||
run blueman blueman-applet
|
||||
|
||||
run nm-applet nm-applet
|
||||
|
||||
run pasystray pasystray
|
||||
|
||||
# redshift unit already exists
|
||||
run redshift redshift-gtk -c ~/.config/redshift.conf
|
||||
|
||||
run yubikey-touch-detector yubikey-touch-detector -libnotify
|
||||
|
||||
if [[ "${MACHINE_DEFAULT_SCREENPROFILE}" ]] ; then
|
||||
run screencfg "$HOME/.screencfg/${MACHINE_DEFAULT_SCREENPROFILE}.sh"
|
||||
fi
|
||||
|
||||
if [[ "${MACHINE_HAS_KEEPASSX}" == "true" ]] ; then
|
||||
run keepassx keepassx --keyfile ~/.secret/main.key ~/.secret/main.kdbx
|
||||
fi
|
||||
|
||||
if [[ "${MACHINE_HAS_SPOTIFY}" == "true" ]] ; then
|
||||
run spotify spotify
|
||||
fi
|
||||
|
||||
if [[ "${MACHINE_HAS_NEXTCLOUD}" == "true" ]] ; then
|
||||
run nextcloud nextcloud --background
|
||||
fi
|
||||
|
||||
if [[ "${MACHINE_HAS_RESTIC_BACKUP}" == "true" ]] ; then
|
||||
[[ -x ~/bin/restic-backup ]] && schedule restic-backup --on-calendar "Mon..Fri 12:00:00" --on-calendar "Mon..Fri 09:00:00" --on-calendar "Mon..Fri 16:00:00" ~/bin/restic-backup
|
||||
fi
|
||||
|
||||
|
||||
run firefox firefox -P default
|
||||
19
autostart/services/autostart.target
Normal file
19
autostart/services/autostart.target
Normal file
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Wants=blueman.service
|
||||
Wants=dunst.service
|
||||
Wants=firefox.service
|
||||
Wants=gpg-agent.service
|
||||
Wants=keepassx.service
|
||||
Wants=keyboard.service
|
||||
Wants=laptop-lid.service
|
||||
Wants=nextcloud.service
|
||||
Wants=nm-applet.service
|
||||
Wants=pasystray.service
|
||||
Wants=redshift.service
|
||||
Wants=restic.timer
|
||||
Wants=screencfg.service
|
||||
Wants=spotify.service
|
||||
Wants=touchpad.service
|
||||
Wants=wallpaper.timer
|
||||
Wants=xresources.service
|
||||
Wants=yubikey-touch-detector.service
|
||||
5
autostart/services/blueman.service
Normal file
5
autostart/services/blueman.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/blueman-applet
|
||||
5
autostart/services/dunst.service
Normal file
5
autostart/services/dunst.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/dunst -config %h/.config/dunstrc
|
||||
5
autostart/services/firefox.service
Normal file
5
autostart/services/firefox.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/firefox --setDefaultBrowser -P default
|
||||
6
autostart/services/gpg-agent.service
Normal file
6
autostart/services/gpg-agent.service
Normal file
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/usr/bin/gpg-agent --homedir %h/.gnupg --no-detach --daemon
|
||||
6
autostart/services/keepassx.service
Normal file
6
autostart/services/keepassx.service
Normal file
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
ConditionEnvironment=MACHINE_HAS_KEEPASSX=true
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/keepassx --keyfile %h/.secret/main.key %h/.secret/main.kdbx
|
||||
8
autostart/services/keyboard.service
Normal file
8
autostart/services/keyboard.service
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/setxkbmap -layout de -variant nodeadkeys
|
||||
ExecStart=/usr/bin/xset r rate 150 50
|
||||
RemainAfterExit=true
|
||||
7
autostart/services/laptop-lid.service
Normal file
7
autostart/services/laptop-lid.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
ConditionEnvironment=MACHINE_TYPE=laptop
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/bash -c 'grep "^${ACPI_LID_NAME}.*enabled" /proc/acpi/wakeup && echo " ${ACPI_LID_NAME}" | sudo tee /proc/acpi/wakeup'
|
||||
7
autostart/services/nextcloud.service
Normal file
7
autostart/services/nextcloud.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
ConditionEnvironment=MACHINE_HAS_NEXTCLOUD=true
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/nextcloud --background
|
||||
5
autostart/services/nm-applet.service
Normal file
5
autostart/services/nm-applet.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/nm-applet
|
||||
5
autostart/services/pasystray.service
Normal file
5
autostart/services/pasystray.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/pasystray
|
||||
5
autostart/services/redshift.service
Normal file
5
autostart/services/redshift.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/redshift-gtk -c %h/.config/redshift.conf
|
||||
7
autostart/services/restic.service
Normal file
7
autostart/services/restic.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
ConditionEnvironment=MACHINE_HAS_RESTIC_BACKUP=true
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=%h/bin/restic-backup
|
||||
RemainAfterExit=true
|
||||
7
autostart/services/restic.timer
Normal file
7
autostart/services/restic.timer
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Mon..Fri 09:00:00
|
||||
OnCalendar=Mon..Fri 12:00:00
|
||||
OnCalendar=Mon..Fri 16:00:00
|
||||
12
autostart/services/screencfg.service
Normal file
12
autostart/services/screencfg.service
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
ConditionEnvironment=MACHINE_DEFAULT_SCREENPROFILE
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
# systemd.service(5):
|
||||
|
||||
# > The command to execute may contain spaces, but control characters are not
|
||||
# > allowed.
|
||||
ExecStart=bash -c '%h/.screencfg/${MACHINE_DEFAULT_SCREENPROFILE}.sh'
|
||||
RemainAfterExit=true
|
||||
5
autostart/services/spotify.service
Normal file
5
autostart/services/spotify.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/spotify
|
||||
16
autostart/services/touchpad.service
Normal file
16
autostart/services/touchpad.service
Normal file
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
ConditionEnvironment=MACHINE_TYPE=laptop
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/synclient VertEdgeScroll=0
|
||||
ExecStart=/usr/bin/synclient VertTwoFingerScroll=1
|
||||
ExecStart=/usr/bin/synclient MaxSpeed=2.2
|
||||
ExecStart=/usr/bin/synclient AccelFactor=0.08
|
||||
ExecStart=/usr/bin/synclient TapButton1=1
|
||||
ExecStart=/usr/bin/synclient CoastingSpeed=0
|
||||
ExecStart=/usr/bin/synclient PalmDetect=1
|
||||
ExecStart=/usr/bin/synclient PalmMinWidth=20
|
||||
ExecStart=/usr/bin/synclient PalmMinZ=1
|
||||
RemainAfterExit=true
|
||||
4
autostart/services/wallpaper.service
Normal file
4
autostart/services/wallpaper.service
Normal file
@@ -0,0 +1,4 @@
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/setrandom --recursive --onlylarge --mode=stretch /usr/share/wallpapers
|
||||
RemainAfterExit=true
|
||||
8
autostart/services/wallpaper.timer
Normal file
8
autostart/services/wallpaper.timer
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Timer]
|
||||
OnActiveSec=0s
|
||||
OnCalendar=hourly
|
||||
Unit=wallpaper.service
|
||||
RemainAfterElapse=true
|
||||
7
autostart/services/xresources.service
Normal file
7
autostart/services/xresources.service
Normal file
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/xrdb -merge -I%h %h/.Xresources
|
||||
RemainAfterExit=true
|
||||
5
autostart/services/yubikey-touch-detector.service
Normal file
5
autostart/services/yubikey-touch-detector.service
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
BindsTo=autostart.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/yubikey-touch-detector -libnotify
|
||||
Reference in New Issue
Block a user