#!/usr/bin/env bash set -euo pipefail VERSION="1.0.0" # UPDATE THESE FOR YOUR REPO BASE_URL="${BASE_URL:-https://raw.githubusercontent.com///main}" CONFIG_DIR="/etc/restic-backup" CONFIG_FILE="$CONFIG_DIR/config" EXCLUDES_FILE="$CONFIG_DIR/excludes" PRE_HOOKS_DIR="$CONFIG_DIR/pre-backup.d" STATE_DIR="/var/lib/restic-backup" MOTD_SCRIPT="/etc/update-motd.d/90-restic-backup-status" SERVICE_FILE="/etc/systemd/system/restic-backup.service" TIMER_FILE="/etc/systemd/system/restic-backup.timer" README_ETC="$CONFIG_DIR/README.md" FORCE_CONFIG="${1:-}" echo "Restic backup installer v${VERSION}" if [[ "$EUID" -ne 0 ]]; then echo "This installer must be run as root (use sudo)." >&2 exit 1 fi if ! command -v systemctl >/dev/null 2>&1; then echo "systemd is required." >&2 exit 1 fi if ! command -v apt-get >/dev/null 2>&1; then echo "This installer expects an apt-based system (Ubuntu/Debian)." >&2 exit 1 fi echo "Installing dependencies (restic, curl)..." apt-get update -y >/dev/null apt-get install -y restic curl >/dev/null echo "Creating directories..." mkdir -p "$CONFIG_DIR" "$PRE_HOOKS_DIR" "$STATE_DIR" chmod 750 "$CONFIG_DIR" "$PRE_HOOKS_DIR" "$STATE_DIR" # ------------------ # CONFIG FILE # ------------------ if [[ -f "$CONFIG_FILE" && "$FORCE_CONFIG" != "--force-config" ]]; then echo "Config file already exists at $CONFIG_FILE" echo "Leaving it unchanged. To reconfigure, rerun with: --force-config" else if [[ -f "$CONFIG_FILE" && "$FORCE_CONFIG" == "--force-config" ]]; then echo "Reconfiguring existing $CONFIG_FILE" else echo "Creating new config at $CONFIG_FILE" fi read -rp "Restic repository name (will be created in Backblaze B2): " RESTIC_REPO read -rp "Backblaze B2 Account ID: " B2_ACCOUNT_ID read -rp "Backblaze B2 Application Key: " B2_ACCOUNT_KEY read -srp "Restic repository password: " RESTIC_PASSWORD echo read -rp "ntfy URL (e.g. https://ntfy.example.com/topic): " NTFY_URL read -srp "ntfy auth key (Bearer token): " NTFY_AUTH_KEY echo read -rp "Heartbeat URL (optional, press Enter to skip): " HEARTBEAT_URL cat >"$CONFIG_FILE" <"$EXCLUDES_FILE" <"$README_ETC" <