Organize by host machine

This commit is contained in:
Jeffrey Serio 2024-06-20 10:12:41 -05:00
parent 0139060bf2
commit f48d826e55
26 changed files with 205 additions and 53 deletions

View File

@ -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.

3
README.org Normal file
View File

@ -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.

18
pi0/bin/mastodon-db-backup Executable file
View File

@ -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

8
pi0/gmcapsulerc Normal file
View File

@ -0,0 +1,8 @@
[server]
host = hyperreal.coffee
address = 0.0.0.0
port = 1965
certs = ~/.gemini-certs
[static]
root = ~/public/gemini

46
pi0/justfile Normal file
View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -0,0 +1,9 @@
[Unit]
Description=mastodon-db-backup
[Timer]
OnCalendar=*-*-* 21:00:00
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -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

View File

@ -0,0 +1,9 @@
[Unit]
Description=mastodon-system-to-minio
[Timer]
OnCalendar=*-*-* 21:00:00
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -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" | parallel "qbt torrent delete --with-files {}"
echo "$1" | xargs -I _ gum log -l info "Deleted" _
fi
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")

3
pi1/bin/qbtlist Executable file
View File

@ -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

31
pi1/justfile Normal file
View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
[Unit]
Description=Run seed-armbian-torrents.nu
Description=Run seed-armbian-tx.nu
[Timer]
OnCalendar=weekly

View File

@ -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

30
pi2/justfile Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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