dotfiles 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"