Files
archypr/restore.sh
T

67 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
# Restore script for archypr configuration system
# Restores configs from git backup to ~/.config/
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BRANCH_FILE="$REPO_DIR/.machine-branch"
MACHINE_NAME="${HOSTNAME:-$(hostname)}"
if [[ -f $BRANCH_FILE ]]; then
BRANCH=$(cat "$BRANCH_FILE")
else
BRANCH="$MACHINE_NAME"
fi
cd "$REPO_DIR"
# Pull latest from remote
echo "--- Pulling latest from origin..."
git fetch origin "$BRANCH" 2>/dev/null || true
git checkout "$BRANCH" 2>/dev/null || git checkout -b "$BRANCH" 2>/dev/null || true
# Backup current configs before restoring
TIMESTAMP=$(date '+%Y%m%d_%H%M%S')
BACKUP_DIR="/tmp/archypr-config-restore-backup-$TIMESTAMP"
mkdir -p "$BACKUP_DIR"
CONFIG_DIRS=(
"hypr"
"waybar"
"walker"
"mako"
"swayosd"
"elephant"
"kitty"
"ghostty"
"alacritty"
"btop"
"fastfetch"
"autostart"
)
echo "--- Backing up current configs to $BACKUP_DIR ..."
for dir in "${CONFIG_DIRS[@]}"; do
local src="$HOME/.config/$dir"
if [[ -d $src ]]; then
cp -a "$src" "$BACKUP_DIR/"
echo " Backed up: $dir"
fi
done
# Restore configs from repo
echo "--- Restoring configs from backup..."
for dir in "${CONFIG_DIRS[@]}"; do
local src="$REPO_DIR/configs/$dir"
local dst="$HOME/.config/$dir"
if [[ -d $src ]]; then
mkdir -p "$(dirname "$dst")"
rsync -a "$src"/ "$dst"/
echo " Restored: $dir"
fi
done
echo "--- Restore complete. Previous configs saved to: $BACKUP_DIR"
echo " To undo: rsync -a $BACKUP_DIR/* ~/.config/"