Last active
March 16, 2026 14:25
-
-
Save dfaivre/c5777bced1b07f01f76c2cb6c1d927c4 to your computer and use it in GitHub Desktop.
Dev machine bootstrap scripts (Windows + Ubuntu/WSL2)
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
| # bootstrap.ps1 - Public gist for zero-dependency machine setup | |
| # Usage: iex (irm 'https://gist.githubusercontent.com/dfaivre/GIST_ID/raw/bootstrap.ps1') | |
| # | |
| # This script bootstraps a fresh Windows machine by: | |
| # 1. Installing Git (required for chezmoi to clone private repos) | |
| # 2. Installing Chezmoi (dotfiles manager) | |
| # 3. Running chezmoi init --apply to clone and apply dotfiles | |
| # | |
| # The dotfiles repo contains run_once_* scripts that will automatically | |
| # run to complete the full machine setup. | |
| Write-Host "=== Dev Machine Bootstrap ===" -ForegroundColor Cyan | |
| Write-Host "" | |
| # Check if running as admin (recommended but not required) | |
| $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
| if (-not $isAdmin) { | |
| Write-Host "[NOTE] Running as non-admin. Some setup steps may require elevation later." -ForegroundColor Yellow | |
| Write-Host "" | |
| } | |
| # Install Git (needed for chezmoi to clone private repos) | |
| Write-Host "[1/3] Installing Git..." -ForegroundColor Yellow | |
| winget install --id Git.Git -e --accept-source-agreements --accept-package-agreements | |
| if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne -1978335189) { | |
| Write-Host " Warning: Git installation returned code $LASTEXITCODE" -ForegroundColor Yellow | |
| } | |
| # Refresh PATH to pick up git | |
| $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") | |
| # Verify git is available | |
| $gitPath = Get-Command git -ErrorAction SilentlyContinue | |
| if ($gitPath) { | |
| Write-Host " Git installed: $($gitPath.Source)" -ForegroundColor Green | |
| } else { | |
| Write-Host " Warning: Git not found in PATH. You may need to restart your terminal." -ForegroundColor Yellow | |
| } | |
| # Install Chezmoi | |
| Write-Host "[2/3] Installing Chezmoi..." -ForegroundColor Yellow | |
| winget install --id twpayne.chezmoi -e --accept-source-agreements --accept-package-agreements | |
| if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne -1978335189) { | |
| Write-Host " Warning: Chezmoi installation returned code $LASTEXITCODE" -ForegroundColor Yellow | |
| } | |
| # Refresh PATH again | |
| $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") | |
| # Verify chezmoi is available | |
| $chezmoiPath = Get-Command chezmoi -ErrorAction SilentlyContinue | |
| if ($chezmoiPath) { | |
| Write-Host " Chezmoi installed: $($chezmoiPath.Source)" -ForegroundColor Green | |
| } else { | |
| Write-Host "[ERROR] Chezmoi not found in PATH. Please restart your terminal and run:" -ForegroundColor Red | |
| Write-Host " chezmoi init --apply https://github.com/dfaivre/dotfiles.git" -ForegroundColor Cyan | |
| exit 1 | |
| } | |
| # Initialize and apply dotfiles (will prompt for GitHub auth via Git Credential Manager) | |
| Write-Host "[3/3] Initializing dotfiles..." -ForegroundColor Yellow | |
| Write-Host " You will be prompted to authenticate with GitHub." -ForegroundColor Cyan | |
| Write-Host "" | |
| chezmoi init --apply https://github.com/dfaivre/dotfiles.git | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Host "" | |
| Write-Host "========================================" -ForegroundColor Green | |
| Write-Host " BOOTSTRAP COMPLETE " -ForegroundColor Green | |
| Write-Host "========================================" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Host "Chezmoi has applied your dotfiles and run setup scripts." -ForegroundColor Cyan | |
| Write-Host "" | |
| Write-Host "If WSL installation triggered a reboot prompt, restart and" -ForegroundColor Yellow | |
| Write-Host "the setup will resume automatically." -ForegroundColor Yellow | |
| } else { | |
| Write-Host "" | |
| Write-Host "[ERROR] Chezmoi init failed with code $LASTEXITCODE" -ForegroundColor Red | |
| Write-Host " Check the output above for details." -ForegroundColor Yellow | |
| } |
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.sh - Public gist for zero-dependency WSL2/Ubuntu setup | |
| # Usage: curl -fsSL 'https://gist.githubusercontent.com/dfaivre/c5777bced1b07f01f76c2cb6c1d927c4/raw/bootstrap.sh' | bash | |
| # | |
| # This script bootstraps a fresh Ubuntu 24.04 (WSL2) instance by: | |
| # 1. Installing Git (required for chezmoi to clone private repos) | |
| # 2. Installing Chezmoi (dotfiles manager) to ~/.local/bin | |
| # 3. Running chezmoi init --apply to clone and apply dotfiles | |
| # | |
| # The dotfiles repo contains run_once_* scripts that will automatically | |
| # run to complete the full machine setup. | |
| set -euo pipefail | |
| echo "=== Dev Machine Bootstrap (Ubuntu/WSL2) ===" | |
| echo "" | |
| # Check if running as root (not recommended -- chezmoi should run as the user) | |
| if [ "$(id -u)" -eq 0 ]; then | |
| echo "[WARN] Running as root. Consider running as a normal user instead." | |
| echo "" | |
| fi | |
| # Install Git | |
| echo "[1/3] Installing Git..." | |
| sudo apt-get update -qq | |
| sudo apt-get install -y -qq git | |
| if command -v git &>/dev/null; then | |
| echo " Git installed: $(command -v git)" | |
| else | |
| echo "[ERROR] Git installation failed." | |
| exit 1 | |
| fi | |
| # Install Chezmoi to ~/.local/bin via get.chezmoi.io | |
| echo "[2/3] Installing Chezmoi..." | |
| BINDIR="$HOME/.local/bin" | |
| mkdir -p "$BINDIR" | |
| sh -c "$(curl -fsSL https://get.chezmoi.io)" -- -b "$BINDIR" | |
| if [ -x "$BINDIR/chezmoi" ]; then | |
| echo " Chezmoi installed: $BINDIR/chezmoi" | |
| else | |
| echo "[ERROR] Chezmoi installation failed." | |
| exit 1 | |
| fi | |
| # Ensure ~/.local/bin is on PATH for this session | |
| export PATH="$BINDIR:$PATH" | |
| # Initialize and apply dotfiles | |
| echo "[3/3] Initializing dotfiles..." | |
| echo " You will be prompted to authenticate with GitHub." | |
| echo "" | |
| "$BINDIR/chezmoi" init --apply https://github.com/dfaivre/dotfiles.git | |
| echo "" | |
| echo "========================================" | |
| echo " BOOTSTRAP COMPLETE " | |
| echo "========================================" | |
| echo "" | |
| echo "Chezmoi has applied your dotfiles and run setup scripts." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment