#!/usr/bin/env bash # Portable dotfiles restore script — generated by dotfiles_manager.sh # Run on a new machine after: git clone http://172.27.0.35:3000/kenjim/dotfiles ~/dotfiles set -euo pipefail DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MANIFEST="$DOTFILES_DIR/.dotfiles_manifest" BACKUP_DIR="$HOME/.dotfiles_backup/$(date +%Y%m%d_%H%M%S)" echo "=== Restoring dotfiles from $DOTFILES_DIR ===" [ -f "$MANIFEST" ] || { echo "No manifest found."; exit 1; } while IFS= read -r rel || [ -n "$rel" ]; do [ -z "$rel" ] && continue src="$DOTFILES_DIR/$rel" dest="$HOME/$rel" [ -e "$src" ] || { echo " MISSING: $src"; continue; } mkdir -p "$(dirname "$dest")" if [ -e "$dest" ] && [ ! -L "$dest" ]; then mkdir -p "$BACKUP_DIR/$(dirname "$rel")" cp -a "$dest" "$BACKUP_DIR/$rel" echo " Backed up: $dest" rm -f "$dest" elif [ -L "$dest" ]; then rm "$dest" fi [[ "$rel" == .ssh/* ]] && chmod 600 "$src" 2>/dev/null || true ln -sf "$src" "$dest" echo " Linked: ~/$rel" done < "$MANIFEST" echo echo "✓ Dotfiles symlinks applied." # ---- Machine-local config ---- # Write a minimal .bashrc.local if one does not exist (user edits profile) if [ ! -f "$HOME/.bashrc.local" ]; then echo echo "Select profile for this machine:" echo " [1] work — OneDrive" echo " [2] personal — ProtonDrive + GoogleDrive" read -r -p "Profile (1/2) [2]: " _choice _profile="personal" [[ "${_choice:-2}" == "1" ]] && _profile="work" # setup script lives inside dotfiles now: dotfiles/scripts/setup_enterprise_ai_bash.sh if [ -f "$DOTFILES_DIR/scripts/setup_enterprise_ai_bash.sh" ]; then MACHINE_PROFILE="$_profile" bash "$DOTFILES_DIR/scripts/setup_enterprise_ai_bash.sh" else echo " ⚠ Could not find setup_enterprise_ai_bash.sh — create ~/.bashrc.local manually." fi fi # ---- SSH key decrypt ---- gpg_count=$(find "$DOTFILES_DIR/.ssh/keys" -maxdepth 1 -name '*.gpg' 2>/dev/null | wc -l | tr -d ' ') if [[ "$gpg_count" -gt 0 ]]; then echo echo "Found $gpg_count GPG-encrypted SSH key(s) in dotfiles." read -r -p "Decrypt SSH private keys now? (y/n): " _dec if [[ "$_dec" == [yY] ]]; then # dotfiles_manager.sh lives inside dotfiles now: dotfiles/scripts/dotfiles_manager.sh bash "$DOTFILES_DIR/scripts/dotfiles_manager.sh" ssh-import fi fi echo echo "✓ Restore complete. Run: source ~/.bash_profile"