forbi 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env bash
  2. # NAME: Setup dotfiles and Neovim configuration
  3. set -euo pipefail
  4. DOTFILES_REPO="https://git.mz.uy/marianozunino/dotfiles.git"
  5. NVIM_REPO="https://github.com/marianozunino/nvim.git"
  6. DOTFILES_DIR="$HOME/dotfiles"
  7. NVIM_CONFIG_DIR="$HOME/.config/nvim"
  8. echo "🏠 Setting up Forbi's development environment..."
  9. # ═══════════════════════════════════════════════════════════
  10. # 📁 CLONE DOTFILES
  11. # ═══════════════════════════════════════════════════════════
  12. echo "📦 Cloning dotfiles repository..."
  13. if [[ -d "$DOTFILES_DIR" ]]; then
  14. echo "→ Dotfiles directory already exists, updating..."
  15. cd "$DOTFILES_DIR"
  16. git pull origin main || git pull origin master
  17. else
  18. echo "→ Cloning dotfiles to $DOTFILES_DIR"
  19. git clone "$DOTFILES_REPO" "$DOTFILES_DIR"
  20. fi
  21. # ═══════════════════════════════════════════════════════════
  22. # 🔐 HANDLE GIT-CRYPT
  23. # ═══════════════════════════════════════════════════════════
  24. echo "🔐 Checking for git-crypt..."
  25. cd "$DOTFILES_DIR"
  26. # Check if repo uses git-crypt
  27. if [[ -f ".git-crypt/.gitattributes" ]] || git-crypt status &>/dev/null; then
  28. echo "→ git-crypt repository detected"
  29. # Check if already unlocked
  30. if git-crypt status | grep -q "unlocked"; then
  31. echo "→ Repository already unlocked"
  32. else
  33. echo "→ Repository is encrypted, attempting to unlock..."
  34. # Check if YubiKey/GPG setup is available
  35. if command -v gpg &>/dev/null; then
  36. echo "→ GPG found, checking for available keys..."
  37. # List secret keys to see if YubiKey is connected
  38. if gpg --list-secret-keys &>/dev/null; then
  39. echo "→ GPG keys detected, attempting git-crypt unlock..."
  40. # Attempt to unlock with GPG (YubiKey)
  41. if git-crypt unlock 2>/dev/null; then
  42. echo "✅ Repository unlocked successfully with GPG/YubiKey!"
  43. else
  44. echo "❌ Failed to unlock with GPG"
  45. echo
  46. echo "🔑 Manual unlock required:"
  47. echo " 1. Make sure your YubiKey is connected"
  48. echo " 2. Test GPG: gpg --card-status"
  49. echo " 3. Try: cd $DOTFILES_DIR && git-crypt unlock"
  50. echo " 4. Or unlock with key file: git-crypt unlock /path/to/key"
  51. echo " 5. Then re-run: ./run forbi"
  52. echo
  53. exit 1
  54. fi
  55. else
  56. echo "❌ No GPG secret keys found"
  57. echo
  58. echo "🔑 YubiKey/GPG setup needed:"
  59. echo " 1. Connect your YubiKey"
  60. echo " 2. Import your GPG key: gpg --card-status"
  61. echo " 3. Set trust level: gpg --edit-key <your-key-id> trust"
  62. echo " 4. Then re-run: ./run forbi"
  63. echo
  64. exit 1
  65. fi
  66. else
  67. echo "❌ GPG not available"
  68. echo
  69. echo "🔑 To unlock your dotfiles:"
  70. echo " 1. Install GPG and connect YubiKey, or"
  71. echo " 2. Use key file: cd $DOTFILES_DIR && git-crypt unlock /path/to/key"
  72. echo " 3. Then re-run: ./run forbi"
  73. echo
  74. exit 1
  75. fi
  76. fi
  77. else
  78. echo "→ No git-crypt encryption detected"
  79. fi
  80. # ═══════════════════════════════════════════════════════════
  81. # ⚙️ CLONE NEOVIM CONFIG
  82. # ═══════════════════════════════════════════════════════════
  83. echo "📝 Setting up Neovim configuration..."
  84. # Backup existing Neovim config if it exists
  85. if [[ -d "$NVIM_CONFIG_DIR" ]]; then
  86. BACKUP_DIR="$NVIM_CONFIG_DIR.backup.$(date +%Y%m%d_%H%M%S)"
  87. echo "→ Backing up existing Neovim config to $BACKUP_DIR"
  88. mv "$NVIM_CONFIG_DIR" "$BACKUP_DIR"
  89. fi
  90. # Clone Neovim configuration
  91. echo "→ Cloning Neovim config to $NVIM_CONFIG_DIR"
  92. git clone "$NVIM_REPO" "$NVIM_CONFIG_DIR"
  93. # ═══════════════════════════════════════════════════════════
  94. # 🔧 CONFIGURE GIT HOOKS
  95. # ═══════════════════════════════════════════════════════════
  96. echo "🎣 Setting up Git hooks for Neovim config..."
  97. cd "$NVIM_CONFIG_DIR"
  98. if [[ -d ".githooks" ]]; then
  99. git config core.hooksPath .githooks
  100. echo "→ Git hooks configured"
  101. else
  102. echo "→ No .githooks directory found, skipping"
  103. fi
  104. # ═══════════════════════════════════════════════════════════
  105. # 📂 CREATE NECESSARY DIRECTORIES
  106. # ═══════════════════════════════════════════════════════════
  107. echo "📂 Creating necessary directories..."
  108. # Create .config directory if it doesn't exist
  109. mkdir -p "$HOME/.config"
  110. # Create common development directories
  111. mkdir -p "$HOME/Dev"
  112. mkdir -p "$HOME/.local/bin"
  113. echo
  114. echo "# Install everything"
  115. echo "stow */"
  116. echo
  117. echo "# Or install individual modules"
  118. echo "stow zsh"
  119. echo "stow nvim"
  120. echo "stow sway"
  121. echo
  122. echo "Run these commands in: $DOTFILES_DIR"
  123. # ═══════════════════════════════════════════════════════════
  124. # 📋 SUMMARY & NEXT STEPS
  125. # ═══════════════════════════════════════════════════════════
  126. echo
  127. echo "📁 Locations:"
  128. echo " • Dotfiles: $DOTFILES_DIR"
  129. echo " • Neovim config: $NVIM_CONFIG_DIR"