mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-01 08:03:05 +01:00
Archive various, add resend_error.py sync_remotes
This commit is contained in:
parent
ac5741d7b7
commit
b80e04397a
39
justfile
39
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:
|
||||
#!/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:
|
||||
#!/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:
|
||||
#!/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
|
||||
|
26
resend_error.py
Executable file
26
resend_error.py
Executable file
@ -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 <onboarding@resend.dev>",
|
||||
"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)
|
41
sync_remotes
Executable file
41
sync_remotes
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user