diff --git a/_machines/ares.yml b/_machines/ares.yml index 6ad0e1d..1223eda 100644 --- a/_machines/ares.yml +++ b/_machines/ares.yml @@ -33,9 +33,8 @@ screen: workspace: environment: + MACHINE_TYPE: "workstation" MACHINE_HAS_KEEPASSX: "false" MACHINE_HAS_NEXTCLOUD: "true" MACHINE_HAS_RESTIC_BACKUP: "false" - MACHINE_HAS_SPOTIFY: "true" - MACHINE_HAS_TOUCHPAD: "false" MACHINE_DEFAULT_SCREENPROFILE: "ares" diff --git a/_machines/tb-hak.yml b/_machines/tb-hak.yml index 75ac186..a43766f 100644 --- a/_machines/tb-hak.yml +++ b/_machines/tb-hak.yml @@ -48,7 +48,6 @@ workspace: 10: pim environment: + MACHINE_TYPE: "laptop" MACHINE_HAS_KEEPASSX: "true" MACHINE_HAS_RESTIC_BACKUP: "true" - MACHINE_HAS_SPOTIFY: "true" - MACHINE_HAS_TOUCHPAD: "true" diff --git a/autostart/autostart.sh b/autostart/autostart.sh deleted file mode 100755 index d329151..0000000 --- a/autostart/autostart.sh +++ /dev/null @@ -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 diff --git a/autostart/services/autostart.target b/autostart/services/autostart.target new file mode 100644 index 0000000..5954f7d --- /dev/null +++ b/autostart/services/autostart.target @@ -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 diff --git a/autostart/services/blueman.service b/autostart/services/blueman.service new file mode 100644 index 0000000..20801a9 --- /dev/null +++ b/autostart/services/blueman.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/blueman-applet diff --git a/autostart/services/dunst.service b/autostart/services/dunst.service new file mode 100644 index 0000000..2764e5b --- /dev/null +++ b/autostart/services/dunst.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/dunst -config %h/.config/dunstrc diff --git a/autostart/services/firefox.service b/autostart/services/firefox.service new file mode 100644 index 0000000..5e97d02 --- /dev/null +++ b/autostart/services/firefox.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/firefox --setDefaultBrowser -P default diff --git a/autostart/services/gpg-agent.service b/autostart/services/gpg-agent.service new file mode 100644 index 0000000..50c97a6 --- /dev/null +++ b/autostart/services/gpg-agent.service @@ -0,0 +1,6 @@ +[Unit] +BindsTo=autostart.target + +[Service] +Type=forking +ExecStart=/usr/bin/gpg-agent --homedir %h/.gnupg --no-detach --daemon diff --git a/autostart/services/keepassx.service b/autostart/services/keepassx.service new file mode 100644 index 0000000..230cb96 --- /dev/null +++ b/autostart/services/keepassx.service @@ -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 diff --git a/autostart/services/keyboard.service b/autostart/services/keyboard.service new file mode 100644 index 0000000..45a5735 --- /dev/null +++ b/autostart/services/keyboard.service @@ -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 diff --git a/autostart/services/laptop-lid.service b/autostart/services/laptop-lid.service new file mode 100644 index 0000000..893bb07 --- /dev/null +++ b/autostart/services/laptop-lid.service @@ -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' diff --git a/autostart/services/nextcloud.service b/autostart/services/nextcloud.service new file mode 100644 index 0000000..c145821 --- /dev/null +++ b/autostart/services/nextcloud.service @@ -0,0 +1,7 @@ +[Unit] +BindsTo=autostart.target + +ConditionEnvironment=MACHINE_HAS_NEXTCLOUD=true + +[Service] +ExecStart=/usr/bin/nextcloud --background diff --git a/autostart/services/nm-applet.service b/autostart/services/nm-applet.service new file mode 100644 index 0000000..2832b60 --- /dev/null +++ b/autostart/services/nm-applet.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/nm-applet diff --git a/autostart/services/pasystray.service b/autostart/services/pasystray.service new file mode 100644 index 0000000..a7e1892 --- /dev/null +++ b/autostart/services/pasystray.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/pasystray diff --git a/autostart/services/redshift.service b/autostart/services/redshift.service new file mode 100644 index 0000000..b40ba28 --- /dev/null +++ b/autostart/services/redshift.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/redshift-gtk -c %h/.config/redshift.conf diff --git a/autostart/services/restic.service b/autostart/services/restic.service new file mode 100644 index 0000000..62a3ce5 --- /dev/null +++ b/autostart/services/restic.service @@ -0,0 +1,7 @@ +[Unit] +ConditionEnvironment=MACHINE_HAS_RESTIC_BACKUP=true + +[Service] +Type=oneshot +ExecStart=%h/bin/restic-backup +RemainAfterExit=true diff --git a/autostart/services/restic.timer b/autostart/services/restic.timer new file mode 100644 index 0000000..4bb9055 --- /dev/null +++ b/autostart/services/restic.timer @@ -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 diff --git a/autostart/services/screencfg.service b/autostart/services/screencfg.service new file mode 100644 index 0000000..6130875 --- /dev/null +++ b/autostart/services/screencfg.service @@ -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 diff --git a/autostart/services/spotify.service b/autostart/services/spotify.service new file mode 100644 index 0000000..417b339 --- /dev/null +++ b/autostart/services/spotify.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/spotify diff --git a/autostart/services/touchpad.service b/autostart/services/touchpad.service new file mode 100644 index 0000000..e20d137 --- /dev/null +++ b/autostart/services/touchpad.service @@ -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 diff --git a/autostart/services/wallpaper.service b/autostart/services/wallpaper.service new file mode 100644 index 0000000..b4d0ac2 --- /dev/null +++ b/autostart/services/wallpaper.service @@ -0,0 +1,4 @@ +[Service] +Type=oneshot +ExecStart=/usr/bin/setrandom --recursive --onlylarge --mode=stretch /usr/share/wallpapers +RemainAfterExit=true diff --git a/autostart/services/wallpaper.timer b/autostart/services/wallpaper.timer new file mode 100644 index 0000000..05613b2 --- /dev/null +++ b/autostart/services/wallpaper.timer @@ -0,0 +1,8 @@ +[Unit] +BindsTo=autostart.target + +[Timer] +OnActiveSec=0s +OnCalendar=hourly +Unit=wallpaper.service +RemainAfterElapse=true diff --git a/autostart/services/xresources.service b/autostart/services/xresources.service new file mode 100644 index 0000000..321dd03 --- /dev/null +++ b/autostart/services/xresources.service @@ -0,0 +1,7 @@ +[Unit] +BindsTo=autostart.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/xrdb -merge -I%h %h/.Xresources +RemainAfterExit=true diff --git a/autostart/services/yubikey-touch-detector.service b/autostart/services/yubikey-touch-detector.service new file mode 100644 index 0000000..df71f0d --- /dev/null +++ b/autostart/services/yubikey-touch-detector.service @@ -0,0 +1,5 @@ +[Unit] +BindsTo=autostart.target + +[Service] +ExecStart=/usr/bin/yubikey-touch-detector -libnotify diff --git a/bin/dunstctl b/bin/dunstctl index 7ff1582..20de88b 100755 --- a/bin/dunstctl +++ b/bin/dunstctl @@ -11,12 +11,12 @@ log() { case "$1" in enable) log "Enabling dunst" - systemctl --user --no-block kill --signal SIGUSR2 user:dunst + systemctl --user --no-block kill --signal SIGUSR2 dunst ;; disable) log "Disabling dunst" - systemctl --user --no-block kill --signal SIGUSR1 user:dunst + systemctl --user --no-block kill --signal SIGUSR1 dunst ;; *) >&2 printf 'Unknown command\n' diff --git a/dotfiles.yml b/dotfiles.yml index ec4f0b1..bef75cb 100644 --- a/dotfiles.yml +++ b/dotfiles.yml @@ -7,8 +7,6 @@ empty_directories: - name: .config/gtk-3.0 - name: .config/qt5ct dotfiles: - - from: autostart/autostart.sh - to: .autostart.sh - from: git/gitconfig to: .gitconfig template: true diff --git a/i3/config.j2 b/i3/config.j2 index ddc10ac..e11d93b 100644 --- a/i3/config.j2 +++ b/i3/config.j2 @@ -201,8 +201,8 @@ assign [class="^Google-chrome$"] $workspace7 bindsym F2 exec --no-startup-id ~/.i3/scripts/screenmenu bindsym $mod+F1 exec --no-startup-id ~/.i3/scripts/i3exit lock - bindsym $mod+F2 exec --no-startup-id screencfg ~/.screencfg/all.yml ; exec --no-startup-id ~/.autostart/30_keyboard.sh - bindsym $mod+F3 exec --no-startup-id screencfg ~/.screencfg/laptop.yml ; exec --no-startup-id ~/.autostart/30_keyboard.sh + bindsym $mod+F2 exec --no-startup-id screencfg ~/.screencfg/all.yml ; exec systemctl --user restart keyboard.service + bindsym $mod+F3 exec --no-startup-id screencfg ~/.screencfg/laptop.yml ; exec systemctl --user restart keyboard.service bindsym $mod+F4 exec --no-startup-id ~/.i3/scripts/i3exit suspend bindsym $mod+Home exec --no-startup-id ~/.i3/scripts/shutdown-menu diff --git a/i3/scripts/presentation-mode b/i3/scripts/presentation-mode index 892c1a0..e589b07 100755 --- a/i3/scripts/presentation-mode +++ b/i3/scripts/presentation-mode @@ -10,14 +10,15 @@ is_on() { switch_on() { touch "${_status_file}" dunstctl disable & - systemctl --user --no-block stop user:redshift - systemctl --user --no-block stop user:spotify + systemctl --user --no-block stop redshift.service + systemctl --user --no-block stop spotify.service } switch_off() { rm -f "${_status_file}" dunstctl enable & - "$_autostart" redshift spotify + systemctl --user --no-block start redshift.service + systemctl --user --no-block start spotify.service } diff --git a/user.yml b/user.yml index 943dac0..41e3b25 100644 --- a/user.yml +++ b/user.yml @@ -447,3 +447,28 @@ tags: - kubectl + +- name: handle autostart units + block: + - name: create systemd user directory + file: + state: directory + path: ~/{{ item }} + loop: + - .config/ + - .config/systemd/ + - .config/systemd/user/ + + - name: link autostart service files + file: + state: link + force: true + follow: false + path: "/home/{{ user.name }}/.config/systemd/user/{{ item | basename }}" + src: "{{ item }}" + owner: "{{ user.name }}" + group: "{{ user_group_name }}" + with_fileglob: /var/lib/dotfiles/autostart/services/* + + tags: + - autostart diff --git a/x/xinitrc b/x/xinitrc index 98d52b9..3b278eb 100644 --- a/x/xinitrc +++ b/x/xinitrc @@ -25,9 +25,8 @@ start_wm() { } autostart() { - autostart="$HOME/.autostart.sh" - log "Executing autostart file \"$autostart\"" - "$autostart" >>"${LOGFILE}" 2>&1 + log "Starting systemd user target \"autostart.target\"" + systemctl --user start autostart.target >>"${LOGFILE}" 2>&1 } exec >> "$LOGFILE" 2>&1 diff --git a/zsh/zprofile.j2 b/zsh/zprofile.j2 index 8e261ff..8336d99 100644 --- a/zsh/zprofile.j2 +++ b/zsh/zprofile.j2 @@ -55,6 +55,9 @@ umask 0022 export {{ k }}="{{ v }}" {% endfor %} +# Make all environment variables also usable in the systemd user instancee +systemctl --user import-environment + # exec startx breaks some logind fuckery, without exec it works if [[ -z $DISPLAY ]] ; then if (( $XDG_VTNR == {{ user.vt }} )) ; then