Files
git-workshop/install.ps1
Bjarke Sporring e7ce41cbbc Update oneshot installation to clone repository locally
- Modified install.ps1 to clone git-workshop repository to ~/git-workshop
- Added option to remove existing directory before cloning
- Updated documentation to reflect the new behavior
- Now provides complete setup: install tools + clone repo in one command
- Similar to Scoop's get.scoop.sh installation pattern
2026-01-14 16:29:09 +01:00

265 lines
8.4 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Oneshot Git Workshop installer - Downloads and runs the prerequisites installation.
.DESCRIPTION
This script downloads the Git Workshop repository and runs the prerequisites
installation script. It's designed to be run directly from the web:
irm https://git.frod.dk/floppydiscen/git-workshop/raw/branch/main/install.ps1 | iex
The script will:
1. Create a temporary working directory
2. Download the Git Workshop repository
3. Run the install-prerequisites.ps1 script
4. Clean up temporary files
.EXAMPLE
PS> irm https://git.frod.dk/floppydiscen/git-workshop/raw/branch/main/install.ps1 | iex
Downloads and runs the Git Workshop installer.
.NOTES
Requires Windows 11 with PowerShell and internet access.
#>
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
#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
}
#endregion
#region Main Script
Write-Host @"
Git Workshop - Oneshot Installation Script
"@ -ForegroundColor Cyan
Write-Host "This script will download and install all prerequisites for the Git Workshop." -ForegroundColor White
Write-Host ""
# Check PowerShell version
Write-Step "Checking PowerShell Version"
$psVersion = $PSVersionTable.PSVersion
Write-Success "PowerShell $psVersion"
if ($psVersion.Major -lt 7) {
Write-Warning "PowerShell 7+ is recommended for best compatibility"
Write-Host " Continuing with PowerShell $($psVersion.Major)..." -ForegroundColor Gray
}
# Create temporary working directory
Write-Step "Creating Working Directory"
$tempDir = Join-Path $env:TEMP "git-workshop-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
try {
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
Write-Success "Created temporary directory: $tempDir"
}
catch {
Write-Error "Failed to create temporary directory: $_"
exit 1
}
# Download the repository
Write-Step "Downloading Git Workshop Repository"
$repoUrl = "https://git.frod.dk/floppydiscen/git-workshop/archive/main.zip"
$zipPath = Join-Path $tempDir "git-workshop.zip"
try {
Write-Host " Downloading from: $repoUrl" -ForegroundColor Gray
Invoke-WebRequest -Uri $repoUrl -OutFile $zipPath -UseBasicParsing
Write-Success "Repository downloaded successfully"
}
catch {
Write-Error "Failed to download repository: $_"
Write-Host ""
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host " • Check your internet connection" -ForegroundColor White
Write-Host " • Verify the repository URL is correct" -ForegroundColor White
Write-Host " • Try running the script again" -ForegroundColor White
exit 1
}
# Extract the repository
Write-Step "Extracting Repository"
try {
Write-Host " Extracting to: $tempDir" -ForegroundColor Gray
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
# Find the extracted directory (should be git-workshop-main)
$extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -like "git-workshop-*" } | Select-Object -First 1
if (-not $extractedDir) {
throw "Could not find extracted repository directory"
}
Write-Success "Repository extracted to: $($extractedDir.FullName)"
}
catch {
Write-Error "Failed to extract repository: $_"
exit 1
}
# Run the prerequisites installer
Write-Step "Running Prerequisites Installation"
$installerScript = Join-Path $extractedDir.FullName "install-prerequisites.ps1"
if (-not (Test-Path $installerScript)) {
Write-Error "Installation script not found: $installerScript"
Write-Host ""
Write-Host "Expected file structure:" -ForegroundColor Yellow
Write-Host " git-workshop-main/" -ForegroundColor White
Write-Host " ├── install-prerequisites.ps1" -ForegroundColor White
Write-Host " ├── README.md" -ForegroundColor White
Write-Host " └── ..." -ForegroundColor White
exit 1
}
try {
Write-Host " Running: $installerScript" -ForegroundColor Gray
Write-Host ""
# Change to the extracted directory and run the installer
Push-Location $extractedDir.FullName
& $installerScript
$installerExitCode = $LASTEXITCODE
Pop-Location
if ($installerExitCode -eq 0) {
Write-Success "Prerequisites installation completed successfully!"
}
else {
Write-Warning "Prerequisites installation completed with warnings (exit code: $installerExitCode)"
}
}
catch {
Write-Error "Failed to run prerequisites installer: $_"
exit 1
}
finally {
if (Get-Location -ErrorAction SilentlyContinue) {
Pop-Location -ErrorAction SilentlyContinue
}
}
# Clean up
Write-Step "Cleaning Up"
try {
Write-Host " Removing temporary directory: $tempDir" -ForegroundColor Gray
Remove-Item -Path $tempDir -Recurse -Force
Write-Success "Temporary files cleaned up"
}
catch {
Write-Warning "Failed to clean up temporary files: $_"
Write-Host " You can manually delete: $tempDir" -ForegroundColor Yellow
}
# Clone the repository locally
Write-Step "Cloning Git Workshop Repository"
$cloneDir = Join-Path $HOME "git-workshop"
try {
if (Test-Path $cloneDir) {
Write-Warning "Directory already exists: $cloneDir"
$response = Read-Host " Do you want to remove it and clone fresh? (y/n)"
if ($response.Trim().ToLower() -eq 'y' -or $response.Trim().ToLower() -eq 'yes') {
Remove-Item -Path $cloneDir -Recurse -Force
Write-Host " Removed existing directory" -ForegroundColor Gray
}
else {
Write-Host " Skipping clone - using existing directory" -ForegroundColor Gray
}
}
if (-not (Test-Path $cloneDir)) {
Write-Host " Cloning to: $cloneDir" -ForegroundColor Gray
git clone "https://git.frod.dk/floppydiscen/git-workshop.git" $cloneDir
Write-Success "Repository cloned successfully!"
}
}
catch {
Write-Error "Failed to clone repository: $_"
Write-Host ""
Write-Host "You can clone manually:" -ForegroundColor Yellow
Write-Host " git clone https://git.frod.dk/floppydiscen/git-workshop.git ~/git-workshop" -ForegroundColor White
exit 1
}
# Final instructions
Write-Step "Installation Complete"
Write-Host ""
Write-Success "Git Workshop installation is complete!"
Write-Host ""
Write-Host "Repository cloned to: $cloneDir" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host " 1. Configure Git if you haven't already:" -ForegroundColor White
Write-Host " git config --global user.name `"Your Name`"" -ForegroundColor Gray
Write-Host " git config --global user.email `"your.email@example.com`"" -ForegroundColor Gray
Write-Host ""
Write-Host " 2. Navigate to the workshop:" -ForegroundColor White
Write-Host " cd $cloneDir" -ForegroundColor Gray
Write-Host ""
Write-Host " 3. Start with the first module:" -ForegroundColor White
Write-Host " cd 01-essentials\01-basics" -ForegroundColor Gray
Write-Host " .\setup.ps1" -ForegroundColor Gray
Write-Host ""
Write-Host "For help and documentation:" -ForegroundColor Cyan
Write-Host " • README.md - Workshop overview" -ForegroundColor White
Write-Host " • GIT-CHEATSHEET.md - Git command reference" -ForegroundColor White
Write-Host " • AGENDA.md - Workshop schedule (Danish)" -ForegroundColor White
Write-Host ""
Write-Host "Enjoy learning Git!" -ForegroundColor Green
#endregion
exit 0