60 lines
1.8 KiB
Bash
60 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# scripts/20-setup-stow.sh - Handle GNU Stow operations
|
|
|
|
set -euo pipefail
|
|
|
|
# Source utilities
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/utils.sh"
|
|
|
|
setup_stow() {
|
|
local dotfiles_dir="$1"
|
|
|
|
if [ -d "$dotfiles_dir/stow" ]; then
|
|
# Use new stow structure - stow each subdirectory individually
|
|
cd "$dotfiles_dir/stow"
|
|
log_info "Using Stow to symlink dotfiles from stow/ subdirectories..."
|
|
|
|
local stowed=()
|
|
|
|
for config_dir in *; do
|
|
if [ -d "$config_dir" ]; then
|
|
log_info "Stowing $config_dir configuration..."
|
|
|
|
if ! stow --adopt -t "$HOME" "$config_dir" 2>/dev/null; then
|
|
log_warning "Adopting failed for $config_dir, trying regular stow..."
|
|
stow -t "$HOME" "$config_dir"
|
|
fi
|
|
|
|
stowed+=("$config_dir")
|
|
fi
|
|
done
|
|
|
|
if [ ${#stowed[@]} -gt 0 ]; then
|
|
log_success "Stowed ${#stowed[@]} configuration(s): ${stowed[*]}"
|
|
else
|
|
log_warning "No stow subdirectories found in $dotfiles_dir/stow"
|
|
fi
|
|
else
|
|
# Fallback to old structure - stow entire directory
|
|
cd "$dotfiles_dir"
|
|
log_info "Using Stow to symlink dotfiles from root directory..."
|
|
|
|
if ! stow --adopt -t "$HOME" . 2>/dev/null; then
|
|
log_warning "Adopting failed, trying regular stow..."
|
|
stow -t "$HOME" .
|
|
fi
|
|
|
|
log_success "Stow setup complete"
|
|
fi
|
|
}
|
|
|
|
# Run if called directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
if [ $# -ne 1 ]; then
|
|
log_error "Usage: $0 <dotfiles_directory>"
|
|
exit 1
|
|
fi
|
|
setup_stow "$1"
|
|
fi
|