dev: automated commit - 2025-06-08 23:28:55
This commit is contained in:
parent
33106ea4a6
commit
0ab9f62ace
13 changed files with 1255 additions and 715 deletions
229
runs/dotfiles
229
runs/dotfiles
|
@ -1,151 +1,118 @@
|
|||
#!/usr/bin/env bash
|
||||
# NAME: Setup dotfiles and Neovim configuration
|
||||
# NAME: Setup dotfiles and configuration
|
||||
# REQUIRES: interactive
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DOTFILES_REPO="https://git.mz.uy/marianozunino/dotfiles.git"
|
||||
NVIM_REPO="https://github.com/marianozunino/nvim.git"
|
||||
DOTFILES_DIR="$HOME/dotfiles"
|
||||
NVIM_CONFIG_DIR="$HOME/.config/nvim"
|
||||
# Source common functions
|
||||
source "$(dirname "$0")/../common.sh" || {
|
||||
echo "[ERROR] Could not source common.sh" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "🏠 Setting up Forbi's development environment..."
|
||||
readonly DOTFILES_REPO="https://git.mz.uy/marianozunino/dotfiles.git"
|
||||
readonly DOTFILES_DIR="$HOME/dotfiles"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 📁 CLONE DOTFILES
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo "📦 Cloning dotfiles repository..."
|
||||
check_requirements() {
|
||||
local required_commands=(git git-crypt stow)
|
||||
|
||||
if [[ -d "$DOTFILES_DIR" ]]; then
|
||||
echo "→ Dotfiles directory already exists, updating..."
|
||||
cd "$DOTFILES_DIR"
|
||||
git pull origin main || git pull origin master
|
||||
else
|
||||
echo "→ Cloning dotfiles to $DOTFILES_DIR"
|
||||
git clone "$DOTFILES_REPO" "$DOTFILES_DIR"
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 🔐 HANDLE GIT-CRYPT
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo "🔐 Checking for git-crypt..."
|
||||
|
||||
cd "$DOTFILES_DIR"
|
||||
|
||||
# Check if repo uses git-crypt
|
||||
if [[ -f ".git-crypt/.gitattributes" ]] || git-crypt status &>/dev/null; then
|
||||
echo "→ git-crypt repository detected"
|
||||
|
||||
# Check if already unlocked
|
||||
if git-crypt status | grep -q "unlocked"; then
|
||||
echo "→ Repository already unlocked"
|
||||
else
|
||||
echo "→ Repository is encrypted, attempting to unlock..."
|
||||
|
||||
# Check if YubiKey/GPG setup is available
|
||||
if command -v gpg &>/dev/null; then
|
||||
echo "→ GPG found, checking for available keys..."
|
||||
|
||||
# List secret keys to see if YubiKey is connected
|
||||
if gpg --list-secret-keys &>/dev/null; then
|
||||
echo "→ GPG keys detected, attempting git-crypt unlock..."
|
||||
|
||||
# Attempt to unlock with GPG (YubiKey)
|
||||
if git-crypt unlock 2>/dev/null; then
|
||||
echo "✅ Repository unlocked successfully with GPG/YubiKey!"
|
||||
else
|
||||
echo "❌ Failed to unlock with GPG"
|
||||
echo
|
||||
echo "🔑 Manual unlock required:"
|
||||
echo " 1. Make sure your YubiKey is connected"
|
||||
echo " 2. Test GPG: gpg --card-status"
|
||||
echo " 3. Try: cd $DOTFILES_DIR && git-crypt unlock"
|
||||
echo " 4. Or unlock with key file: git-crypt unlock /path/to/key"
|
||||
echo " 5. Then re-run: ./run forbi"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "❌ No GPG secret keys found"
|
||||
echo
|
||||
echo "🔑 YubiKey/GPG setup needed:"
|
||||
echo " 1. Connect your YubiKey"
|
||||
echo " 2. Import your GPG key: gpg --card-status"
|
||||
echo " 3. Set trust level: gpg --edit-key <your-key-id> trust"
|
||||
echo " 4. Then re-run: ./run forbi"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "❌ GPG not available"
|
||||
echo
|
||||
echo "🔑 To unlock your dotfiles:"
|
||||
echo " 1. Install GPG and connect YubiKey, or"
|
||||
echo " 2. Use key file: cd $DOTFILES_DIR && git-crypt unlock /path/to/key"
|
||||
echo " 3. Then re-run: ./run forbi"
|
||||
echo
|
||||
for cmd in "${required_commands[@]}"; do
|
||||
if ! command_exists "$cmd"; then
|
||||
log_error "Required command not found: $cmd"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
clone_dotfiles() {
|
||||
log_info "Setting up dotfiles repository"
|
||||
|
||||
if [[ -d "$DOTFILES_DIR" ]]; then
|
||||
log_info "Dotfiles directory already exists, updating"
|
||||
cd "$DOTFILES_DIR"
|
||||
git pull origin main || git pull origin master
|
||||
else
|
||||
log_info "Cloning dotfiles to $DOTFILES_DIR"
|
||||
git clone "$DOTFILES_REPO" "$DOTFILES_DIR"
|
||||
fi
|
||||
else
|
||||
echo "→ No git-crypt encryption detected"
|
||||
fi
|
||||
}
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# ⚙️ CLONE NEOVIM CONFIG
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo "📝 Setting up Neovim configuration..."
|
||||
handle_git_crypt() {
|
||||
log_info "Checking git-crypt status"
|
||||
cd "$DOTFILES_DIR"
|
||||
|
||||
# Backup existing Neovim config if it exists
|
||||
if [[ -d "$NVIM_CONFIG_DIR" ]]; then
|
||||
BACKUP_DIR="$NVIM_CONFIG_DIR.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
echo "→ Backing up existing Neovim config to $BACKUP_DIR"
|
||||
mv "$NVIM_CONFIG_DIR" "$BACKUP_DIR"
|
||||
fi
|
||||
if git-crypt status | grep -q "unlocked"; then
|
||||
log_info "Repository already unlocked"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Clone Neovim configuration
|
||||
echo "→ Cloning Neovim config to $NVIM_CONFIG_DIR"
|
||||
git clone "$NVIM_REPO" "$NVIM_CONFIG_DIR"
|
||||
log_info "Repository is encrypted, attempting to unlock"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 🔧 CONFIGURE GIT HOOKS
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo "🎣 Setting up Git hooks for Neovim config..."
|
||||
if gpg --card-status &>/dev/null; then
|
||||
log_info "YubiKey detected, fetching public key"
|
||||
|
||||
cd "$NVIM_CONFIG_DIR"
|
||||
if [[ -d ".githooks" ]]; then
|
||||
git config core.hooksPath .githooks
|
||||
echo "→ Git hooks configured"
|
||||
else
|
||||
echo "→ No .githooks directory found, skipping"
|
||||
fi
|
||||
local key_id
|
||||
key_id=$(gpg --card-status 2>/dev/null | grep "General key info" -A 1 | tail -1 | awk '{print $1}' | sed 's/.*\///')
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 📂 CREATE NECESSARY DIRECTORIES
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo "📂 Creating necessary directories..."
|
||||
if [[ -n "$key_id" ]] && ! gpg --list-keys "$key_id" &>/dev/null; then
|
||||
gpg --card-edit --batch --command-fd 0 <<<"fetch" &>/dev/null ||
|
||||
gpg --keyserver hkps://keys.openpgp.org --recv-keys "$key_id" &>/dev/null || true
|
||||
fi
|
||||
else
|
||||
log_error "YubiKey not detected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create .config directory if it doesn't exist
|
||||
mkdir -p "$HOME/.config"
|
||||
if git-crypt unlock 2>/dev/null; then
|
||||
log_info "Repository unlocked successfully"
|
||||
else
|
||||
log_error "Failed to unlock repository"
|
||||
log_info "Manual unlock required: cd $DOTFILES_DIR && git-crypt unlock"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Create common development directories
|
||||
mkdir -p "$HOME/Dev"
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
create_directories() {
|
||||
log_info "Creating necessary directories"
|
||||
mkdir -p "$HOME/.config" "$HOME/Dev" "$HOME/.local/bin"
|
||||
}
|
||||
|
||||
echo
|
||||
echo "# Install everything"
|
||||
echo "stow */"
|
||||
echo
|
||||
echo "# Or install individual modules"
|
||||
echo "stow zsh"
|
||||
echo "stow nvim"
|
||||
echo "stow sway"
|
||||
echo
|
||||
echo "Run these commands in: $DOTFILES_DIR"
|
||||
stow_packages() {
|
||||
cd "$DOTFILES_DIR"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# 📋 SUMMARY & NEXT STEPS
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
echo
|
||||
echo "📁 Locations:"
|
||||
echo " • Dotfiles: $DOTFILES_DIR"
|
||||
echo " • Neovim config: $NVIM_CONFIG_DIR"
|
||||
log_info "Available stow packages:"
|
||||
for dir in */; do
|
||||
if [[ -d "$dir" ]]; then
|
||||
log_info " ${dir%/}"
|
||||
fi
|
||||
done
|
||||
|
||||
if confirm "Stow all packages?" "y"; then
|
||||
log_info "Stowing all packages"
|
||||
if stow */; then
|
||||
log_info "All packages stowed successfully"
|
||||
else
|
||||
log_error "Some packages failed to stow. Check for conflicts"
|
||||
fi
|
||||
else
|
||||
log_info "Skipping automatic stow. Run manually:"
|
||||
log_info " cd $DOTFILES_DIR"
|
||||
log_info " stow <package_name>"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
init_script
|
||||
|
||||
check_requirements
|
||||
clone_dotfiles
|
||||
handle_git_crypt
|
||||
create_directories
|
||||
stow_packages
|
||||
|
||||
log_info "Dotfiles location: $DOTFILES_DIR"
|
||||
|
||||
finish_script 0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue