From b80e04397a94480abc797228372e1acc97dcf550 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Mon, 23 Sep 2024 16:59:45 -0500 Subject: [PATCH] Archive various, add resend_error.py sync_remotes --- .../add_scihub_torrents.py | 0 .../seed_scihub_max_seeders.py | 0 justfile | 77 ++++++++++--------- ...ia_size.bash => record_mastodon_media_size | 0 resend_error.py | 26 +++++++ sync_remotes | 41 ++++++++++ 6 files changed, 109 insertions(+), 35 deletions(-) rename add_scihub_torrents.py => .archived/add_scihub_torrents.py (100%) rename seed_scihub_max_seeders.py => .archived/seed_scihub_max_seeders.py (100%) rename record_mastodon_media_size.bash => record_mastodon_media_size (100%) create mode 100755 resend_error.py create mode 100755 sync_remotes diff --git a/add_scihub_torrents.py b/.archived/add_scihub_torrents.py similarity index 100% rename from add_scihub_torrents.py rename to .archived/add_scihub_torrents.py diff --git a/seed_scihub_max_seeders.py b/.archived/seed_scihub_max_seeders.py similarity index 100% rename from seed_scihub_max_seeders.py rename to .archived/seed_scihub_max_seeders.py diff --git a/justfile b/justfile index 8ecf0b3..ded9849 100644 --- a/justfile +++ b/justfile @@ -2,21 +2,37 @@ ## ## Helps automate various homelab tasks. +set export distro := `grep -G "\bID\b" /etc/os-release | awk -F= '{print $2}'` +id_like := `grep -G "\bID_LIKE\b" /etc/os-release | awk -F= '{print $2}'` release := `grep "VERSION_CODENAME" /etc/os-release | awk -F= '{print $2}'` run_user := env_var("USER") caddy: - sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl - curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg - curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list - sudo apt update - sudo apt install caddy + #!/usr/bin/env sh + if [ "$distro" == "debian" ]; then + sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list + sudo apt update + sudo apt install caddy + elif echo "$id_like" | grep "rhel"; then + sudo dnf install -y 'dnf-command(copr)' + sudo dnf copr enable -y @caddy/caddy + sudo dnf install -y caddy + elif [ "$distro" == "freebsd" ]; then + sudo pkg install -y caddy + fi 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 - rm -fv ./thelounge*.deb + #!/usr/bin/env sh + if [ "$distro" == "debian" ]; then + 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 + rm -fv ./thelounge*.deb + else + echo "This justfile only supports The Lounge on Debian systems." + fi tailscale: curl -fsSL https://tailscale.com/install.sh | sh @@ -29,45 +45,36 @@ scihub: rm -fv ~/scihub-torrent-urls/urls.txt docker: - for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt remove $pkg; done - - sudo apt update - sudo apt install -y ca-certificates curl - sudo install -m 0755 -d /etc/apt/keyrings - sudo curl -fsSL https://download.docker.com/linux/{{distro}}/gpg -o /etc/apt/keyrings/docker.asc - sudo chmod a+r /etc/apt/keyrings/docker.asc - - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{distro}} {{release}} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - sudo apt update - sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose docker-compose-plugin - sudo systemctl enable --now docker.service - sudo usermod -aG docker {{run_user}} + #!/usr/bin/env sh + if [ "$distro" == "debian" ]; then + for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt remove $pkg; done + sudo apt update + sudo apt install -y ca-certificates curl + sudo install -m 0755 -d /etc/apt/keyrings + sudo curl -fsSL https://download.docker.com/linux/{{distro}}/gpg -o /etc/apt/keyrings/docker.asc + sudo chmod a+r /etc/apt/keyrings/docker.asc + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{distro}} {{release}} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt update + sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose docker-compose-plugin + sudo systemctl enable --now docker.service + sudo usermod -aG docker {{run_user}} + else + echo "This justfile only supports Docker on Debian systems." + fi rustup: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -rust-tools: - . "${HOME}/.cargo/env" - cargo install cargo-binstall - for pkg in "arp-scan" "bandwhich" "bat" "diskonaut" "du-dust" "fblog" "fd" "hyperfine" "procs" "ripgrep" "skim"; do \ - cargo-binstall -y "$pkg"; \ - done - neovim: sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' mkdir -p "${HOME}/.config/nvim" - wget https://cdn.hyperreal.coffee/init.vim -O "${HOME}/.config/nvim/init.vim" + wget https://files.hyperreal.coffee/init.vim -O "${HOME}/.config/nvim/init.vim" neovim-root: sudo sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' sudo mkdir -p /root/.config/nvim - sudo wget https://cdn.hyperreal.coffee/init.vim -O /root/.config/nvim/init.vim - -zshrc: - sudo wget https://cdn.hyperreal.coffee/zshrc -O /etc/zsh/zshrc - touch "${HOME}/.zshrc" - sudo touch /root/.zshrc + sudo wget https://files.hyperreal.coffee/init.vim -O /root/.config/nvim/init.vim diff --git a/record_mastodon_media_size.bash b/record_mastodon_media_size similarity index 100% rename from record_mastodon_media_size.bash rename to record_mastodon_media_size diff --git a/resend_error.py b/resend_error.py new file mode 100755 index 0000000..dcd59fd --- /dev/null +++ b/resend_error.py @@ -0,0 +1,26 @@ +#!/home/jas/virtualenvs/resend/bin/python +# +# Usage: +# 1. Create a virtualenv for resend under ~/virtualenvs/resend +# 2. Activate the virtualenv: `~/virtualenvs/resend/bin/activate` +# 3. Install resend API: `pip install resend` +# 4. Deactivate the virtualenv: `deactivate` +# 5. Make the script executable: `chmod +x /home/jas/bin/resend_error.py` +# 6. Run the script from another script or wherever: `/home/jas/bin/resend_error.py` + +import resend +import sys + +resend.api_key = "APIKEY GO HERE" + +msg = sys.argv[1] + +params: resend.Emails.SendParams = { + "from": "NAS ", + "to": ["hyperreal@fedoraproject.org"], + "subject": "[NAS] Sync error: " + msg, + "text": "There was an error syncing data: " + msg + ". Please investigate.", +} + +email = resend.Emails.send(params) +print(email) diff --git a/sync_remotes b/sync_remotes new file mode 100755 index 0000000..45190fc --- /dev/null +++ b/sync_remotes @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# I use this on my FreeBSD NAS to pull data from remotes and mirror +# it on my NAS. It runs via cron every two days. + +if [[ "$1" == "-q" ]]; then + exec >/dev/null 2>&1 +fi + +if ! zfs mount | awk '{print $2}' | grep "coffeeNAS" >/dev/null; then + if ! zpool import -f coffeeNAS; then + /home/jas/bin/resend_error.py "failed to import coffeeNAS pool" + logger -t sync-remotes "failed to import coffeeNAS pool" + exit 100 + else + logger -t sync-remotes "coffeeNAS pool is imported" + fi +fi + +if ! rsync -avz --delete root@hyperreal.coffee:/srv/borgbackup/hyperreal/ /coffeeNAS/borgbackup/repositories/hyperreal; then + /home/jas/bin/resend_error.py "hyperreal-borg" + logger -t sync-remotes "Error during sync of hyperreal-borg" +else + logger -t sync-remotes "hyperreal-borg successfully synced" +fi + +if ! rsync -avz --delete root@auxnc-96g:/srv/backup/auxnc-96g/ /coffeeNAS/borgbackup/repositories/auxnc-96g; then + /home/jas/bin/resend_error.py "auxnc-96g-borg" + logger -t sync-remotes "Error during sync of auxnc-96g-borg" +else + logger -t sync-remotes "auxnc-96g-borg successfully synced" +fi + +if ! rsync -avz --delete root@hyperreal.coffee:/home/mastodon/live/public/system/ /coffeeNAS/mastodata; then + /home/jas/bin/resend_error.py "mastodata" + logger -t sync-remotes "Error during sync of mastodata" +else + logger -t sync-remotes "mastodata successfully synced" +fi + +exit 0