-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
109 lines (100 loc) · 3.92 KB
/
bootstrap.ps1
File metadata and controls
109 lines (100 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Bootstrap Perch on a fresh Windows machine.
.DESCRIPTION
Installs .NET 10 SDK if missing, clones Perch and your config repo,
builds, and runs the first deploy. Idempotent — safe to re-run.
.PARAMETER ConfigRepo
GitHub slug for your config repo (default: Laoujin/perch-config).
.PARAMETER PerchDir
Where to clone Perch (default: ~/Perch).
.PARAMETER ConfigDir
Where to clone your config repo (default: ~/perch-config).
.PARAMETER SkipDeploy
Clone and build only, don't run deploy.
.EXAMPLE
# One-liner from a fresh machine:
irm https://raw.githubusercontent.com/Laoujin/perch/master/bootstrap.ps1 | iex
#>
param(
[string]$ConfigRepo = 'Laoujin/perch-config',
[string]$PerchDir = (Join-Path $HOME 'Perch'),
[string]$ConfigDir = (Join-Path $HOME 'perch-config'),
[switch]$SkipDeploy
)
$ErrorActionPreference = 'Stop'
function Write-Step($msg) { Write-Host "`n>> $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host " $msg" -ForegroundColor Green }
function Write-Skip($msg) { Write-Host " $msg (skipped)" -ForegroundColor DarkGray }
# --- .NET 10 SDK ---
Write-Step 'Checking .NET 10 SDK'
$sdk = dotnet --list-sdks 2>$null | Where-Object { $_ -match '^10\.' }
if ($sdk) {
Write-Ok "Found: $($sdk[0])"
} else {
Write-Step 'Installing .NET 10 SDK via winget'
winget install Microsoft.DotNet.SDK.10 --accept-source-agreements --accept-package-agreements
if ($LASTEXITCODE -ne 0) {
Write-Host ' winget failed — falling back to dotnet-install script' -ForegroundColor Yellow
$installer = Join-Path $env:TEMP 'dotnet-install.ps1'
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile $installer
& $installer -Channel 10.0
}
# Refresh PATH for this session
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' +
[Environment]::GetEnvironmentVariable('PATH', 'User')
$sdk = dotnet --list-sdks 2>$null | Where-Object { $_ -match '^10\.' }
if (-not $sdk) { throw '.NET 10 SDK installation failed' }
Write-Ok "Installed: $($sdk[0])"
}
# --- Git ---
Write-Step 'Checking git'
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Ok "Found: $(git --version)"
} else {
Write-Step 'Installing git via winget'
winget install Git.Git --accept-source-agreements --accept-package-agreements
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' +
[Environment]::GetEnvironmentVariable('PATH', 'User')
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
throw 'Git installation failed — install manually and re-run'
}
Write-Ok "Installed: $(git --version)"
}
# --- Clone Perch ---
Write-Step "Cloning Perch to $PerchDir"
if (Test-Path (Join-Path $PerchDir '.git')) {
Write-Skip 'Already cloned'
git -C $PerchDir pull --ff-only
} else {
git clone "https://github.com/Laoujin/perch.git" $PerchDir
Write-Ok 'Cloned'
}
# --- Clone config repo ---
Write-Step "Cloning config repo to $ConfigDir"
if (Test-Path (Join-Path $ConfigDir '.git')) {
Write-Skip 'Already cloned'
git -C $ConfigDir pull --ff-only
} else {
git clone "https://github.com/$ConfigRepo.git" $ConfigDir
Write-Ok 'Cloned'
}
# --- Build ---
Write-Step 'Building Perch'
dotnet build $PerchDir --nologo -v quiet
if ($LASTEXITCODE -ne 0) { throw 'Build failed' }
Write-Ok 'Build succeeded'
# --- Deploy ---
if ($SkipDeploy) {
Write-Skip 'Deploy (--SkipDeploy)'
} else {
Write-Step 'Running first deploy'
dotnet run --project (Join-Path $PerchDir 'src/Perch.Cli') -- deploy --config-path $ConfigDir
if ($LASTEXITCODE -ne 0) { throw 'Deploy failed' }
Write-Ok 'Deploy complete'
}
Write-Host "`n=== Perch is ready ===" -ForegroundColor Green
Write-Host " Perch: $PerchDir"
Write-Host " Config: $ConfigDir"
Write-Host " Run again: dotnet run --project '$PerchDir/src/Perch.Cli' -- deploy"