update theme

This commit is contained in:
2023-10-13 12:30:13 +02:00
parent 9346aee86d
commit f8070f6e51
37 changed files with 3017 additions and 3364 deletions

View File

@@ -15,8 +15,11 @@ https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-
Description=Sync Brain Website everyday
RefuseManualStart=no
RefuseManualStop=yes
OnFailure=notify-via-gotify@%i.service
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=%h/.local/bin/brain_git_push
#+END_SRC
@@ -36,8 +39,9 @@ Wants=network-online.target
After=network-online.target
[Timer]
OnCalendar=*-*-* 16:00:00
Persistent=true
Persistent=false
OnBootSec=30min
OnUnitActiveSec=1d
Unit=braingit.service
[Install]
@@ -52,7 +56,7 @@ WantedBy=default.target
:END:
#+begin_src bash
cd ~/Cloud/programming/brain-website/
cd /home/thomas/Cloud/programming/brain-website/
if [[ ! -z $(git status -s content/) ]]
then
@@ -63,6 +67,93 @@ then
fi
#+end_src
* =notify-via-gotify= - Notify
** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/notify-via-gotify@.service
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=%i failure notification over gotify
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=/bin/bash -c "systemctl status -n10 %i | ~/.local/bin/create-gotify-notification-for-systemd --unit %i --host %H | curl -XPOST \"https://gotify.tdehaeze.xyz/message?token=$(pass nas/gotify_notif_token | sed -n 1p)\" -H \"Content-Type: application/json\" --data-binary @-"
#+end_src
** Script
:PROPERTIES:
:header-args: :tangle ~/.local/bin/create-gotify-notification-for-systemd
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env python3"
:END:
#+begin_src python
import json
import argparse
import sys
TITLE_TEMPLATE = "Systemd unit failed"
MESSAGE_TEMPLATE = "Systemd unit {unit} failed on host {host}."
def main():
arguments = parse_arguments()
status = "\n".join(" " + line.rstrip() for line in sys.stdin.readlines())
message = MESSAGE_TEMPLATE.format(unit=arguments.unit, host=arguments.host, status=status)
title = TITLE_TEMPLATE.format(unit=arguments.unit, host=arguments.host)
output = create_gotify_json(title, message, arguments.priority)
print(output)
def parse_arguments():
parser = argparse.ArgumentParser(
description="Create Gotify notification for failing systemd unit",
)
parser.add_argument(
"--unit",
default="unknown",
help="the failing systemd unit name",
)
parser.add_argument(
"--host",
default="unknown",
help="the failing systemd unit host",
)
parser.add_argument(
"--priority",
default="5",
type=int,
help="the notification priority",
)
return parser.parse_args()
def create_gotify_json(title, message, priority):
data = {
"title": title,
"message": message,
"priority": priority,
"extras": {
"client::display": {
"contentType": "text/markdown"
},
},
}
return json.dumps(data)
if __name__ == '__main__':
main()
#+end_src
* =checkmail= - Check new mails
** Service
:PROPERTIES:
@@ -75,8 +166,11 @@ fi
Description=Check new mails
RefuseManualStart=no
RefuseManualStop=yes
OnFailure=notify-via-gotify@%i.service
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=%h/.local/bin/checkmail -q
#+END_SRC
@@ -94,7 +188,6 @@ RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
After=network-online.target
Requires=checkmail.service
[Timer]
Persistent=false
@@ -117,53 +210,32 @@ WantedBy=default.target
#+begin_src bash
while [ -n "$1" ]; do # while loop starts
case "$1" in
-a) opt_all='--all' ;; # Check All inboxes
-v) opt_verbose='--verbose' ;; # Verbose
-q) opt_quiet='--quiet' ;; # Quiet
,*) echo "Option $1 not recognized" ;; # In case you typed a different option
-a) opt_all='--all' ;; # Check All inboxes
-v) opt_verbose='--verbose' ;; # Verbose
-q) opt_quiet='--quiet' ;; # Quiet
,*) echo "Option $1 not recognized" ;; # In case you typed a different option
esac
shift
done
# Count number of new mails before retreiving mails
gmail_old="$(ls ~/.local/share/mails/gmail/Inbox/new | wc -l)"
esrf_old="$(ls ~/.local/share/mails/esrf/Inbox/new | wc -l)"
# =============================================================
# Count number of mails
gmail_old="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
esrf_old="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
# =============================================================
# =============================================================
# Retreive mails
mbsync $opt_all $opt_verbose gmail-Home esrf-Home 2>/tmp/mbsync.log
# =============================================================
mbsync -c /home/thomas/.config/isync/mbsyncrc $opt_all $opt_verbose gmail-Home esrf-Home 2>/tmp/mbsync.log
# =============================================================
# Count number of mails
gmail_new="$(ls ~/.mail/gmail/Inbox/new | wc -l)"
esrf_new="$(ls ~/.mail/esrf/Inbox/new | wc -l)"
# =============================================================
# Count number of new mails after retreiving mails
gmail_new="$(ls ~/.local/share/mails/gmail/Inbox/new | wc -l)"
esrf_new="$(ls ~/.local/share/mails/esrf/Inbox/new | wc -l)"
# =============================================================
# Total Number of new mails since last checking
new="$(($esrf_new+$gmail_new))"
old="$(($esrf_old+$gmail_old))"
# =============================================================
# =============================================================
# Notification
if [ "$new" -gt 0 ]; then
notify-send --hint=string:x-dunst-stack-tag:fV84ivMi 'Mails ' "$new new mail(s)"
# Notification if there are new retreive mails
if [ "$(($esrf_new+$gmail_new))" -gt "$(($esrf_old+$gmail_old))" ]; then
dunstify --replace=98465 'Mails ' "$(($gmail_new+$esrf_new)) new mail(s)"
fi
# =============================================================
# =============================================================
# Indexation and Tags
if pgrep -f 'mu server'; then
emacsclient --eval '(mu4e-update-index)'
else
mu index -m ~/.mail $opt_verbose $opt_quiet
fi
# =============================================================
mu index $opt_verbose $opt_quiet
#+end_src
* =syncmail= - Synchronize all mails
@@ -178,8 +250,11 @@ fi
Description=Sync all mails
RefuseManualStart=no
RefuseManualStop=yes
OnFailure=notify-via-gotify@%i.service
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=%h/.local/bin/checkmail -a -q
#+END_SRC
@@ -197,7 +272,6 @@ RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
After=network-online.target
Requires=syncmail.service
[Timer]
Persistent=false
@@ -223,9 +297,12 @@ Description=Synchronize calendars and contacts
Documentation=https://vdirsyncer.readthedocs.org/
Wants=network-online.target
After=network-online.target
OnFailure=notify-via-gotify@%i.service
[Service]
ExecStart=/home/thomas/.local/bin/vdirsyncer --verbosity "ERROR" sync
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
ExecStart=/usr/bin/vdirsyncer --verbosity "ERROR" sync
Type=oneshot
#+end_src
@@ -248,89 +325,13 @@ AccuracySec=5m
WantedBy=timers.target
#+end_src
* TODO =ssh-agent= - SSH Agent
** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/ssh-agent.service
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=SSH key agent
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
[Install]
WantedBy=default.target
#+end_src
* TODO =emacs= - 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
* TODO =trash-empty= - Empty the trash for files older than 30 days
** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/trash-empty.service
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=Empty the trash for files older than 30 days
Documentation=https://github.com/andreafrancia/trash-cli
[Service]
ExecStart=/home/thomas/.local/bin/trash-empty 30
Type=oneshot
#+end_src
** Timer
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/trash-empty.timer
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=Empty trash
[Timer]
OnCalendar=*-*-* 16:00:00
Persistent=true
Unit=trash-empty
[Install]
WantedBy=timers.target
#+end_src
* =syncthing=
* =syncthing= - Synchronize =Cloud= directory
** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/syncthing.service
:header-args+: :comments both :mkdirp yes
:END:
#+begin_src conf
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
@@ -348,6 +349,150 @@ RestartForceExitStatus=3 4
WantedBy=default.target
#+end_src
* =restic-backup= - Backup Home Directory
** Backup
*** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/restic-backup.service
:header-args+: :comments both :mkdirp yes
:END:
#+BEGIN_SRC conf
[Unit]
Description=Backup Home Directory
RefuseManualStart=no
RefuseManualStop=no
OnFailure=notify-via-gotify@%i.service
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=%h/.local/bin/restic-backup
ExecStartPost=/bin/sleep 30
ExecStartPost=%h/.local/bin/restic-forget
#+END_SRC
*** Timer
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/restic-backup.timer
:header-args+: :comments both :mkdirp yes
:END:
#+BEGIN_SRC conf
[Unit]
Description=Backup Home Directory Everyday
RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
[Timer]
Persistent=true
OnCalendar=daily
Unit=restic-backup.service
[Install]
WantedBy=default.target
#+END_SRC
*** Script - Backup
:PROPERTIES:
:header-args: :tangle ~/.local/bin/restic-backup
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
restic backup \
-r sftp:thomas@homelab:/srv/storage/Backups/esrf-laptop \
--password-command "pass show restic" \
--verbose --one-file-system --tag systemd.timer \
--exclude "/home/thomas/.cache" \
--exclude "/home/thomas/Cloud" \
--exclude "/home/thomas/mnt" \
--exclude "/home/thomas/perl5" \
--exclude "/home/thomas/.local/soft" \
/home/thomas
#+end_src
*** Script - Forget
:PROPERTIES:
:header-args: :tangle ~/.local/bin/restic-forget
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
restic unlock \
-r sftp:thomas@homelab:/srv/storage/Backups/esrf-laptop \
--password-command "pass show restic" && \
restic forget \
-r sftp:thomas@homelab:/srv/storage/Backups/esrf-laptop \
--password-command "pass show restic" \
--verbose --tag systemd.timer \
--group-by "paths,tags" \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 1 \
--keep-yearly 1
#+end_src
** Prune
*** Service
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/restic-prune.service
:header-args+: :comments both :mkdirp yes
:END:
#+BEGIN_SRC conf
[Unit]
Description=Prune restic backup
RefuseManualStart=no
RefuseManualStop=no
OnFailure=notify-via-gotify@%i.service
[Service]
Environment="PASSWORD_STORE_DIR=/home/thomas/.local/share/pass"
Environment="GNUPGHOME=/home/thomas/.local/share/gnupg"
Type=oneshot
ExecStart=%h/.local/bin/restic-prune
#+END_SRC
*** Timer
:PROPERTIES:
:header-args: :tangle ~/.config/systemd/user/restic-prune.timer
:header-args+: :comments both :mkdirp yes
:END:
#+BEGIN_SRC conf
[Unit]
Description=Prune Restic Backup
RefuseManualStart=no
RefuseManualStop=no
Wants=network-online.target
[Timer]
Persistent=true
OnCalendar=monthly
Unit=restic-prune.service
[Install]
WantedBy=default.target
#+END_SRC
*** Script
:PROPERTIES:
:header-args: :tangle ~/.local/bin/restic-prune
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
restic prune \
-r sftp:thomas@homelab:/srv/storage/Backups/esrf-laptop \
--password-command "pass show restic" \
#+end_src
* =homelab-tunnel= - SSH Tunnel
Useful to bypass firewalls.
This can we used on the browser:
@@ -390,7 +535,7 @@ Description=Setup a secure tunnel with ESRF
After=network.target
[Service]
ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -D 8081 -q -N -T rnice.esrf.fr
ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -D 8081 -q -N -T firewall.esrf.fr
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5