forked from cflmy/deepseek-harness
- add scripts/package-windows.ps1, scripts/install.ps1 and scripts/mqdh.cmd for a portable Windows tree with a user-level install, version pointer and launcher; - teach the release manifest script the Windows target/platform fields and publish the Windows target in the platform table; - cover the Windows target in platform/manifest tests and document the experimental Windows scope (unsigned, manual updates, no native CI lane).
155 lines
6.2 KiB
PowerShell
155 lines
6.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
User-level installer for a packaged Marqdo Harness (MQDH) tree on Windows.
|
|
|
|
.DESCRIPTION
|
|
Installs one extracted release tree into a per-user prefix, writes the
|
|
`current.json` version pointer and a launcher that always runs the active
|
|
version. The application install tree is separate from MQDH_HOME (sessions,
|
|
private knowledge, diagnostics and the Marqdo runtime); uninstall preserves
|
|
MQDH_HOME unless the user removes it explicitly.
|
|
|
|
This is an experimental Windows distribution path: the archive is unsigned
|
|
and the application's in-app updater only supports the Linux archive. Updates
|
|
on Windows are manual (download and run the new installer).
|
|
|
|
.PARAMETER Prefix
|
|
Install prefix. Defaults to `$env:LOCALAPPDATA\MQDH`.
|
|
|
|
.PARAMETER NoPath
|
|
Do not add `<prefix>\bin` to the user PATH.
|
|
|
|
.PARAMETER NoShortcut
|
|
Do not create a Start Menu shortcut.
|
|
|
|
.PARAMETER Uninstall
|
|
Remove the install tree and launcher; user data under MQDH_HOME is preserved.
|
|
|
|
.EXAMPLE
|
|
powershell -ExecutionPolicy Bypass -File .\install.ps1
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Prefix = (Join-Path $env:LOCALAPPDATA 'MQDH'),
|
|
[switch]$NoPath,
|
|
[switch]$NoShortcut,
|
|
[switch]$Uninstall
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$source = $PSScriptRoot
|
|
$prefixFull = [System.IO.Path]::GetFullPath($Prefix)
|
|
$launcher = Join-Path $prefixFull 'bin\mqdh.cmd'
|
|
$shortcut = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\MQDH.lnk'
|
|
$homeHint = if ($env:MQDH_HOME) { $env:MQDH_HOME } else { Join-Path $env:USERPROFILE '.local\share\marqdo-harness' }
|
|
|
|
function Remove-UserPathEntry([string]$entry) {
|
|
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
if ([string]::IsNullOrWhiteSpace($current)) { return }
|
|
$parts = $current -split ';' | Where-Object { $_ -ne '' -and $_ -ne $entry }
|
|
[Environment]::SetEnvironmentVariable('Path', ($parts -join ';'), 'User')
|
|
}
|
|
|
|
if ($Uninstall) {
|
|
Remove-Item -LiteralPath $launcher -Force -ErrorAction SilentlyContinue
|
|
Remove-Item -LiteralPath $shortcut -Force -ErrorAction SilentlyContinue
|
|
if (Test-Path -LiteralPath $prefixFull) {
|
|
Remove-Item -LiteralPath $prefixFull -Recurse -Force
|
|
}
|
|
if (-not $NoPath) { Remove-UserPathEntry (Join-Path $prefixFull 'bin') }
|
|
Write-Host "removed $prefixFull; user data under $homeHint is preserved"
|
|
exit 0
|
|
}
|
|
|
|
foreach ($required in @('scripts\mqdh.mjs', 'SOURCE_SHA', 'packages\marqdo\harness\package.json', 'runtime\node.exe')) {
|
|
if (-not (Test-Path -LiteralPath (Join-Path $source $required))) {
|
|
throw "install.ps1: not a Marqdo Harness Windows tree (missing $required): $source"
|
|
}
|
|
}
|
|
$version = (Get-Content -LiteralPath (Join-Path $source 'packages\marqdo\harness\package.json') -Raw | ConvertFrom-Json).version
|
|
if ([string]::IsNullOrWhiteSpace($version)) { throw 'install.ps1: cannot read the product version' }
|
|
$sha = (Get-Content -LiteralPath (Join-Path $source 'SOURCE_SHA') -Raw).Trim()
|
|
if ($sha -notmatch '^[0-9a-f]{12,40}$') { throw 'install.ps1: invalid SOURCE_SHA' }
|
|
$installId = "$version-$($sha.Substring(0,12))"
|
|
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $prefixFull 'versions') | Out-Null
|
|
$target = Join-Path $prefixFull "versions\$installId"
|
|
if (-not (Test-Path -LiteralPath $target)) {
|
|
# Move preserves the staged tree's file identities and avoids re-copying the
|
|
# multi-gigabyte production dependency tree; fall back to a copy across volumes.
|
|
try {
|
|
Move-Item -LiteralPath $source -Destination $target
|
|
} catch {
|
|
New-Item -ItemType Directory -Force -Path $target | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $source '*') -Destination $target -Recurse -Force
|
|
}
|
|
} elseif ((Get-Item -LiteralPath $target).FullName -ne (Get-Item -LiteralPath $source).FullName) {
|
|
Write-Host "install.ps1: version tree already installed: $target"
|
|
}
|
|
|
|
$previous = $null
|
|
$previousVersion = $null
|
|
$currentPath = Join-Path $prefixFull 'current.json'
|
|
if (Test-Path -LiteralPath $currentPath) {
|
|
$current = Get-Content -LiteralPath $currentPath -Raw | ConvertFrom-Json
|
|
$previous = $current.install_id
|
|
$previousVersion = $current.version
|
|
}
|
|
$pointer = [ordered]@{
|
|
schema = 'marqdo.mqdh.app-current'
|
|
schema_version = 1
|
|
version = $version
|
|
install_id = $installId
|
|
source_sha = $sha
|
|
previous = $previous
|
|
previous_version = $previousVersion
|
|
updated_at = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
|
|
}
|
|
$pointer | ConvertTo-Json | Set-Content -LiteralPath $currentPath -Encoding UTF8
|
|
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $prefixFull 'bin') | Out-Null
|
|
# The launcher resolves the active version from current.json at every start, so
|
|
# a newer install switches atomically and a failed one leaves the old pointer.
|
|
$launcherBody = @'
|
|
@echo off
|
|
setlocal
|
|
set "ROOT=%~dp0.."
|
|
if defined MQDH_INSTALL_ROOT set "ROOT=%MQDH_INSTALL_ROOT%"
|
|
set "ID="
|
|
for /f "tokens=2 delims=:" %%A in ('findstr /c:"\"install_id\"" "%ROOT%\current.json"') do set "ID=%%A"
|
|
set "ID=%ID: =%"
|
|
set "ID=%ID:"=%"
|
|
set "ID=%ID:,=%"
|
|
if "%ID%"=="" echo mqdh: invalid or missing install pointer: %ROOT%\current.json 1>&2 & exit /b 1
|
|
set "TREE=%ROOT%\versions\%ID%"
|
|
if not exist "%TREE%\runtime\node.exe" echo mqdh: installed version tree is missing: %TREE% 1>&2 & exit /b 1
|
|
"%TREE%\runtime\node.exe" "%TREE%\scripts\mqdh.mjs" %*
|
|
'@
|
|
Set-Content -LiteralPath $launcher -Value $launcherBody -Encoding ASCII
|
|
|
|
if (-not $NoShortcut) {
|
|
try {
|
|
$shell = New-Object -ComObject WScript.Shell
|
|
$link = $shell.CreateShortcut($shortcut)
|
|
$link.TargetPath = $launcher
|
|
$link.WorkingDirectory = $prefixFull
|
|
$link.Description = 'Marqdo Harness (MQDH) workbench'
|
|
$link.Save()
|
|
} catch {
|
|
Write-Warning "install.ps1: could not create the Start Menu shortcut: $($_.Exception.Message)"
|
|
}
|
|
}
|
|
|
|
if (-not $NoPath) {
|
|
$bin = Join-Path $prefixFull 'bin'
|
|
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
if (($current -split ';') -notcontains $bin) {
|
|
[Environment]::SetEnvironmentVariable('Path', (($current, $bin) -join ';').Trim(';'), 'User')
|
|
Write-Host "added $bin to the user PATH (open a new shell to use it)"
|
|
}
|
|
}
|
|
|
|
Write-Host "installed Marqdo Harness $version ($installId) at $prefixFull"
|
|
Write-Host "run: $launcher --version"
|
|
Write-Host "user data: $homeHint"
|