#!/usr/bin/env bash # Pull current router config into config/ and commit if there are changes. set -euo pipefail ROUTER="${ROUTER:-openwrt}" CONFIGS=(dhcp dropbear firewall network system wireless) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CONFIG_DIR="$SCRIPT_DIR/../config" echo "Pulling config from $ROUTER..." for f in "${CONFIGS[@]}"; do ssh "$ROUTER" "cat /etc/config/$f" > "$CONFIG_DIR/$f" echo " $f" done cd "$SCRIPT_DIR/.." if git diff --quiet && git diff --cached --quiet; then echo "No changes — config is up to date." else echo "" git diff --stat config/ echo "" read -rp "Commit these changes? [y/N] " answer if [[ "${answer,,}" == "y" ]]; then git add config/ git commit -m "backup: pull config from router $(date '+%Y-%m-%d %H:%M')" echo "Committed." fi fi