Files
herdrMario/scripts/install.ps1
T
2026-11-19 11:06:12 +01:00

98 lines
3.7 KiB
PowerShell

# install.ps1 - link the repo's ovis-composer mod into the Herdr config.
#
# .\scripts\install.ps1 install (idempotent)
# .\scripts\install.ps1 -Uninstall remove the junction, restore backups
#
# Works on Windows PowerShell 5.
[CmdletBinding()]
param([switch]$Uninstall)
$ErrorActionPreference = 'Stop'
$Stamp = '20261119'
$Repo = Split-Path -Parent $PSScriptRoot
$HerdrDir = Join-Path $env:USERPROFILE '.config\herdr-app'
$ModsDir = Join-Path $HerdrDir 'mods'
$Junction = Join-Path $ModsDir 'ovis-composer'
$ModBackup = "$Junction.bak-$Stamp"
$ModSource = Join-Path $Repo 'mod\ovis-composer'
$LayoutSrc = Join-Path $Repo 'layouts\ovis-composer.json'
$LayoutDst = Join-Path $HerdrDir 'layouts\ovis-composer.json'
$LayoutBak = "$LayoutDst.bak-$Stamp"
$KeysFile = Join-Path $HerdrDir 'keys.json'
$KeysBak = "$KeysFile.bak-$Stamp"
function Test-Junction([string]$Path) {
if (-not (Test-Path -LiteralPath $Path)) { return $false }
$item = Get-Item -LiteralPath $Path -Force
return [bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint)
}
function Remove-Junction([string]$Path) {
# rmdir on a junction removes only the link, never the target's contents.
cmd /c rmdir "`"$Path`"" | Out-Null
if ($LASTEXITCODE -ne 0) { throw "rmdir failed for $Path" }
}
# Task 2 adds the key binding here (keys.json.bak-$Stamp is taken first).
function Install-KeyEntry {
# TODO(Task 2): back up keys.json once as $KeysBak, then add the entry.
}
if ($Uninstall) {
if (Test-Junction $Junction) {
Remove-Junction $Junction
if (-not (Test-Path -LiteralPath (Join-Path $ModSource 'main.js'))) {
throw 'Repo files vanished after removing the junction - aborting.'
}
Write-Host "Removed junction $Junction"
}
if ((Test-Path -LiteralPath $ModBackup) -and -not (Test-Path -LiteralPath $Junction)) {
Move-Item -LiteralPath $ModBackup -Destination $Junction
Write-Host "Restored $Junction"
}
if (Test-Path -LiteralPath $LayoutBak) {
Copy-Item -LiteralPath $LayoutBak -Destination $LayoutDst -Force
Write-Host "Restored layout"
}
if (Test-Path -LiteralPath $KeysBak) {
Copy-Item -LiteralPath $KeysBak -Destination $KeysFile -Force
Write-Host "Restored keys.json"
}
herdr-app do layout.switch '{"name":"main"}'
exit 0
}
# 1. Mod directory -> junction to the repo.
if (Test-Junction $Junction) {
Write-Host "Junction already in place: $Junction"
} else {
if (Test-Path -LiteralPath $Junction) {
if (Test-Path -LiteralPath $ModBackup) { throw "$ModBackup already exists - resolve by hand." }
Move-Item -LiteralPath $Junction -Destination $ModBackup
Write-Host "Backed up to $ModBackup"
}
cmd /c mklink /J "`"$Junction`"" "`"$ModSource`"" | Out-Null
if ($LASTEXITCODE -ne 0) { throw 'mklink /J failed' }
Write-Host "Junction: $Junction -> $ModSource"
}
# gpui-kit.d.ts is git-ignored; keep a copy next to the sources for the editor.
$kitDst = Join-Path $ModSource 'gpui-kit.d.ts'
$kitSrc = if (Test-Path -LiteralPath (Join-Path $ModBackup 'gpui-kit.d.ts')) { Join-Path $ModBackup 'gpui-kit.d.ts' } else { Join-Path $HerdrDir 'gpui-kit.d.ts' }
if (-not (Test-Path -LiteralPath $kitDst) -and (Test-Path -LiteralPath $kitSrc)) {
Copy-Item -LiteralPath $kitSrc -Destination $kitDst
}
# 2. Layout (back up the existing file once).
if ((Test-Path -LiteralPath $LayoutDst) -and -not (Test-Path -LiteralPath $LayoutBak)) {
Copy-Item -LiteralPath $LayoutDst -Destination $LayoutBak
Write-Host "Backed up layout to $LayoutBak"
}
Copy-Item -LiteralPath $LayoutSrc -Destination $LayoutDst -Force
Write-Host "Layout copied"
# 3. Key binding (Task 2).
Install-KeyEntry