#!/usr/bin/env bash # # Copyright (c) 2025. Anshul Gupta # All rights reserved. # set -eu GREEN='\033[0;32m' ELEPHANT='\xF0\x9F\x90\x98' NC='\033[0m' START_MARKER='<< ADDED BY setup.sh >>' END_MARKER='<< END ADDED BY setup.sh >>' # renovate: datasource=github-releases depName=restic/restic RESTIC_VERSION="0.18.0" # renovate: datasource=github-releases depName=creativeprojects/resticprofile RESTICPROFILE_VERSION="0.31.0" OP_SERVICE_ACCOUNT_TOKEN=$(cat "1password.txt") export OP_SERVICE_ACCOUNT_TOKEN log() { echo -e "${GREEN}${ELEPHANT} $1${NC}" } cleanup() { log "Cleaning up..." # Cleanup root log "Cleaning up root..." rm -rf root log "Done." } copy_root() { log "Copy root files..." # Install rsync if not installed if ! command -v rsync &> /dev/null; then log "rsync could not be found. Installing it..." apt-get install -y rsync fi log "Setting permissions..." chown -R root:root root/etc chown -R root:root root/usr log "Copying files..." rsync -a --verbose root/ / } install_packages() { log "Installing required packages..." apt-get update xargs apt-get install -o DPkg::Options::="--force-confold" -y < packages.txt } install_ca() { log "Installing CA certificates..." wget -O /home/anshulgupta/ca.crt http://privateca-content-64cbe468-0000-233e-beaa-14223bc3fa9e.storage.googleapis.com/c745acb2f145f7f9e343/ca.crt chmod 644 /home/anshulgupta/ca.crt cp /home/anshulgupta/ca.crt /usr/local/share/ca-certificates/anshulg.crt update-ca-certificates } setup_firewall() { log "Setting up firewall..." # Enable and start nftables systemctl enable nftables systemctl start nftables # Manually load the rules nft -f /etc/nftables.conf log "Firewall rules loaded successfully." } setup_mta() { log "Setting up Mail Transfer Agent (MTA)..." FASTMAIL_USER=$(op read "op://RPI4/RPI4 Fastmail Password/username") FASTMAIL_PASS=$(op read "op://RPI4/RPI4 Fastmail Password/password") log "Configuring /etc/mailname..." echo "rpi4.anshulg.com" > /etc/mailname chown root:root /etc/mailname chmod 644 /etc/mailname log "Writing Postfix SASL credentials..." install -m 600 -o root -g root /dev/null /etc/postfix/sasl_passwd cat >/etc/postfix/sasl_passwd </dev/null 2>&1; then log "Adding Zeyple user..." adduser --system --no-create-home --disabled-login zeyple fi # Create Zeyple directories chmod 700 /var/lib/zeyple/keys chown -R zeyple: /var/lib/zeyple/keys touch /var/log/zeyple.log && chown zeyple: /var/log/zeyple.log # Download Zeyple log "Downloading Zeyple..." wget -qO /usr/local/bin/zeyple "https://github.com/ansg191/zeyple/raw/refs/heads/signing/zeyple/zeyple.py" chmod 744 /usr/local/bin/zeyple chown zeyple: /usr/local/bin/zeyple # Modify postfix master.cf to use Zeyple log "Configuring Postfix to use Zeyple..." read -r -d '' POSTFIX_CF < /etc/bash_completion.d/resticprofile chmod +x /etc/bash_completion.d/resticprofile } setup_backup() { log "Setting up backups..." local REST_USERNAME local REST_PASSWORD REST_USERNAME=$(op read -n "op://RPI4/RPI4 Restic Password/username") REST_PASSWORD=$(op read -n "op://RPI4/RPI4 Restic Password/password") op read --out-file /etc/resticprofile/password.txt -f "op://RPI4/RPI4 Restic Password/rpi4.txt" # Create 10auth.conf file cat < /etc/resticprofile/10auth.conf [Service] Environment=RESTIC_REST_USERNAME=$REST_USERNAME Environment="RESTIC_REST_PASSWORD=$REST_PASSWORD" EOF chmod 600 /etc/resticprofile/10auth.conf log "Scheduling backups..." resticprofile schedule } trap cleanup EXIT copy_root install_packages install_ca setup_firewall setup_mta setup_zeyple setup_issuer setup_postgres install_restic setup_backup