Refactor and tidy

This commit is contained in:
Jeffrey Serio 2024-07-14 18:51:57 -05:00
parent e98a8379ae
commit 780ce26bf6
24 changed files with 88 additions and 81 deletions

18
bin/mastodon-backup Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eu
trap "mv /home/mastodon/db-backup.sql.temp /home/mastodon/db-backup.sql" SIGHUP SIGINT SIGQUIT SIGTERM
trap "rm -v /home/mastodon/db-backup.sql.temp" EXIT
mv -v /home/mastodon/db-backup.sql /home/mastodon/db-backup.sql.temp
pg_dump -U mastodon -Fc mastodon_production -p 5432 -f /home/mastodon/db-backup.sql
rclone sync -c /home/mastodon/live/public/system/ /mnt/mastodon/system
rclone copy -c /home/mastodon/db-backup.sql /mnt/mastodon
rclone copy -c /home/mastodon/live/.env.production /mnt/mastodon
exit 0

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
sudo -u mastodon pg_dump -U mastodon -Fc mastodon_production -p 5432 -f "mastodon-db-$(date '+%Y-%m-%d').sql"

View File

@ -1,33 +0,0 @@
#!/usr/bin/env bash
DB_FILENAME="/home/mastodon/db-backup-$(date '+%Y-%m-%d').sql"
if ! pg_dump -U mastodon -Fc 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
if ! rclone copy --transfers=4 /home/mastodon/live/public/system minio:mastodata; then
echo "Error rcloning /home/mastodon/live/public/system to MinIO instance"
exit 1
fi
if ! rclone copy "${DB_FILENAME}" minio:mastodata; then
echo "Error rcloning ${DB_FILENAME} to MinIO instance"
exit 1
fi
if ! rclone copy /home/mastodon/live/.env.production minio:mastodata; then
echo "Error rcloning /home/mastodon/live/.env.production to MinIO instance"
exit 1
fi
exit 0

View File

@ -1,11 +1,20 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#
# Dependencies: python-qbittorrent
# pip install --user python-qbittorrent
#
# On Debian:
# pip install --user python-qbittorrent --break-system-packages
"""qbt-sum-size
Usage:
qbt-sum-size (HOSTNAME) (USERNAME) (PASSWORD)
qbt-sum-size -h
Examples:
qbt-sum-size "http://localhost:8080" "admin" "adminadmin"
qbt-sum-size "https://cat.seedhost.eu/lol/qbittorrent" "lol" "supersecretpassword"
Options:
-h, --help show this help message and exit
"""
from docopt import docopt
from qbittorrent import Client from qbittorrent import Client
@ -33,11 +42,11 @@ def human_bytes(bites: int) -> str:
if __name__ == "__main__": if __name__ == "__main__":
# Instantiate a qbittorrent client args = docopt(__doc__)
qb = Client("http://localhost:8080/")
# username and password not required when 'Bypass from localhost' setting is active. # Initialize client and login
qb.login() qb = Client(args["HOSTNAME"])
qb.login(username=args["USERNAME"], password=args["PASSWORD"])
# get torrents # get torrents
torrents = qb.torrents() torrents = qb.torrents()

View File

@ -18,7 +18,7 @@ from qbittorrent import Client
if __name__ == "__main__": if __name__ == "__main__":
qb = Client("http://10.0.0.81:8080/") qb = Client("http://localhost:8080/")
qb.login() qb.login()
with TemporaryDirectory() as tmp_dir: with TemporaryDirectory() as tmp_dir:

View File

