66 lines
2.8 KiB
PowerShell
66 lines
2.8 KiB
PowerShell
param(
|
|
[string]$Prefix = (Join-Path $env:LOCALAPPDATA "bjd-cms")
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ScriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$ReleaseRoot = Split-Path -Parent $ScriptDirectory
|
|
|
|
if (-not [System.IO.Path]::IsPathRooted($Prefix)) {
|
|
throw "Installation prefix must be absolute."
|
|
}
|
|
$Prefix = [System.IO.Path]::GetFullPath($Prefix)
|
|
$Root = [System.IO.Path]::GetPathRoot($Prefix)
|
|
if ($Prefix.TrimEnd('\') -eq $Root.TrimEnd('\')) {
|
|
throw "Refusing a broad filesystem-root installation prefix."
|
|
}
|
|
|
|
$Version = (Get-Content -LiteralPath (Join-Path $ReleaseRoot "VERSION") -Raw).Trim()
|
|
if ($Version -notmatch '^[0-9A-Za-z.+-]+$') {
|
|
throw "Release VERSION is invalid."
|
|
}
|
|
|
|
$PluginSource = Join-Path $ReleaseRoot "plugin\bjd-cms-content"
|
|
$SkillSource = Join-Path $ReleaseRoot "skill\bjd-cms-content"
|
|
if (-not (Test-Path -LiteralPath (Join-Path $PluginSource "scripts\server.py") -PathType Leaf)) {
|
|
throw "Release plugin is incomplete."
|
|
}
|
|
if (-not (Test-Path -LiteralPath (Join-Path $SkillSource "SKILL.md") -PathType Leaf)) {
|
|
throw "Release skill is incomplete."
|
|
}
|
|
|
|
$Versions = Join-Path $Prefix "versions"
|
|
$Destination = Join-Path $Versions $Version
|
|
$Staging = Join-Path $Versions (".install-{0}-{1}" -f $Version, [System.Diagnostics.Process]::GetCurrentProcess().Id)
|
|
New-Item -ItemType Directory -Path $Versions -Force | Out-Null
|
|
if (Test-Path -LiteralPath $Destination) {
|
|
throw "Version $Version is already installed at $Destination"
|
|
}
|
|
if (Test-Path -LiteralPath $Staging) {
|
|
throw "Private staging path already exists."
|
|
}
|
|
|
|
try {
|
|
New-Item -ItemType Directory -Path $Staging | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $ReleaseRoot "plugin") -Destination (Join-Path $Staging "plugin") -Recurse
|
|
Copy-Item -LiteralPath (Join-Path $ReleaseRoot "skill") -Destination (Join-Path $Staging "skill") -Recurse
|
|
Copy-Item -LiteralPath (Join-Path $ReleaseRoot "install") -Destination (Join-Path $Staging "install") -Recurse
|
|
Copy-Item -LiteralPath (Join-Path $ReleaseRoot "VERSION") -Destination $Staging
|
|
Copy-Item -LiteralPath (Join-Path $ReleaseRoot "RELEASE.json") -Destination $Staging
|
|
Move-Item -LiteralPath $Staging -Destination $Destination
|
|
|
|
$CurrentNext = Join-Path $Prefix (".current-{0}.txt" -f [System.Diagnostics.Process]::GetCurrentProcess().Id)
|
|
[System.IO.File]::WriteAllText($CurrentNext, $Destination + [Environment]::NewLine)
|
|
Move-Item -LiteralPath $CurrentNext -Destination (Join-Path $Prefix "current.txt") -Force
|
|
} catch {
|
|
if (Test-Path -LiteralPath $Staging) {
|
|
Remove-Item -LiteralPath $Staging -Recurse -Force
|
|
}
|
|
throw
|
|
}
|
|
|
|
Write-Output "Installed BJD CMS Content $Version"
|
|
Write-Output "Plugin: $Destination\plugin\bjd-cms-content"
|
|
Write-Output "Skill: $Destination\skill\bjd-cms-content"
|
|
Write-Output "Next: read $Destination\install\generic-mcp.md"
|