From f48d826e55ae0cc258d07e0d3510be153f3ba63d Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:12:41 -0500 Subject: [PATCH] Organize by host machine --- README.md | 7 --- README.org | 3 ++ pi0/bin/mastodon-db-backup | 18 ++++++++ pi0/gmcapsulerc | 8 ++++ pi0/justfile | 46 +++++++++++++++++++ .../systemd/user/gmcapsuled.service | 2 +- pi0/systemd/user/mastodon-db-backup.service | 11 +++++ pi0/systemd/user/mastodon-db-backup.timer | 9 ++++ .../user/mastodon-system-to-minio.service | 10 ++++ .../user/mastodon-system-to-minio.timer | 9 ++++ .../bin/armbian-tx-stats-html.nu | 0 qbth => pi1/bin/qbth | 12 ++--- pi1/bin/qbtlist | 3 ++ .../bin/seed-armbian-tx.nu | 0 .../bin/tx-stats-html.nu | 0 pi1/justfile | 31 +++++++++++++ pi1/systemd/user/seed-armbian-tx.service | 10 ++++ .../systemd/user/seed-armbian-tx.timer | 2 +- .../user}/transmission-trackers.service | 0 .../systemd/user}/transmission-trackers.timer | 0 pi1/systemd/user/tx-stats-html.service | 11 +++++ .../systemd/user/tx-stats-html.timer | 0 pi2/justfile | 30 ++++++++++++ systemd-user/breezewiki.service | 14 ------ systemd-user/seed-armbian-torrents.service | 11 ----- systemd-user/torrentstats-html.service | 11 ----- 26 files changed, 205 insertions(+), 53 deletions(-) delete mode 100644 README.md create mode 100644 README.org create mode 100755 pi0/bin/mastodon-db-backup create mode 100644 pi0/gmcapsulerc create mode 100644 pi0/justfile rename systemd-user/gmcapsule.service => pi0/systemd/user/gmcapsuled.service (84%) create mode 100644 pi0/systemd/user/mastodon-db-backup.service create mode 100644 pi0/systemd/user/mastodon-db-backup.timer create mode 100644 pi0/systemd/user/mastodon-system-to-minio.service create mode 100644 pi0/systemd/user/mastodon-system-to-minio.timer rename armbian-torrent-stats-html.nu => pi1/bin/armbian-tx-stats-html.nu (100%) rename qbth => pi1/bin/qbth (96%) create mode 100755 pi1/bin/qbtlist rename seed-armbian-torrents.nu => pi1/bin/seed-armbian-tx.nu (100%) rename torrentstats-html.nu => pi1/bin/tx-stats-html.nu (100%) create mode 100644 pi1/justfile create mode 100644 pi1/systemd/user/seed-armbian-tx.service rename systemd-user/seed-armbian-torrents.timer => pi1/systemd/user/seed-armbian-tx.timer (67%) rename {systemd-user => pi1/systemd/user}/transmission-trackers.service (100%) rename {systemd-user => pi1/systemd/user}/transmission-trackers.timer (100%) create mode 100644 pi1/systemd/user/tx-stats-html.service rename systemd-user/torrentstats-html.timer => pi1/systemd/user/tx-stats-html.timer (100%) create mode 100644 pi2/justfile delete mode 100644 systemd-user/breezewiki.service delete mode 100644 systemd-user/seed-armbian-torrents.service delete mode 100644 systemd-user/torrentstats-html.service diff --git a/README.md b/README.md deleted file mode 100644 index a3ae82f..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# homelab-scripts - -Assorted scripts I use for my homelab. - -- [armbian-torrent-stats-html.nu](./armbian-torrent-stats-html.nu): Nushell script that uses `transmission-remote` to get torrent stats on my Orange Pi 5 Plus running Armbian and seeding Armbian torrents. It converts the output to HTML, then sends the HTML document to my website root. -- [seed-armbian-torrents.nu](./seed-armbian-torrents.nu): Nushell script that downloads the latest Armbian torrents and adds/updates them on a transmission-daemon instance. -- [torrentstats-html.nu](./torrentstats-html.nu): Nushell script that uses `transmission-remote` to get torrent stats on my primary homelab machine, which seeds a different set of torrents. I prefer to keep Armbian torrents separate so they don't clutter up the main torrent stats page. diff --git a/README.org b/README.org new file mode 100644 index 0000000..ccb6503 --- /dev/null +++ b/README.org @@ -0,0 +1,3 @@ +#+title: homelab-scripts + +Assorted scripts I use for my homelab. My homelab consists of my TrueNAS machine and my three Orange Pi 5+'s. These scripts are mostly for the latter. diff --git a/pi0/bin/mastodon-db-backup b/pi0/bin/mastodon-db-backup new file mode 100755 index 0000000..6d58c31 --- /dev/null +++ b/pi0/bin/mastodon-db-backup @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +DB_FILENAME="/home/mastodon/db-backup-$(date '+%Y-%m-%d').sql" + +if ! pg_dump -U mastodon mastodon_production -p 5432 -f "$DB_FILENAME"; then + echo "Error creating backup of mastodon_production database" + exit 1 +else + echo "Backup of mastodon_production database completed" +fi + +find /home/mastodon \ + -maxdepth 1 \ + -type f \ + \( -name "*.sql" -and -not -wholename "$DB_FILENAME" \) \ + -delete + +exit 0 diff --git a/pi0/gmcapsulerc b/pi0/gmcapsulerc new file mode 100644 index 0000000..b95f5d3 --- /dev/null +++ b/pi0/gmcapsulerc @@ -0,0 +1,8 @@ +[server] +host = hyperreal.coffee +address = 0.0.0.0 +port = 1965 +certs = ~/.gemini-certs + +[static] +root = ~/public/gemini diff --git a/pi0/justfile b/pi0/justfile new file mode 100644 index 0000000..539a752 --- /dev/null +++ b/pi0/justfile @@ -0,0 +1,46 @@ +## Justfile (https://github.com/casey/justfile) +## +## pi0 - Orange Pi 5+ +## +## Services: +## - gmcapsuled +## - Mastodon +## - Tailscale +## - The Lounge IRC + +debian_codename := `grep "VERSION_CODENAME" /etc/os-release | awk -F= '{print $2}'` + +gmcapsuled: + pipx install gmcapsule + mkdir -p ~/.config/systemd/user + cp -v "${PWD}/systemd/user/gmcapsuled.service" ~/.config/systemd/user/ + cp -v "${PWD}/gmcapsulerc" ~/.gmcapsulerc + +mastodon: + sudo mkdir -p /home/mastodon/.config/systemd/user + sudo cp -v "${PWD}/systemd/user/mastodon-db-backup.service" /home/mastodon/.config/systemd/user/ + sudo cp -v "${PWD}/systemd/user/mastodon-db-backup.timer" /home/mastodon/.config/systemd/user/ + sudo cp -v "${PWD}/systemd/user/mastodon-system-to-minio.service" /home/mastodon/.config/systemd/user/ + sudo cp -v "${PWD}/systemd/user/mastodon-system-to-minio.timer" /home/mastodon/.config/systemd/user/ + sudo chown -R mastodon:mastodon /home/mastodon/.config + sudo cp -v "${PWD}/bin/mastodon-db-backup" /usr/local/bin + sudo chown -R root:root /usr/local/bin/mastodon-db-backup + sudo loginctl enable-linger + sudo -u mastodon systemctl --user enable --now mastodon-db-backup.timer + sudo -u mastodon systemctl --user enable --now mastodon-system-to-minio.timer + +thelounge: + curl -s https://api.github.com/repos/thelounge/thelounge-deb/releases/latest \ + | grep "browser_download_url.*deb" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + | wget -qi - + sudo apt install -y ./thelounge*.deb + +tailscale: + curl -fsSL https://pkgs.tailscale.com/stable/debian/{{ debian_codename }}.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null + curl -fsSL https://pkgs.tailscale.com/stable/debian/{{ debian_codename }}.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list + sudo apt update + sudo apt install -y tailscale + sudo systemctl enable --now tailscaled + sudo tailscale up diff --git a/systemd-user/gmcapsule.service b/pi0/systemd/user/gmcapsuled.service similarity index 84% rename from systemd-user/gmcapsule.service rename to pi0/systemd/user/gmcapsuled.service index 39c8139..01321f4 100644 --- a/systemd-user/gmcapsule.service +++ b/pi0/systemd/user/gmcapsuled.service @@ -4,7 +4,7 @@ After=network.target [Service] Type=simple -ExecStart=/home/jas/.local/bin/gmcapsuled +ExecStart=/home/dietpi/.local/bin/gmcapsuled ExecReload=/bin/kill -HUP $MAINPID Restart=always Environment="PYTHONUNBUFFERED=1" diff --git a/pi0/systemd/user/mastodon-db-backup.service b/pi0/systemd/user/mastodon-db-backup.service new file mode 100644 index 0000000..c2c32f1 --- /dev/null +++ b/pi0/systemd/user/mastodon-db-backup.service @@ -0,0 +1,11 @@ +[Unit] +Description=mastodon-db-backup +Wants=postgresql.service +AssertFileIsExecutable=/usr/local/bin/mastodon-db-backup + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/mastodon-db-backup + +[Install] +WantedBy=multi-user.target diff --git a/pi0/systemd/user/mastodon-db-backup.timer b/pi0/systemd/user/mastodon-db-backup.timer new file mode 100644 index 0000000..0c26fa2 --- /dev/null +++ b/pi0/systemd/user/mastodon-db-backup.timer @@ -0,0 +1,9 @@ +[Unit] +Description=mastodon-db-backup + +[Timer] +OnCalendar=*-*-* 21:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/pi0/systemd/user/mastodon-system-to-minio.service b/pi0/systemd/user/mastodon-system-to-minio.service new file mode 100644 index 0000000..3ced1aa --- /dev/null +++ b/pi0/systemd/user/mastodon-system-to-minio.service @@ -0,0 +1,10 @@ +[Unit] +Description=mastodon-system-to-minio +Wants=network.target + +[Service] +Type=oneshot +ExecStart=rclone copy --progress --transfers=8 /home/mastodon/live/public/system/ minio:mastodata + +[Install] +WantedBy=multi-user.target diff --git a/pi0/systemd/user/mastodon-system-to-minio.timer b/pi0/systemd/user/mastodon-system-to-minio.timer new file mode 100644 index 0000000..74ce329 --- /dev/null +++ b/pi0/systemd/user/mastodon-system-to-minio.timer @@ -0,0 +1,9 @@ +[Unit] +Description=mastodon-system-to-minio + +[Timer] +OnCalendar=*-*-* 21:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/armbian-torrent-stats-html.nu b/pi1/bin/armbian-tx-stats-html.nu similarity index 100% rename from armbian-torrent-stats-html.nu rename to pi1/bin/armbian-tx-stats-html.nu diff --git a/qbth b/pi1/bin/qbth similarity index 96% rename from qbth rename to pi1/bin/qbth index 4435080..c0e59be 100755 --- a/qbth +++ b/pi1/bin/qbth @@ -24,17 +24,13 @@ function add_torrents() { exit 1 fi - for url in "${torrents[@]}"; do gum log -l info "Added" "$(basename $url)"; done + for url in "${torrents[@]}"; do gum log -l info "Added" "$(basename "$url")"; done } function delete_torrents() { if test -n "$1"; then - if ! "$(echo "$1" | parallel "qbt torrent delete --with-files {}")"; then - gum log -l error "Error deleting torrents" - exit 1 - else - echo "$1" | xargs -I _ gum log -l info "Deleted" _ - fi + echo "$1" | parallel "qbt torrent delete --with-files {}" + echo "$1" | xargs -I _ gum log -l info "Deleted" _ else gum log -l warn "Nothing to do." fi @@ -44,8 +40,8 @@ export -f add_torrents export -f delete_torrents distro_selection=$(gum choose --limit=1 --header="Available torrents" --height=13 "AlmaLinux" "Debian" "Devuan" "Fedora" "FreeBSD" "Kali Linux" "NetBSD" "NixOS" "Qubes" "Rocky Linux" "Tails") -relver=$(gum input --placeholder="Enter $distro_selection release version") action=$(gum choose --limit=1 --header="Choose an action: Add, Delete" "Add" "Delete") +relver=$(gum input --placeholder="Enter $distro_selection release version") case "$distro_selection" in "AlmaLinux") diff --git a/pi1/bin/qbtlist b/pi1/bin/qbtlist new file mode 100755 index 0000000..5bc20b3 --- /dev/null +++ b/pi1/bin/qbtlist @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +qbt torrent list -F csv | awk -F, '{ print $2 }' | grep -v "Name" | sort | tee /home/dietpi/public/html/torrents.txt || true diff --git a/seed-armbian-torrents.nu b/pi1/bin/seed-armbian-tx.nu similarity index 100% rename from seed-armbian-torrents.nu rename to pi1/bin/seed-armbian-tx.nu diff --git a/torrentstats-html.nu b/pi1/bin/tx-stats-html.nu similarity index 100% rename from torrentstats-html.nu rename to pi1/bin/tx-stats-html.nu diff --git a/pi1/justfile b/pi1/justfile new file mode 100644 index 0000000..98faa42 --- /dev/null +++ b/pi1/justfile @@ -0,0 +1,31 @@ +## Justfile (https://github.com/casey/justfile) +## +## pi1 - Orange Pi 5+ +## +## Services: +## - qBittorrent +## - ProtonVPN via Wireguard + +debian_codename := `grep "VERSION_CODENAME" /etc/os-release | awk -F= '{print $2}'` +run_user := env_var("USER") + +qbt: + curl -1sLf 'https://dl.cloudsmith.io/public/qbittorrent-cli/qbittorrent-cli/gpg.F8756541ADDA2B7D.key' | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/qbittorrent-cli.gpg + sudo wget https://repos.fedorovich.com/debian/{{ debian_codename }}/qbittorrent-cli.list -O /etc/apt/sources.list.d/qbittorrent-cli.list + sudo apt update + sudo apt install -y qbittorrent-cli + mkdir ~/bin + cp -v "${PWD}/bin/qbth" ~/bin/ + cp -v "${PWD}/bin/qbtlist" ~/bin/ + +install: + sudo apt install -y qbittorrent-nox wireguard-tools lynx parallel wget curl + +enable: + sudo systemctl enable --now qbittorrent-nox@{{ run_user }}.service + +scihub: + mkdir ~/scihub-torrent-urls + lynx -dump -nonumbers -listonly=on https://libgen.rs/repository_torrent/ | grep "\.torrent" | tee scihub-torrent-urls/urls.txt + cd scihub-torrent-urls && split -l 60 urls.txt torrent- + rm -fv scihub-torrent-urls/urls.txt diff --git a/pi1/systemd/user/seed-armbian-tx.service b/pi1/systemd/user/seed-armbian-tx.service new file mode 100644 index 0000000..8e84990 --- /dev/null +++ b/pi1/systemd/user/seed-armbian-tx.service @@ -0,0 +1,10 @@ +[Unit] +Description=Run seed-armbian-tx.nu +After=network.target + +[Service] +Type=oneshot +ExecStart=nu /home/jas/bin/seed-armbian-tx.nu + +[Install] +WantedBy=default.target diff --git a/systemd-user/seed-armbian-torrents.timer b/pi1/systemd/user/seed-armbian-tx.timer similarity index 67% rename from systemd-user/seed-armbian-torrents.timer rename to pi1/systemd/user/seed-armbian-tx.timer index d80aa35..bf1526c 100644 --- a/systemd-user/seed-armbian-torrents.timer +++ b/pi1/systemd/user/seed-armbian-tx.timer @@ -1,5 +1,5 @@ [Unit] -Description=Run seed-armbian-torrents.nu +Description=Run seed-armbian-tx.nu [Timer] OnCalendar=weekly diff --git a/systemd-user/transmission-trackers.service b/pi1/systemd/user/transmission-trackers.service similarity index 100% rename from systemd-user/transmission-trackers.service rename to pi1/systemd/user/transmission-trackers.service diff --git a/systemd-user/transmission-trackers.timer b/pi1/systemd/user/transmission-trackers.timer similarity index 100% rename from systemd-user/transmission-trackers.timer rename to pi1/systemd/user/transmission-trackers.timer diff --git a/pi1/systemd/user/tx-stats-html.service b/pi1/systemd/user/tx-stats-html.service new file mode 100644 index 0000000..94ad59f --- /dev/null +++ b/pi1/systemd/user/tx-stats-html.service @@ -0,0 +1,11 @@ +[Unit] +Description=Run tx-stats-html.nu +After=network.target + +[Service] +Type=oneshot +ExecStart=nu /home/jas/bin/tx-stats-html.nu +SyslogIdentifier=tx-stats-html + +[Install] +WantedBy=default.target diff --git a/systemd-user/torrentstats-html.timer b/pi1/systemd/user/tx-stats-html.timer similarity index 100% rename from systemd-user/torrentstats-html.timer rename to pi1/systemd/user/tx-stats-html.timer diff --git a/pi2/justfile b/pi2/justfile new file mode 100644 index 0000000..fb78560 --- /dev/null +++ b/pi2/justfile @@ -0,0 +1,30 @@ +## Justfile (https://github.com/casey/just) +## +## Services: +## - archivebox + +data_dir := "/nfs/archivebox" +nfs_mnt := "10.0.0.6:/mnt/coffeeNAS/archivebox" +run_user := env_var("USER") + +default: env install + +env: + sudo mkdir -p {{ data_dir }} + sudo chown -R {{ run_user }}:{{ run_user }} {{ data_dir }} + echo "{{ nfs_mnt }} {{ data_dir }} nfs4 soft,intr,rsize=8192,wsize=8192" | sudo tee -a /etc/fstab + sudo systemctl daemon-reload + sudo mount -av + +install: + sudo apt install -y pipx python3-dev python3-pip nodejs npm curl wget git ripgrep + pipx install archivebox + pipx install yt-dlp + pipx install playwright + playwright install --with-deps chromium + +init: + cd {{ data_dir }} && archivebox init --setup + +setup: + cd {{ data_dir }} && archivebox setup diff --git a/systemd-user/breezewiki.service b/systemd-user/breezewiki.service deleted file mode 100644 index 0312dcd..0000000 --- a/systemd-user/breezewiki.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=BreezeWiki service -After=network.target - -[Service] -Type=simple -ExecStart=racket /home/jas/repos/breezewiki/dist.rkt -ExecReload=/bin/kill -HUP $MAINPID -Restart=always -SyslogIdentifier=BreezeWiki -WorkingDirectory=/home/jas/repos/breezewiki - -[Install] -WantedBy=default.target diff --git a/systemd-user/seed-armbian-torrents.service b/systemd-user/seed-armbian-torrents.service deleted file mode 100644 index b4c854a..0000000 --- a/systemd-user/seed-armbian-torrents.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Run seed-armbian-torrents.nu -After=network.target - -[Service] -Type=oneshot -ExecStart=nu /home/jas/homelab-scripts/seed-armbian-torrents.nu -SyslogIdentifier=seed-armbian-torrents - -[Install] -WantedBy=default.target diff --git a/systemd-user/torrentstats-html.service b/systemd-user/torrentstats-html.service deleted file mode 100644 index 7fbef08..0000000 --- a/systemd-user/torrentstats-html.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Run torrentstats-html.nu -After=network.target - -[Service] -Type=oneshot -ExecStart=nu /home/jas/homelab-scripts/torrentstats-html.nu -SyslogIdentifier=torrentstats-html - -[Install] -WantedBy=default.target