@ -1,21 +1,8 @@
## Justfile (https://github.com/casey/justfile) ## Justfile (https://github.com/casey/justfile)
##
## Orange Pi 5+ x 3
##
## Services:
## - ArchiveBox
## - Caddy web server
## - gmcapsuled
## - Mastodon auxiliary scripts
## - qBittorrent + WireGuard
## - Tailscale
## - The Lounge IRC
distro := `grep -G "\bID\b" /etc/os-release | awk -F= '{print $2}'` distro := `grep -G "\bID\b" /etc/os-release | awk -F= '{print $2}'`
release := `grep "VERSION_CODENAME" /etc/os-release | awk -F= '{print $2}'` release := `grep "VERSION_CODENAME" /etc/os-release | awk -F= '{print $2}'`
run_user := env_var("USER") run_user := env_var("USER")
archivebox_data := "/nfs/archivebox"
archivebox_nfs := "10.0.0.6:/mnt/coffeeNAS/archivebox"
default: common default: common
@ -35,7 +22,6 @@ common:
curl \ curl \
firewalld \ firewalld \
git \ git \
glances \
htop \ htop \
httpie \ httpie \
ifplugd \ ifplugd \
@ -65,13 +51,6 @@ caddy-install:
sudo apt update sudo apt update
sudo apt install caddy sudo apt install caddy
archivebox-mnt-nfs:
sudo mkdir -p {{archivebox_data}}
if ! df -h | grep "archivebox"; then sudo chown -R {{run_user}}:{{run_user}} {{archivebox_data}}; fi
if ! grep "archivebox" /etc/fstab; then echo "{{archivebox_nfs}} {{archivebox_data}} nfs4 soft,intr,rsize=8192,wsize=8192" | sudo tee -a /etc/fstab; fi
sudo systemctl daemon-reload
sudo mount -av
archivebox-install: archivebox-install:
sudo apt install -y pipx python3-dev python3-pip nodejs npm curl wget git ripgrep sudo apt install -y pipx python3-dev python3-pip nodejs npm curl wget git ripgrep
pipx install archivebox pipx install archivebox
@ -85,13 +64,6 @@ archivebox-init:
archivebox-setup: archivebox-setup:
cd {{archivebox_data}} && archivebox setup cd {{archivebox_data}} && archivebox setup
mastodon-aux-setup:
sudo cp -v "${PWD}/bin/mastodon-to-minio" /usr/local/bin/
sudo chmod +x /usr/local/bin/mastodon-to-minio
sudo cp -v "${PWD}/systemd/system/mastodon-to-minio.service" /etc/systemd/system/
sudo cp -v "${PWD}/systemd/system/mastodon-to-minio.timer" /etc/systemd/system/
sudo systemctl enable --now mastodon-to-minio.timer
thelounge-install: thelounge-install:
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 - 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 sudo apt install -y ./thelounge*.deb
@ -106,12 +78,6 @@ qbt-install:
sudo apt update sudo apt update
sudo apt install -y qbittorrent-cli sudo apt install -y qbittorrent-cli
qbittorrent-install:
sudo apt install -y qbittorrent-nox wireguard-tools lynx parallel wget curl httpie
qbittorrent-enable:
sudo systemctl enable --now qbittorrent-nox@{{run_user}}.service
scihub-setup: scihub-setup:
mkdir ~/scihub-torrent-urls mkdir ~/scihub-torrent-urls
lynx -dump -nonumbers -listonly=on https://libgen.rs/repository_torrent/ | grep "\.torrent" | tee ~/scihub-torrent-urls/urls.txt lynx -dump -nonumbers -listonly=on https://libgen.rs/repository_torrent/ | grep "\.torrent" | tee ~/scihub-torrent-urls/urls.txt

View File

@ -0,0 +1,14 @@
[Unit]
Description=mastodon-backup
AssertFileIsExecutable=/home/mastodon/bin/mastodon-backup
Requires=mnt-mastodon.mount
After=mnt-mastodon.mount
[Service]
Type=oneshot
User=mastodon
Group=mastodon
ExecStart=/home/mastodon/bin/mastodon-backup
[Install]
WantedBy=multi-user.target

View File

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

View File

@ -0,0 +1,15 @@
[Unit]
Description=mastodon-data NFS share from TrueNAS (10.0.0.81)
DefaultDependencies=no
Conflicts=umount.target
After=network-online.target remote-fs.target
Before=umount.target
[Mount]
What=10.0.0.81:/mnt/coffeeNAS/mastodon-data
Where=/mnt/mastodon
Type=nfs
Options=defaults
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Glances
After=network.target
AssertFileIsExecutable=/home/jas/.local/bin/glances
[Service]
ExecStart=/home/jas/.local/bin/glances -s
Restart=always
RemainAfterExit=no
[Install]
WantedBy=default.target