From 063df11269e2e533c2a1597f33a3f78e02559e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Mon, 3 Jun 2024 20:09:38 +0200 Subject: [PATCH] Mon Jun 3 08:09:38 PM CEST 2024 --- home/Mallorea.nix | 55 ++++++++++++++++++++++++++ home/scripts/files/backup.sh | 2 +- home/scripts/files/launch_alacritty.sh | 37 ----------------- home/scripts/files/sync_vault.sh | 3 +- 4 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 home/Mallorea.nix delete mode 100755 home/scripts/files/launch_alacritty.sh diff --git a/home/Mallorea.nix b/home/Mallorea.nix new file mode 100644 index 0000000..89701e8 --- /dev/null +++ b/home/Mallorea.nix @@ -0,0 +1,55 @@ +{ inputs, config, pkgs, ... }: +let + mkTimer = { name, interval, serviceScript }: + let + timerName = "${name}-timer"; + serviceName = "${name}-service"; + in + { + systemd.timers.${timerName} = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = interval; + OnUnitActiveSec = interval; + Unit = "${serviceName}.service"; + }; + }; + + systemd.services.${serviceName} = { + script = '' + set -eu + ${serviceScript} + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + }; + +in +{ + imports = [ + (import ./common.nix { inherit inputs config pkgs; }) + ./ssh + ]; + + mkTimer { + name = "disk_check"; + interval = "1h"; + serviceScript = toString (pkgs.writeShellScript "disk_check" '' + REPORT_EMAIL=email@thomasave.be + ZPOOL_STATUS=$(zpool status -x) + if [ "$ZPOOL_STATUS" = "all pools are healthy" ] || [ "$ZPOOL_STATUS" = "no pools available" ] + then + printf 0 > /var/db/zpool.status + else + if [ "$(cat /var/db/zpool.status)" -eq 0 ] + then + zpool status | mail -s "ZPOOL NOT HEALTHY" $REPORT_EMAIL + printf 1 > /var/db/zpool.status + fi + fi + ''); + } +} diff --git a/home/scripts/files/backup.sh b/home/scripts/files/backup.sh index aa7bf1c..0e5d959 100755 --- a/home/scripts/files/backup.sh +++ b/home/scripts/files/backup.sh @@ -7,7 +7,7 @@ set -o pipefail export XDG_RUNTIME_DIR=/run/user/1000 export XDG_CONFIG_HOME=/home/server/.config -source "$XDG_CONFIG_HOME"/zsh/secrets.sh +source $HOME/.secrets/Backup/env.sh ########################################## # Create sqlite3 backup for Vaultwarden # diff --git a/home/scripts/files/launch_alacritty.sh b/home/scripts/files/launch_alacritty.sh deleted file mode 100755 index 12764c9..0000000 --- a/home/scripts/files/launch_alacritty.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -RUNNING_WAYPIPE=false -SSH_CLIENT="" -CHILD_PID=$(pgrep -P "$1") - -GRAND_CHILD_PID=$(pgrep -P "$CHILD_PID") -if [ "$GRAND_CHILD_PID" != 0 ]; then - GRAND_CHILD_NAME=$(ps -p "$GRAND_CHILD_PID" -o comm=) - if [ "$GRAND_CHILD_NAME" == "ssh" ]; then - CHILD_PID=$GRAND_CHILD_PID - SSH_CLIENT=$(ps -p "$CHILD_PID" -o args --no-headers | awk '{ print $2 }') - fi - if [ "$GRAND_CHILD_NAME" == "waypipe" ]; then - RUNNING_WAYPIPE=true - CHILD_PID=$(pgrep -P "$GRAND_CHILD_PID") - SSH_CLIENT=$(ps -p "$GRAND_CHILD_PID" -o args --no-headers | awk '{ print $4 }') - fi -fi - - -if [ $RUNNING_WAYPIPE == true ]; then - PREVIOUS_SESSION_ID=$(grep -z "SSH_SESSION_ID" "/proc/$CHILD_PID/environ" | xargs -0 -n 1 | grep -oP "[0-9]*") - SSH_SESSION_ID=$RANDOM - alacritty -e zsh -c "SSH_SESSION_ID=$SSH_SESSION_ID waypipe ssh -t \"$SSH_CLIENT\" env SSH_SESSION_ID=\"$SSH_SESSION_ID\" PREVIOUS_SESSION_ID=\"$PREVIOUS_SESSION_ID\" \"zsh --login\"" -else - if [ "$(ps -p "$1" -o comm=)" == "alacritty" ]; then - CWD=$(readlink -e /proc/"$CHILD_PID"/cwd) - if [ "$CWD" != "" ]; then - alacritty --working-directory "$CWD" - else - alacritty - fi - else - alacritty - fi -fi diff --git a/home/scripts/files/sync_vault.sh b/home/scripts/files/sync_vault.sh index 7f371e6..8a73345 100755 --- a/home/scripts/files/sync_vault.sh +++ b/home/scripts/files/sync_vault.sh @@ -1,7 +1,6 @@ #!/bin/bash -export XDG_CONFIG_HOME=/home/server/.config -source "$XDG_CONFIG_HOME"/zsh/secrets.sh +source $HOME/.secrets/Backup/env.sh for _ in {1..2}; do OUTPUT=$(echo "$ZFS_PASSPHRASE" | ssh 10.4.0.1 zfs load-key Vault/Thomas/Encrypted 2>&1);