Repository navigation
Expand file tree
/
Copy pathdeploy-full.ps1
More file actions
73 lines (64 loc) · 3.8 KB
/
Copy pathdeploy-full.ps1
File metadata and controls
73 lines (64 loc) · 3.8 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
# Despliega bin\Debug al directorio del servicio instalado: exe/dll + Sunshine, FreeRDP, wwwroot y runtimes.
# NO toca datos: sessions\, sessions.json, service.config.json ni logs.
# Se auto-eleva (UAC) si no se ejecuta como administrador.
param([switch]$NoBuild)
$principal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$argList = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', "`"$PSCommandPath`"")
if ($NoBuild) { $argList += '-NoBuild' }
Start-Process powershell.exe -Verb RunAs -ArgumentList $argList
exit
}
$ErrorActionPreference = 'Stop'
$root = $PSScriptRoot
$bin = Join-Path $root 'bin\Debug\net10.0-windows'
# Directorio REAL del servicio (ImagePath del SCM), no bin\Debug.
$svc = Get-CimInstance Win32_Service -Filter "Name='OpenStreamMS'"
$install = if ($svc) { $svc.PathName -replace '^"?([^"]+)\\OpenStreamMS\.exe.*$', '$1' } else { 'C:\Program Files\OpenStreamMS' }
Write-Host "Install dir (servicio): $install" -ForegroundColor DarkCyan
if (-not $NoBuild) {
Write-Host '== 1. Build ==' -ForegroundColor Cyan
Push-Location $root
dotnet build -c Debug
if ($LASTEXITCODE -ne 0) { Pop-Location; throw 'Build fallido.' }
Pop-Location
}
Write-Host '== 2. Stop service + procesos hijos ==' -ForegroundColor Cyan
if ($svc -and $svc.State -ne 'Stopped') {
Stop-Service OpenStreamMS -Force
(Get-Service OpenStreamMS).WaitForStatus('Stopped', '00:00:30')
}
# Tray incluido: tiene abierto OpenStreamMS.exe y bloquearia la copia.
Get-Process wfreerdp, mstsc, sunshine -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process OpenStreamMS -ErrorAction SilentlyContinue |
Where-Object { $_.Path -and $_.Path.StartsWith($install, [StringComparison]::OrdinalIgnoreCase) } |
Stop-Process -Force
Start-Sleep -Seconds 1
Write-Host '== 3. Copiar binarios ==' -ForegroundColor Cyan
Get-ChildItem $bin -File | Where-Object { $_.Extension -in '.exe', '.dll', '.pdb', '.json', '.ico' -and
$_.Name -notin 'service.config.json', 'sessions.json' } |
ForEach-Object { Copy-Item $_.FullName (Join-Path $install $_.Name) -Force }
# bin\Debug es framework-dependent, pero el instalador deja un runtime self-contained.
# Con hostfxr.dll junto al exe, el apphost busca .NET en la carpeta de la app y no arranca
# ("You must install .NET"). Se quitan para que use el .NET compartido del sistema.
foreach ($f in 'hostfxr.dll', 'hostpolicy.dll') {
$p = Join-Path $install $f
if (Test-Path $p) { Move-Item $p "$p.bak" -Force; Write-Host " -> $f retirado (runtime self-contained)" -ForegroundColor Green }
}
foreach ($d in 'Sunshine', 'FreeRDP', 'wwwroot', 'runtimes') {
# /MIR: carpeta identica a bin (borra restos de versiones anteriores). Solo contienen binarios.
robocopy (Join-Path $bin $d) (Join-Path $install $d) /MIR /NFL /NDL /NJH /NJS /R:2 /W:1 | Out-Null
if ($LASTEXITCODE -ge 8) { throw "robocopy fallo en $d (codigo $LASTEXITCODE)" }
Write-Host " -> $d" -ForegroundColor Green
}
Write-Host '== 4. Versiones desplegadas ==' -ForegroundColor Cyan
Write-Host " Sunshine: $((Get-Item (Join-Path $install 'Sunshine\sunshine.exe')).VersionInfo.ProductVersion)"
Write-Host " wfreerdp: $((Get-Item (Join-Path $install 'FreeRDP\wfreerdp.exe')).VersionInfo.FileVersion)"
Write-Host '== 5. Start service ==' -ForegroundColor Cyan
Start-Service OpenStreamMS
Write-Host "service: $((Get-Service OpenStreamMS).Status)" -ForegroundColor Green
Write-Host ''
Write-Host 'Arranca una sesion y revisa su log:' -ForegroundColor Yellow
Write-Host ' "Actualizando Sunshine de la instancia", "Encoder hardware confirmado", "mstsc (AVC420 hw)"' -ForegroundColor Yellow
Write-Host 'Pulsa Enter para cerrar...'
[void][Console]::ReadLine()