Last active
January 4, 2026 04:44
-
-
Save JunseokH/26cde6533f4e6b384b8d3695109fbf68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Bootstrap script for fresh macOS setup with chezmoi dotfiles | |
| # Usage: curl -fsSL https://gist.githubusercontent.com/.../bootstrap.sh | bash | |
| set -euo pipefail | |
| echo "π Starting dotfiles bootstrap..." | |
| # 1. Install Homebrew if not present | |
| if ! command -v brew &>/dev/null; then | |
| echo "π¦ Installing Homebrew..." | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| # Add Homebrew to PATH (Apple Silicon) | |
| if [ -d /opt/homebrew/bin ]; then | |
| eval "$(/opt/homebrew/bin/brew shellenv)" | |
| fi | |
| echo "β Homebrew installed" | |
| else | |
| echo "β Homebrew already installed" | |
| fi | |
| # 2. Install essential packages | |
| echo "π¦ Installing chezmoi and gnupg..." | |
| brew install chezmoi gnupg | |
| echo "β Essential packages installed" | |
| # 3. Setup iCloud Secret directory (auto-create if missing) | |
| ICLOUD_SECRET="$HOME/iCloud/Shared/Secret" | |
| if [ ! -d "$ICLOUD_SECRET" ]; then | |
| echo "π Creating iCloud Secret directory structure..." | |
| mkdir -p "$ICLOUD_SECRET"/{gpg,ssh} | |
| cat > "$ICLOUD_SECRET/README.md" <<'EOREADME' | |
| # iCloud Secret Directory | |
| This directory stores sensitive files that should NOT be committed to Git. | |
| ## Structure | |
| - gpg/ - GPG private keys | |
| - ssh/ - SSH private keys | |
| ## Setup Instructions | |
| See chezmoi repository: docs/icloud-secret-setup.md | |
| EOREADME | |
| echo "β οΈ iCloud Secret directory created but empty." | |
| echo " Please export GPG and SSH keys to:" | |
| echo " - $ICLOUD_SECRET/gpg/" | |
| echo " - $ICLOUD_SECRET/ssh/" | |
| echo "" | |
| echo " See setup guide in chezmoi repo after initialization." | |
| fi | |
| # 4. Get machine type from user | |
| read "?Enter machine type (work/personal): " MACHINE_TYPE | |
| while [[ ! "$MACHINE_TYPE" =~ ^(work|personal)$ ]]; do | |
| echo "β Invalid input. Please enter 'work' or 'personal'" | |
| read "?Enter machine type (work/personal): " MACHINE_TYPE | |
| done | |
| # 5. Import GPG key from iCloud | |
| echo "π Importing GPG key..." | |
| GPG_KEY_PATH="$ICLOUD_SECRET/gpg/private-key-$MACHINE_TYPE.asc" | |
| if [ -f "$GPG_KEY_PATH" ]; then | |
| gpg --import "$GPG_KEY_PATH" | |
| echo "β GPG key imported" | |
| else | |
| echo "β οΈ GPG key not found at: $GPG_KEY_PATH" | |
| echo " You'll need to import it manually later." | |
| echo " Command: gpg --import $GPG_KEY_PATH" | |
| fi | |
| # 6. Setup SSH key for GitHub access (required for private repo) | |
| echo "π Setting up SSH key..." | |
| SSH_KEY_PATH="$ICLOUD_SECRET/ssh/id_ed25519_$MACHINE_TYPE" | |
| if [ -f "$SSH_KEY_PATH" ]; then | |
| mkdir -p ~/.ssh | |
| chmod 700 ~/.ssh | |
| # Create symlink | |
| ln -sf "$SSH_KEY_PATH" ~/.ssh/id_ed25519 | |
| ln -sf "${SSH_KEY_PATH}.pub" ~/.ssh/id_ed25519.pub | |
| chmod 600 ~/.ssh/id_ed25519 | |
| # Add to ssh-agent | |
| eval "$(ssh-agent -s)" | |
| # Wait for agent to be ready | |
| sleep 1 | |
| if ssh-add ~/.ssh/id_ed25519 2>/dev/null; then | |
| echo "β SSH key added to agent" | |
| else | |
| echo "β οΈ Failed to add SSH key to agent" | |
| echo " You may need to run manually: ssh-add ~/.ssh/id_ed25519" | |
| echo " Continuing anyway..." | |
| fi | |
| echo "β SSH key configured" | |
| else | |
| echo "β SSH key not found at: $SSH_KEY_PATH" | |
| echo " Cannot proceed without SSH key for private repository." | |
| echo "" | |
| echo "π Manual setup required:" | |
| echo " 1. Copy SSH keys to $ICLOUD_SECRET/ssh/" | |
| echo " 2. Re-run this bootstrap script" | |
| exit 1 | |
| fi | |
| # 7. Check network connectivity | |
| echo "π Checking network connectivity..." | |
| if ! ping -c 1 github.com &>/dev/null; then | |
| echo "β Cannot reach github.com - check your network connection" | |
| exit 1 | |
| fi | |
| # 8. Initialize chezmoi repository (using SSH URL for private repo) | |
| echo "π₯ Initializing chezmoi repository..." | |
| chezmoi init [email protected]:private-junseokh/chezmoi-dotfiles.git | |
| # 9. Configure machine type in chezmoi config | |
| echo "βοΈ Configuring chezmoi..." | |
| mkdir -p ~/.config/chezmoi | |
| # Detect GPG key ID | |
| GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG 2>/dev/null | grep sec | awk '{print $2}' | cut -d'/' -f2 | head -n1) | |
| cat > ~/.config/chezmoi/chezmoi.toml <<EOF | |
| encryption = "gpg" | |
| [gpg] | |
| recipient = "$GPG_KEY_ID" | |
| [data] | |
| machine_type = "$MACHINE_TYPE" | |
| # Personal info | |
| name_personal = "Junseok Hyun" | |
| email_personal = "[email protected]" | |
| gpg_key_personal = "CB5A764C7AC650D7" | |
| # Work info | |
| name_work = "Junseok Hyun" | |
| email_work = "[email protected]" | |
| gpg_key_work = "C4F9C757F830678D" | |
| EOF | |
| echo "β Configuration created" | |
| # 10. Apply dotfiles (this will trigger all run_once and run_before scripts) | |
| echo "π Applying dotfiles..." | |
| chezmoi apply --refresh-externals | |
| echo "" | |
| echo "β Bootstrap complete!" | |
| echo "" | |
| echo "π Next steps:" | |
| echo " 1. Restart your terminal to load new shell configuration" | |
| echo " 2. Run 'devcheck' to verify setup" | |
| echo " 3. Install missing Homebrew packages: brew bundle install" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
κ²½μ 쑰건 μμ , λ€νΈμν¬ μ²΄ν¬