diff --git a/office/.config/neomutt/maps b/office/.config/neomutt/maps index 508ba69..d46c4d2 100644 --- a/office/.config/neomutt/maps +++ b/office/.config/neomutt/maps @@ -86,8 +86,8 @@ bind index,pager ro reply macro index,pager \CU " unset pipe_decodeextract_url | fzf | clip" "get URLs" # Refresh far imap email -macro index O "export MBSYNC_PRE=true; neomutt-syncmail" "refresh all e-mail" +macro index O "export MBSYNC_PRE=true; sync-mail" "refresh all e-mail" # Send mail to taskwarrior -macro index,pager ,T "neomutt-2task -c -d -t" "add mail as task to taskwarrior with custom description and tags" -macro index,pager ,t "neomutt-2task -c" "add mail as task to taskwarrior" +macro index,pager ,T "mutt2task -c -d -t" "add mail as task to taskwarrior with custom description and tags" +macro index,pager ,t "mutt2task -c" "add mail as task to taskwarrior" diff --git a/office/.local/bin/neomutt-2task b/office/.local/bin/mutt2task similarity index 100% rename from office/.local/bin/neomutt-2task rename to office/.local/bin/mutt2task diff --git a/office/.local/bin/neomutt-syncmail b/office/.local/bin/sync-mail similarity index 100% rename from office/.local/bin/neomutt-syncmail rename to office/.local/bin/sync-mail diff --git a/office/README.md b/office/README.md index 44c70a7..c10a58c 100644 --- a/office/README.md +++ b/office/README.md @@ -16,7 +16,7 @@ Take care that most of the credential/account setup of course is highly specific ## mail The current mail setup uses `mbsync` (from the isync project) to locally mirror the GMail imap folder. -It is run through a `neomutt-syncmail` script which can invoke pre- and post-sync hooks +It is run through a `sync-mail` script which can invoke pre- and post-sync hooks (e.g. run your incoming mail through filters as soon as they arrive or ingest them into full-text search engines).[^1] The sync script also automatically unlocks any pass directory so that credentials can be put into their respective applications and the directory closes again after use. `msmtp` is used for mail sending by neomutt (and git if using git send-email). diff --git a/services/systemd/.config/systemd/user/dirmngr.service b/services/systemd/.config/systemd/user/dirmngr.service new file mode 100644 index 0000000..3c060cd --- /dev/null +++ b/services/systemd/.config/systemd/user/dirmngr.service @@ -0,0 +1,8 @@ +[Unit] +Description=GnuPG network certificate management daemon +Documentation=man:dirmngr(8) +Requires=dirmngr.socket + +[Service] +ExecStart=/usr/bin/dirmngr --supervised +ExecReload=/usr/bin/gpgconf --reload dirmngr diff --git a/services/systemd/.config/systemd/user/dirmngr.socket b/services/systemd/.config/systemd/user/dirmngr.socket new file mode 100644 index 0000000..ebabf89 --- /dev/null +++ b/services/systemd/.config/systemd/user/dirmngr.socket @@ -0,0 +1,11 @@ +[Unit] +Description=GnuPG network certificate management daemon +Documentation=man:dirmngr(8) + +[Socket] +ListenStream=%t/gnupg/S.dirmngr +SocketMode=0600 +DirectoryMode=0700 + +[Install] +WantedBy=sockets.target diff --git a/services/systemd/.config/systemd/user/gpg-agent-browser.socket b/services/systemd/.config/systemd/user/gpg-agent-browser.socket new file mode 100644 index 0000000..bc8d344 --- /dev/null +++ b/services/systemd/.config/systemd/user/gpg-agent-browser.socket @@ -0,0 +1,13 @@ +[Unit] +Description=GnuPG cryptographic agent and passphrase cache (access for web browsers) +Documentation=man:gpg-agent(1) + +[Socket] +ListenStream=%t/gnupg/S.gpg-agent.browser +FileDescriptorName=browser +Service=gpg-agent.service +SocketMode=0600 +DirectoryMode=0700 + +[Install] +WantedBy=sockets.target diff --git a/services/systemd/.config/systemd/user/gpg-agent-extra.socket b/services/systemd/.config/systemd/user/gpg-agent-extra.socket new file mode 100644 index 0000000..5b87d09 --- /dev/null +++ b/services/systemd/.config/systemd/user/gpg-agent-extra.socket @@ -0,0 +1,13 @@ +[Unit] +Description=GnuPG cryptographic agent and passphrase cache (restricted) +Documentation=man:gpg-agent(1) + +[Socket] +ListenStream=%t/gnupg/S.gpg-agent.extra +FileDescriptorName=extra +Service=gpg-agent.service +SocketMode=0600 +DirectoryMode=0700 + +[Install] +WantedBy=sockets.target diff --git a/services/systemd/.config/systemd/user/gpg-agent-ssh.socket b/services/systemd/.config/systemd/user/gpg-agent-ssh.socket new file mode 100644 index 0000000..798c1d9 --- /dev/null +++ b/services/systemd/.config/systemd/user/gpg-agent-ssh.socket @@ -0,0 +1,13 @@ +[Unit] +Description=GnuPG cryptographic agent (ssh-agent emulation) +Documentation=man:gpg-agent(1) man:ssh-add(1) man:ssh-agent(1) man:ssh(1) + +[Socket] +ListenStream=%t/gnupg/S.gpg-agent.ssh +FileDescriptorName=ssh +Service=gpg-agent.service +SocketMode=0600 +DirectoryMode=0700 + +[Install] +WantedBy=sockets.target diff --git a/services/systemd/.config/systemd/user/gpg-agent.service b/services/systemd/.config/systemd/user/gpg-agent.service new file mode 100644 index 0000000..a050fcc --- /dev/null +++ b/services/systemd/.config/systemd/user/gpg-agent.service @@ -0,0 +1,8 @@ +[Unit] +Description=GnuPG cryptographic agent and passphrase cache +Documentation=man:gpg-agent(1) +Requires=gpg-agent.socket + +[Service] +ExecStart=/usr/bin/gpg-agent --supervised +ExecReload=/usr/bin/gpgconf --reload gpg-agent diff --git a/services/systemd/.config/systemd/user/gpg-agent.socket b/services/systemd/.config/systemd/user/gpg-agent.socket new file mode 100644 index 0000000..4257c2c --- /dev/null +++ b/services/systemd/.config/systemd/user/gpg-agent.socket @@ -0,0 +1,12 @@ +[Unit] +Description=GnuPG cryptographic agent and passphrase cache +Documentation=man:gpg-agent(1) + +[Socket] +ListenStream=%t/gnupg/S.gpg-agent +FileDescriptorName=std +SocketMode=0600 +DirectoryMode=0700 + +[Install] +WantedBy=sockets.target diff --git a/services/systemd/.config/systemd/user/mbsync.service b/services/systemd/.config/systemd/user/mbsync.service new file mode 100644 index 0000000..f5d5c3b --- /dev/null +++ b/services/systemd/.config/systemd/user/mbsync.service @@ -0,0 +1,9 @@ +[Unit] +Description=Mailbox synchronization service +Wants=network-online.target gpg-agent.socket +After=network.target network-online.target dbus.socket gpg-agent.socket + +[Service] +Type=oneshot +# workaround to allow relative executable invocation (i.e. current users' home dir) +ExecStart=/bin/bash -c '%h/.local/bin/sync-mail' diff --git a/services/systemd/.config/systemd/user/mbsync.timer b/services/systemd/.config/systemd/user/mbsync.timer new file mode 100644 index 0000000..e15db08 --- /dev/null +++ b/services/systemd/.config/systemd/user/mbsync.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Mailbox synchronization timer + +[Timer] +OnBootSec=1m +OnUnitActiveSec=1h +Unit=mbsync.service + +[Install] +WantedBy=timers.target diff --git a/services/systemd/.config/systemd/user/sockets.target.wants/dirmngr.socket b/services/systemd/.config/systemd/user/sockets.target.wants/dirmngr.socket new file mode 120000 index 0000000..ce41479 --- /dev/null +++ b/services/systemd/.config/systemd/user/sockets.target.wants/dirmngr.socket @@ -0,0 +1 @@ +../dirmngr.socket \ No newline at end of file diff --git a/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-browser.socket b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-browser.socket new file mode 120000 index 0000000..7f3e9b7 --- /dev/null +++ b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-browser.socket @@ -0,0 +1 @@ +../gpg-agent-browser.socket \ No newline at end of file diff --git a/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-extra.socket b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-extra.socket new file mode 120000 index 0000000..5a1bed5 --- /dev/null +++ b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-extra.socket @@ -0,0 +1 @@ +../gpg-agent-extra.socket \ No newline at end of file diff --git a/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-ssh.socket b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-ssh.socket new file mode 120000 index 0000000..3b40290 --- /dev/null +++ b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent-ssh.socket @@ -0,0 +1 @@ +../gpg-agent-ssh.socket \ No newline at end of file diff --git a/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent.socket b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent.socket new file mode 120000 index 0000000..8b9f67c --- /dev/null +++ b/services/systemd/.config/systemd/user/sockets.target.wants/gpg-agent.socket @@ -0,0 +1 @@ +../gpg-agent.socket \ No newline at end of file diff --git a/services/systemd/.config/systemd/user/timers.target.wants/mbsync.timer b/services/systemd/.config/systemd/user/timers.target.wants/mbsync.timer new file mode 120000 index 0000000..fa56ef4 --- /dev/null +++ b/services/systemd/.config/systemd/user/timers.target.wants/mbsync.timer @@ -0,0 +1 @@ +../mbsync.timer \ No newline at end of file diff --git a/services/systemd/.local/share/services/git-sync b/services/systemd/.local/share/services/git-sync new file mode 100755 index 0000000..27f9bf4 --- /dev/null +++ b/services/systemd/.local/share/services/git-sync @@ -0,0 +1,111 @@ +#!/usr/bin/env sh +# +# Keeps a git directory synced by automatically committing every x seconds. +# After y number of runs without changes automatically pushes the directory to a remote. + +# time in seconds to check for changes to commit +TIME_TO_COMMIT=${GS_TIME_TO_COMMIT:-120} +# amount of times to check for changes *without changes occurring* to push to origin +UNCHANGED_RUNS_TO_PUSH=${GS_UNCHANGED_RUNS_TO_PUSH:-30} + +# logging verbosity level -- 0=error, 1=info, 2=debug +VERBOSITY=${GS_LOG_VERBOSITY:-1} + +set_target() { + [ -z "$GS_TARGETDIR" ] && [ -z "$1" ] && { + msg "ERROR: git-sync requires a target directory to keep in sync to be passed in." 0 + exit 1 + } + DIR="${GS_TARGETDIR:-$1}" +} + +pull() { + msg "Pulling upstream changes into $DIR" + run_git pull --ff-only --ff +} + +commit() { + msg "Committing changes to $DIR" + run_git add . + # shellcheck disable=2039 + run_git commit --no-gpg-sign -m "Git sync: $(date +%F_%R) from ${HOSTNAME:-"${HOST:-undefined}"}" +} + +push() { + msg "No changes for $((UNCHANGED_RUNS_TO_PUSH * TIME_TO_COMMIT)) seconds, pushing to origin" + run_git push +} + +should_commit() { + if [ "$(run_git diff-files --name-only | wc -l)" -eq 0 ]; then + msg "No changes to commit in $DIR" 2 + false + else + msg "Found changes to commit in $DIR" 2 + true + fi +} + +should_push() { + if [ "$no_change_cycle" -ge "$UNCHANGED_RUNS_TO_PUSH" ]; then + true + else + false + fi +} + +should_pull() { + run_git fetch + # shellcheck disable=1083 + if [ "$(run_git rev-parse HEAD)" = "$(run_git rev-parse @{u})" ]; then + false + else + true + fi +} + +run_git() { + git -C "$DIR" "$@" +} + +# echos its first argument +# verbosity level optionally set through second argument +# default verbosity 1 (info), can be set to 2 (debug), or 0 (error) +msg() { + lvl=${2:-1} + [ "$lvl" -gt "$VERBOSITY" ] && return 0 + + echo "$1" +} + +watch_changes() { + no_change_cycle=0 + while true; do + if should_pull; then + pull + fi + + if should_commit; then + commit + no_change_cycle=0 + fi + + if should_push; then + push + no_change_cycle=-9999 + fi + + msg "No changes for $((no_change_cycle * TIME_TO_COMMIT)) of $((UNCHANGED_RUNS_TO_PUSH * TIME_TO_COMMIT)) seconds, going back to sleep for $((TIME_TO_COMMIT)) seconds." 2 + + no_change_cycle=$((no_change_cycle + 1)) + sleep "$TIME_TO_COMMIT" + done +} + +main() { + set_target "$1" + + watch_changes +} + +main "$1" diff --git a/services/systemd/.local/share/services/x-started-confirm.sh b/services/systemd/.local/share/services/x-started-confirm.sh new file mode 100755 index 0000000..3dc9489 --- /dev/null +++ b/services/systemd/.local/share/services/x-started-confirm.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# from: https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg/1351489#1351489 + +COUNTER=0 + +while true; do + # Check whether or not socket exists + if [ -S /tmp/.X11-unix/X0 ]; then + exit 0 + fi + + ((++COUNTER)) + + if [ "$COUNTER" -gt 20 ]; then + printf "X did not start in time\n" + exit 1 + fi + printf "X not yet started, counter at %s\n" "$COUNTER" + sleep 1 +done