- Add scripts/ directory with numbered execution pattern - Create 00-check-dependencies.sh for requirement validation - Create 10-backup-files.sh for conflict handling - Create 20-setup-stow.sh for symlink creation - Create 90-post-install.sh for cleanup tasks - Add scripts/utils.sh with colored logging functions - Update install.sh to auto-discover and execute numbered scripts - Remove hardcoded logic in favor of flexible script discovery Benefits: - Clean separation of concerns (each script has one job) - Numbered execution order (SSH/systemd convention) - Colored output for better UX - Easy to extend with additional scripts - Same entry point for all branches
42 lines
1.1 KiB
Bash
42 lines
1.1 KiB
Bash
#!/bin/bash
|
|
# scripts/10-backup-files.sh - Backup existing files that would conflict
|
|
|
|
set -euo pipefail
|
|
|
|
# Source utilities
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/utils.sh"
|
|
|
|
backup_files() {
|
|
local dotfiles_dir="$1"
|
|
|
|
log_info "Checking for file conflicts..."
|
|
|
|
# Files that might conflict with stow
|
|
local files_to_check=(.bashrc .bash_aliases .inputrc .gitconfig)
|
|
local backed_up=()
|
|
|
|
for file in "${files_to_check[@]}"; do
|
|
if [ -f "$HOME/$file" ] && [ ! -L "$HOME/$file" ]; then
|
|
log_warning "Backing up existing file: $HOME/$file -> $HOME/${file}.bak"
|
|
mv "$HOME/$file" "$HOME/${file}.bak"
|
|
backed_up+=("$file")
|
|
fi
|
|
done
|
|
|
|
if [ ${#backed_up[@]} -gt 0 ]; then
|
|
log_info "Backed up ${#backed_up[@]} file(s): ${backed_up[*]}"
|
|
else
|
|
log_info "No file conflicts found"
|
|
fi
|
|
}
|
|
|
|
# Run if called directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
if [ $# -ne 1 ]; then
|
|
log_error "Usage: $0 <dotfiles_directory>"
|
|
exit 1
|
|
fi
|
|
backup_files "$1"
|
|
fi
|