From 370a97b8af6fc987a14422f2727076767ae6bf95 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Thu, 4 Apr 2019 10:26:43 +0200 Subject: [PATCH] Add systemd config file --- dotfiles/systemd.org | 260 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 dotfiles/systemd.org diff --git a/dotfiles/systemd.org b/dotfiles/systemd.org new file mode 100644 index 0000000..419a22d --- /dev/null +++ b/dotfiles/systemd.org @@ -0,0 +1,260 @@ +#+TITLE: Systemd + +* Buku Git +** Service + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/bukugit.service + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Sync Bookmarks every day + RefuseManualStart=no + RefuseManualStop=yes + + [Service] + Type=oneshot + ExecStart=/home/%i/scripts/buku_git_push.sh +#+END_SRC + +** Timer + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/bukugit.timer + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Sync All Mails every x hours + RefuseManualStart=no + RefuseManualStop=no + After=network.target network-online.target dbus.socket + + [Timer] + OnCalendar=*-*-* 16:00:00 + Persistent=true + Unit=bukugit.service + + [Install] + WantedBy=default.target +#+END_SRC + +** Script + :PROPERTIES: + :header-args: :tangle ~/scripts/buku_git_push.sh + :header-args+: :comments both :mkdirp yes + :header-args+: :shebang "#!/usr/bin/env bash" + :END: + +#+begin_src bash + cd ~/.local/share/buku/ + + if [[ ! -z $(git status -s bookmarks.db) ]] + then + git add bookmarks.db + git commit -m "Changed bookmarks - $(date +%F)" + git push + exit + fi +#+end_src + +* Check mail +** Service + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/checkmail.service + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Check new mails + RefuseManualStart=no + RefuseManualStop=yes + + [Service] + Type=oneshot + ExecStart=/home/%i/scripts/checkmail.sh +#+END_SRC + +** Timer + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/checkmail.timer + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Check Mail every x minutes + RefuseManualStart=no + RefuseManualStop=no + After=network.target network-online.target dbus.socket + Requires=checkmail.service + + [Timer] + Persistent=false + OnBootSec=2min + OnUnitActiveSec=5min + AccuracySec=10s + Unit=checkmail.service + + [Install] + WantedBy=default.target +#+END_SRC + +** Script + :PROPERTIES: + :header-args: :tangle ~/scripts/checkmail.sh + :header-args+: :comments both :mkdirp yes + :header-args+: :shebang "#!/usr/bin/env bash" + :END: + +#+begin_src bash + # ============================================================= + # Count number of mails + gmail_old="$(ls ~/.mail/gmail/Inbox/new | wc -l)" + esrf_old="$(ls ~/.mail/esrf/Inbox/new | wc -l)" + ulg_old="$(ls ~/.mail/ulg/Inbox/new | wc -l)" + # ============================================================= + + # ============================================================= + # Retreive mails + if [ -z "$1" ]; then + # No argument => just check Inbox + mbsync gmail-Home esrf-Home ulg-Home + elif [ "$1" = "all" ]; then + # Synchronize all mails + mbsync -a + fi + # ============================================================= + + # ============================================================= + # Count number of mails + gmail_new="$(ls ~/.mail/gmail/Inbox/new | wc -l)" + esrf_new="$(ls ~/.mail/esrf/Inbox/new | wc -l)" + ulg_new="$(ls ~/.mail/ulg/Inbox/new | wc -l)" + # ============================================================= + + # ============================================================= + # Total Number of new mails since last checking + new="$(($gmail_new+$esrf_new+$ulg_new))" + old="$(($gmail_old+$esrf_old+$ulg_old))" + # ============================================================= + + # ============================================================= + # Notification + if [ "$new" -gt 0 ]; then + notify-send 'New mail' " $esrf_new  $gmail_new  $ulg_new" + fi + # ============================================================= + + # ============================================================= + # Indexation and Tags + # notmuch new + # mu index --maildir=~/.mail --quiet + # Update on Emacs + if [ "$(($new-$old))" -gt 0 ]; then + emacsclient --eval '(mu4e-update-index)'; + fi + # ============================================================= +#+end_src + +* Sync mail +** Service + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/syncmail.service + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Sync all mails + RefuseManualStart=no + RefuseManualStop=yes + + [Service] + Type=oneshot + ExecStart=/home/%i/scripts/checkmail.sh all +#+END_SRC + +** Timer + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/syncmail.timer + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Sync All Mails every x hours + RefuseManualStart=no + RefuseManualStop=no + After=network.target network-online.target dbus.socket + Requires=syncmail.service + + [Timer] + Persistent=false + OnBootSec=30min + OnUnitActiveSec=300min + AccuracySec=10s + Unit=syncmail.service + + [Install] + WantedBy=default.target +#+END_SRC + +* Emacs +** Service + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/emacs.service + :header-args+: :comments both :mkdirp yes + :END: + +#+BEGIN_SRC conf + [Unit] + Description=Emacs text editor + Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/ + + [Service] + Type=simple + ExecStart=/usr/bin/emacs --fg-daemon + ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)" + Environment=SSH_AUTH_SOCK=%t/keyring/ssh + Restart=on-failure + + [Install] + WantedBy=default.target +#+END_SRC +* Vdirsyncer +** Service + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/vdirsyncer.service + :header-args+: :comments both :mkdirp yes + :END: +#+begin_src conf + [Unit] + Description=Synchronize calendars and contacts + Documentation=https://vdirsyncer.readthedocs.org/ + + [Service] + ExecStart=/usr/bin/vdirsyncer sync + Type=oneshot +#+end_src + +** Timer + :PROPERTIES: + :header-args: :tangle ~/.config/systemd/user/vdirsyncer.timer + :header-args+: :comments both :mkdirp yes + :END: + +#+begin_src conf + [Unit] + Description=Synchronize vdirs + + [Timer] + OnBootSec=5m + OnUnitActiveSec=15m + AccuracySec=5m + + [Install] + WantedBy=timers.target +#+end_src