Skip to content

Instantly share code, notes, and snippets.

@JunseokH
Last active January 4, 2026 04:44
Show Gist options
  • Select an option

  • Save JunseokH/26cde6533f4e6b384b8d3695109fbf68 to your computer and use it in GitHub Desktop.

Select an option

Save JunseokH/26cde6533f4e6b384b8d3695109fbf68 to your computer and use it in GitHub Desktop.
#!/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"
@JunseokH
Copy link
Author

JunseokH commented Jan 3, 2026

경쟁 쑰건 μˆ˜μ •, λ„€νŠΈμ›Œν¬ 체크

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment