89 lines
1.8 KiB
Bash
89 lines
1.8 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# Backup script for archypr configuration system
|
||
|
|
# This script is versioned in the archypr-config git repo
|
||
|
|
# and should be run from ~/archypr-config/
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
BRANCH_FILE="$REPO_DIR/.machine-branch"
|
||
|
|
MACHINE_NAME="${HOSTNAME:-$(hostname)}"
|
||
|
|
|
||
|
|
# Read branch from config, or derive from hostname
|
||
|
|
if [[ -f $BRANCH_FILE ]]; then
|
||
|
|
BRANCH=$(cat "$BRANCH_FILE")
|
||
|
|
else
|
||
|
|
BRANCH="$MACHINE_NAME"
|
||
|
|
fi
|
||
|
|
|
||
|
|
cd "$REPO_DIR"
|
||
|
|
|
||
|
|
# Ensure we're on the right branch
|
||
|
|
if ! git branch --list "$BRANCH" | grep -q "$BRANCH"; then
|
||
|
|
git checkout -b "$BRANCH" main 2>/dev/null || git checkout -b "$BRANCH"
|
||
|
|
echo "Created branch: $BRANCH"
|
||
|
|
fi
|
||
|
|
git checkout "$BRANCH" 2>/dev/null || true
|
||
|
|
|
||
|
|
# Config directories to sync
|
||
|
|
CONFIG_DIRS=(
|
||
|
|
"hypr"
|
||
|
|
"waybar"
|
||
|
|
"walker"
|
||
|
|
"mako"
|
||
|
|
"swayosd"
|
||
|
|
"elephant"
|
||
|
|
"kitty"
|
||
|
|
"ghostty"
|
||
|
|
"alacritty"
|
||
|
|
"btop"
|
||
|
|
"fastfetch"
|
||
|
|
"autostart"
|
||
|
|
)
|
||
|
|
|
||
|
|
sync_configs() {
|
||
|
|
echo "--- Syncing configs..."
|
||
|
|
for dir in "${CONFIG_DIRS[@]}"; do
|
||
|
|
local src="$HOME/.config/$dir"
|
||
|
|
local dst="$REPO_DIR/configs/$dir"
|
||
|
|
if [[ -d $src ]]; then
|
||
|
|
mkdir -p "$dst"
|
||
|
|
rsync -a --delete "$src"/ "$dst"/
|
||
|
|
echo " Synced: $dir"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
}
|
||
|
|
|
||
|
|
check_and_push() {
|
||
|
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||
|
|
local timestamp
|
||
|
|
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||
|
|
git add -A
|
||
|
|
git commit -m "Auto-backup $BRANCH $timestamp"
|
||
|
|
git push -u origin "$BRANCH" 2>&1 || echo "WARNING: Push failed — check connection"
|
||
|
|
echo "--- Backed up at $timestamp"
|
||
|
|
else
|
||
|
|
echo "--- No changes to commit"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
case "${1:-}" in
|
||
|
|
restore)
|
||
|
|
"$REPO_DIR/restore.sh"
|
||
|
|
;;
|
||
|
|
check-only)
|
||
|
|
sync_configs
|
||
|
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||
|
|
echo "Changes detected"
|
||
|
|
exit 0
|
||
|
|
else
|
||
|
|
echo "No changes"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
sync_configs
|
||
|
|
check_and_push
|
||
|
|
;;
|
||
|
|
esac
|