1
0

feat: restructure dotfiles setup with bootstrap and setup scripts, enhance branch selection and backup processes

This commit is contained in:
2025-08-04 20:39:16 -05:00
parent 03150e539d
commit c366cd7789
9 changed files with 542 additions and 70 deletions

71
bootstrap.sh Normal file
View File

@@ -0,0 +1,71 @@
#!/bin/bash
set -euo pipefail
DOTFILES_REPO="https://gitea.purpleraft.com/ryan/dotfiles"
DOTFILES_DIR="$HOME/.dotfiles"
echo "Starting dotfiles bootstrap..."
# Clone repo (new installs) or update for branch switching
if [ -d "$DOTFILES_DIR/.git" ]; then
echo "Updating existing dotfiles repo..."
git -C "$DOTFILES_DIR" pull --quiet
else
echo "Cloning dotfiles into $DOTFILES_DIR..."
git clone "$DOTFILES_REPO" "$DOTFILES_DIR"
fi
cd "$DOTFILES_DIR"
# Branch selection - allows choosing which version of dotfiles to install
# - New installs: git clone defaults to 'main', but you can switch to any branch
# - Existing installs: switch from current branch to a different one
# - Only runs in interactive terminals (skipped in automated/CI environments)
if [ -t 0 ] && [ -t 1 ] && [ -d ".git" ]; then
current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
echo "Current branch: $current_branch"
echo
read -p "Switch to a different branch? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Available branches:"
git branch -a --format="%(refname:short)" | grep -v "HEAD" | sed 's|^origin/||' | sort -u | nl -w2 -s'. '
branches=($(git branch -a --format="%(refname:short)" | grep -v "HEAD" | sed 's|^origin/||' | sort -u))
while true; do
read -p "Enter branch number (1-${#branches[@]}): " branch_num
if [[ "$branch_num" =~ ^[0-9]+$ ]] && [ "$branch_num" -ge 1 ] && [ "$branch_num" -le "${#branches[@]}" ]; then
selected_branch="${branches[$((branch_num-1))]}"
echo "Switching to branch: $selected_branch"
if git show-ref --verify --quiet "refs/heads/$selected_branch"; then
git checkout "$selected_branch"
elif git show-ref --verify --quiet "refs/remotes/origin/$selected_branch"; then
git checkout -b "$selected_branch" "origin/$selected_branch"
else
echo "Error: Branch $selected_branch not found"
exit 1
fi
git pull --quiet || true
echo "Switched to branch: $selected_branch"
break
else
echo "Invalid selection. Please enter a number between 1 and ${#branches[@]}"
fi
done
fi
fi
# Hand off to setup
if [ -f "setup.sh" ]; then
echo "Starting setup..."
exec "./setup.sh"
else
echo "Error: No setup.sh found!"
exit 1
fi