diff --git a/INSTALLATION.md b/INSTALLATION.md index d5c5589..2d4afac 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -2,6 +2,29 @@ This guide will help you install everything needed for the Git Workshop on Windows 11. +## Quick Start (Automated Installation) + +**Easiest option:** Run our one-shot installation script that automatically installs all required tools using winget. + +1. Open **PowerShell** or **Windows Terminal** +2. Navigate to the git-workshop directory +3. Run the installation script: + +```powershell +.\install-prerequisites.ps1 +``` + +The script will: +- Check if tools are already installed +- Install PowerShell 7, Git 2.23+, and Visual Studio Code +- Prompt you for optional tools (Python 3.12, Windows Terminal) +- Show clear progress and verify each installation +- Display Git configuration instructions when complete + +**If you prefer manual installation**, continue with the detailed steps below. + +--- + ## Prerequisites You'll need administrator access to install software on your Windows 11 machine. @@ -12,7 +35,7 @@ You'll need administrator access to install software on your Windows 11 machine. 2. **Git** - Version control system (2.23 or later) 3. **Visual Studio Code** - Modern code editor with excellent Git integration -## Installation Steps +## Manual Installation Steps ### 1. Install PowerShell 7 diff --git a/README.md b/README.md index 1732ebf..8c83e6b 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,15 @@ Then run scripts using: ### Installation -**Windows 11 Users:** See [INSTALLATION.md](INSTALLATION.md) for complete step-by-step installation instructions including PowerShell 7, Git, and Visual Studio Code. +**Quick Automated Installation (Windows 11):** + +Run our one-shot installation script to automatically install all required tools: + +```powershell +.\install-prerequisites.ps1 +``` + +**Manual Installation:** See [INSTALLATION.md](INSTALLATION.md) for complete step-by-step installation instructions including PowerShell 7, Git, and Visual Studio Code. **Quick Check:** @@ -340,6 +348,7 @@ You can also use existing cloud Git platforms: git-workshop/ ├── README.md # This file ├── INSTALLATION.md # Windows 11 installation guide (PowerShell 7, Git, VS Code) +├── install-prerequisites.ps1 # Automated installation script (one-shot setup) ├── GIT-CHEATSHEET.md # Quick reference for all Git commands ├── WORKSHOP-AGENDA.md # Facilitator guide for running workshops ├── PRESENTATION-OUTLINE.md # Slide deck outline diff --git a/install-prerequisites.ps1 b/install-prerequisites.ps1 new file mode 100644 index 0000000..5f02dfd --- /dev/null +++ b/install-prerequisites.ps1 @@ -0,0 +1,463 @@ +#!/usr/bin/env pwsh +<# +.SYNOPSIS +Installs all prerequisites for the Git Workshop using winget. + +.DESCRIPTION +This script automates the installation of required tools for the Git Workshop: +- PowerShell 7 (cross-platform PowerShell) +- Git 2.23+ (version control system) +- Visual Studio Code (code editor with Git integration) + +Optional tools (with user prompts): +- Python 3.12 (for Module 08: Multiplayer Git) +- Windows Terminal (modern terminal experience) + +The script checks for existing installations, shows clear progress, and verifies +each installation succeeded. At the end, it displays Git configuration instructions. + +.EXAMPLE +PS> .\install-prerequisites.ps1 +Runs the installation script with interactive prompts. + +.NOTES +Requires Windows 11 with winget (App Installer) available. +Some installations may require administrator privileges. +#> + +[CmdletBinding()] +param() + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Continue' # Continue on errors to show all results + +#region Helper Functions + +function Write-ColorMessage { + param( + [string]$Message, + [string]$Color = 'White' + ) + Write-Host $Message -ForegroundColor $Color +} + +function Write-Step { + param([string]$Message) + Write-ColorMessage "`n=== $Message ===" -Color Cyan +} + +function Write-Success { + param([string]$Message) + Write-ColorMessage " ✓ $Message" -Color Green +} + +function Write-Warning { + param([string]$Message) + Write-ColorMessage " ⚠ $Message" -Color Yellow +} + +function Write-Error { + param([string]$Message) + Write-ColorMessage " ✗ $Message" -Color Red +} + +function Test-CommandExists { + param([string]$Command) + + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'SilentlyContinue' + + try { + if (Get-Command $Command -ErrorAction SilentlyContinue) { + return $true + } + return $false + } + finally { + $ErrorActionPreference = $oldPreference + } +} + +function Get-InstalledVersion { + param( + [string]$Command, + [string]$VersionArg = '--version' + ) + + try { + $output = & $Command $VersionArg 2>&1 | Select-Object -First 1 + return $output.ToString().Trim() + } + catch { + return $null + } +} + +function Test-WingetAvailable { + if (-not (Test-CommandExists 'winget')) { + Write-Error "winget is not available on this system." + Write-Host "`nTo fix this:" -ForegroundColor Yellow + Write-Host " 1. Update Windows 11 to the latest version (Settings → Windows Update)" -ForegroundColor White + Write-Host " 2. Install 'App Installer' from the Microsoft Store" -ForegroundColor White + Write-Host " 3. Restart your computer and run this script again" -ForegroundColor White + return $false + } + return $true +} + +function Install-Package { + param( + [string]$Name, + [string]$WingetId, + [string]$CheckCommand, + [string]$MinVersion = $null, + [string]$AdditionalArgs = '' + ) + + Write-Step "Installing $Name" + + # Check if already installed + if (Test-CommandExists $CheckCommand) { + $version = Get-InstalledVersion $CheckCommand + Write-Success "$Name is already installed: $version" + + if ($MinVersion -and $version) { + # Basic version check (not perfect but good enough for common cases) + if ($version -match '(\d+\.[\d.]+)') { + $installedVersion = $matches[1] + if ([version]$installedVersion -lt [version]$MinVersion) { + Write-Warning "Version $installedVersion is below minimum required version $MinVersion" + Write-Host " Attempting to upgrade..." -ForegroundColor Cyan + } + else { + return $true + } + } + } + else { + return $true + } + } + + # Install using winget + Write-Host " Installing via winget: $WingetId" -ForegroundColor Cyan + + $installCmd = "winget install --id $WingetId --source winget --silent $AdditionalArgs".Trim() + Write-Host " Running: $installCmd" -ForegroundColor Gray + + try { + $result = Invoke-Expression $installCmd 2>&1 + + # Check if installation succeeded + Start-Sleep -Seconds 2 # Give the system time to register the new command + + # Refresh environment variables in current session + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") + + if (Test-CommandExists $CheckCommand) { + $version = Get-InstalledVersion $CheckCommand + Write-Success "$Name installed successfully: $version" + return $true + } + else { + Write-Warning "$Name installation completed, but command '$CheckCommand' not found." + Write-Host " You may need to restart your terminal or computer." -ForegroundColor Yellow + return $false + } + } + catch { + Write-Error "Failed to install $Name`: $_" + return $false + } +} + +function Test-GitVersion { + if (-not (Test-CommandExists 'git')) { + return $false + } + + $version = Get-InstalledVersion 'git' + if ($version -match 'git version (\d+\.\d+)') { + $versionNumber = [decimal]$matches[1] + if ($versionNumber -ge 2.23) { + return $true + } + else { + Write-Warning "Git version $versionNumber is below required version 2.23" + return $false + } + } + + return $false +} + +function Get-UserConfirmation { + param([string]$Prompt) + + while ($true) { + $response = Read-Host "$Prompt (y/n)" + $response = $response.Trim().ToLower() + + if ($response -eq 'y' -or $response -eq 'yes') { + return $true + } + elseif ($response -eq 'n' -or $response -eq 'no') { + return $false + } + else { + Write-Host "Please enter 'y' or 'n'" -ForegroundColor Yellow + } + } +} + +#endregion + +#region Main Script + +Write-Host @" + +╔═══════════════════════════════════════════════════════════╗ +║ ║ +║ Git Workshop - Prerequisites Installation Script ║ +║ ║ +╚═══════════════════════════════════════════════════════════╝ + +"@ -ForegroundColor Cyan + +Write-Host "This script will install the required tools for the Git Workshop:" -ForegroundColor White +Write-Host " • PowerShell 7 (cross-platform PowerShell)" -ForegroundColor White +Write-Host " • Git 2.23+ (version control system)" -ForegroundColor White +Write-Host " • Visual Studio Code (code editor)" -ForegroundColor White +Write-Host "" +Write-Host "You will be prompted for optional tools:" -ForegroundColor White +Write-Host " • Python 3.12 (for Module 08: Multiplayer Git)" -ForegroundColor White +Write-Host " • Windows Terminal (modern terminal experience)" -ForegroundColor White +Write-Host "" + +# Check for winget +Write-Step "Checking Prerequisites" + +if (-not (Test-WingetAvailable)) { + Write-Host "`nInstallation cannot continue without winget." -ForegroundColor Red + exit 1 +} + +Write-Success "winget is available" + +# Track installation results +$results = @{ + PowerShell = $false + Git = $false + VSCode = $false + Python = $null # null = not attempted, true = success, false = failed + WindowsTerminal = $null +} + +Write-Host "`nStarting installation..." -ForegroundColor Cyan +Write-Host "Note: Some installations may take a few minutes." -ForegroundColor Gray +Write-Host "" + +#region Required Installations + +# Install PowerShell 7 +$results.PowerShell = Install-Package ` + -Name "PowerShell 7" ` + -WingetId "Microsoft.PowerShell" ` + -CheckCommand "pwsh" + +# Install Git +$results.Git = Install-Package ` + -Name "Git" ` + -WingetId "Git.Git" ` + -CheckCommand "git" ` + -MinVersion "2.23" ` + -AdditionalArgs "-e" + +# Verify Git version specifically +if ($results.Git) { + if (-not (Test-GitVersion)) { + Write-Warning "Git is installed but version may be below 2.23" + $results.Git = $false + } +} + +# Install Visual Studio Code +$results.VSCode = Install-Package ` + -Name "Visual Studio Code" ` + -WingetId "Microsoft.VisualStudioCode" ` + -CheckCommand "code" + +#endregion + +#region Optional Installations + +# Python 3.12 (optional) +Write-Host "" +if (Get-UserConfirmation "Do you want to install Python 3.12? (Required for Module 08: Multiplayer Git)") { + $results.Python = Install-Package ` + -Name "Python 3.12" ` + -WingetId "Python.Python.3.12" ` + -CheckCommand "python" +} +else { + Write-Host " Skipping Python installation." -ForegroundColor Gray + $results.Python = $null +} + +# Windows Terminal (optional) +Write-Host "" +if (Get-UserConfirmation "Do you want to install Windows Terminal? (Highly recommended for better terminal experience)") { + $results.WindowsTerminal = Install-Package ` + -Name "Windows Terminal" ` + -WingetId "Microsoft.WindowsTerminal" ` + -CheckCommand "wt" +} +else { + Write-Host " Skipping Windows Terminal installation." -ForegroundColor Gray + $results.WindowsTerminal = $null +} + +#endregion + +#region Installation Summary + +Write-Step "Installation Summary" + +$allRequired = $results.PowerShell -and $results.Git -and $results.VSCode + +Write-Host "" +Write-Host "Required Tools:" -ForegroundColor White + +if ($results.PowerShell) { + Write-Success "PowerShell 7" +} +else { + Write-Error "PowerShell 7 - Installation failed or needs restart" +} + +if ($results.Git) { + Write-Success "Git 2.23+" +} +else { + Write-Error "Git 2.23+ - Installation failed or needs restart" +} + +if ($results.VSCode) { + Write-Success "Visual Studio Code" +} +else { + Write-Error "Visual Studio Code - Installation failed or needs restart" +} + +if ($results.Python -ne $null) { + Write-Host "" + Write-Host "Optional Tools:" -ForegroundColor White + + if ($results.Python) { + Write-Success "Python 3.12" + } + else { + Write-Error "Python 3.12 - Installation failed or needs restart" + } +} + +if ($results.WindowsTerminal -ne $null) { + if ($results.Python -eq $null) { + Write-Host "" + Write-Host "Optional Tools:" -ForegroundColor White + } + + if ($results.WindowsTerminal) { + Write-Success "Windows Terminal" + } + else { + Write-Error "Windows Terminal - Installation failed or needs restart" + } +} + +#endregion + +#region Next Steps + +Write-Step "Next Steps" + +if ($allRequired) { + Write-Host "" + Write-Success "All required tools installed successfully!" + Write-Host "" + + Write-Host "IMPORTANT: Configure Git before your first commit:" -ForegroundColor Yellow + Write-Host "" + Write-Host " git config --global user.name `"Your Name`"" -ForegroundColor White + Write-Host " git config --global user.email `"your.email@example.com`"" -ForegroundColor White + Write-Host "" + + Write-Host "Optional: Set VS Code as Git's default editor:" -ForegroundColor Cyan + Write-Host " git config --global core.editor `"code --wait`"" -ForegroundColor White + Write-Host "" + + Write-Host "Verify your installation:" -ForegroundColor Cyan + Write-Host " pwsh --version" -ForegroundColor White + Write-Host " git --version" -ForegroundColor White + Write-Host " code --version" -ForegroundColor White + if ($results.Python) { + Write-Host " python --version" -ForegroundColor White + } + Write-Host "" + + Write-Host "Set PowerShell execution policy (if needed):" -ForegroundColor Cyan + Write-Host " Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" -ForegroundColor White + Write-Host "" + + Write-Host "Recommended VS Code Extensions:" -ForegroundColor Cyan + Write-Host " • GitLens - Supercharge Git capabilities" -ForegroundColor White + Write-Host " • Git Graph - View Git history visually" -ForegroundColor White + Write-Host " • PowerShell - Better PowerShell support (from Microsoft)" -ForegroundColor White + Write-Host "" + Write-Host " Install via: Ctrl+Shift+X in VS Code" -ForegroundColor Gray + Write-Host "" + + Write-Host "You're ready to start the workshop!" -ForegroundColor Green + Write-Host " cd path\to\git-workshop" -ForegroundColor White + Write-Host " cd 01-essentials\01-basics" -ForegroundColor White + Write-Host " .\setup.ps1" -ForegroundColor White + Write-Host "" +} +else { + Write-Host "" + Write-Warning "Some required installations failed or need verification." + Write-Host "" + Write-Host "Troubleshooting steps:" -ForegroundColor Yellow + Write-Host " 1. Close and reopen your terminal (or restart your computer)" -ForegroundColor White + Write-Host " 2. Run this script again: .\install-prerequisites.ps1" -ForegroundColor White + Write-Host " 3. If issues persist, try manual installation:" -ForegroundColor White + Write-Host " See INSTALLATION.md for detailed instructions" -ForegroundColor White + Write-Host "" + + if (-not $results.Git) { + Write-Host "For Git issues:" -ForegroundColor Yellow + Write-Host " • Restart terminal after installation (PATH needs to refresh)" -ForegroundColor White + Write-Host " • Manual download: https://git-scm.com/downloads" -ForegroundColor White + Write-Host "" + } + + if (-not $results.VSCode) { + Write-Host "For VS Code issues:" -ForegroundColor Yellow + Write-Host " • Ensure 'Add to PATH' option is enabled during installation" -ForegroundColor White + Write-Host " • Manual download: https://code.visualstudio.com/" -ForegroundColor White + Write-Host "" + } + + if (-not $results.PowerShell) { + Write-Host "For PowerShell 7 issues:" -ForegroundColor Yellow + Write-Host " • Manual download: https://github.com/PowerShell/PowerShell/releases/latest" -ForegroundColor White + Write-Host " • Download the file ending in '-win-x64.msi'" -ForegroundColor White + Write-Host "" + } + + exit 1 +} + +#endregion + +exit 0