-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
95 lines (82 loc) · 3.57 KB
/
install.ps1
File metadata and controls
95 lines (82 loc) · 3.57 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
param(
[string]$Destination = "$HOME\\.local\\bin",
[string]$Configuration = "Release",
[string]$Rid,
[switch]$SelfContained = $true,
[switch]$SkipUserEnvironmentUpdate
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $repoRoot
if (-not $Rid) {
$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) {
if ($architecture -eq "Arm64") {
$Rid = "win-arm64"
} else {
$Rid = "win-x64"
}
} elseif ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::OSX)) {
if ($architecture -eq "Arm64") {
$Rid = "osx-arm64"
} else {
$Rid = "osx-x64"
}
} else {
if ($architecture -eq "Arm64") {
$Rid = "linux-arm64"
} else {
$Rid = "linux-x64"
}
}
}
$dotnet = $env:DOTNET_HOST_PATH
if (-not $dotnet -or -not (Test-Path $dotnet)) {
$dotnet = Join-Path $HOME ".dotnet\dotnet.exe"
}
if (-not $dotnet -or -not (Test-Path $dotnet)) {
$dotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue
if ($dotnetCommand) {
$dotnet = $dotnetCommand.Source
}
}
if (-not (Test-Path $dotnet)) {
throw "Unable to locate dotnet. Install the .NET 9 SDK or set DOTNET_HOST_PATH."
}
$publishRoot = Join-Path $repoRoot ".artifacts\install\$Rid"
$cliOut = Join-Path $publishRoot "cli"
$daemonOut = Join-Path $publishRoot "daemon"
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
Remove-Item -Recurse -Force $publishRoot -ErrorAction SilentlyContinue
if (-not $SelfContained) {
throw "Non-self-contained install publishes are not supported by the current solution layout. Use the default self-contained install."
}
$commonArgs = @("-c", $Configuration, "-r", $Rid, "-p:PublishSingleFile=true")
$commonArgs += "--self-contained"
$commonArgs += "true"
& $dotnet publish "src/AgentPowerShell.Cli/AgentPowerShell.Cli.csproj" @commonArgs "-o" $cliOut
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
& $dotnet publish "src/AgentPowerShell.Daemon/AgentPowerShell.Daemon.csproj" @commonArgs "-o" $daemonOut
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Copy-Item (Join-Path $cliOut "*") -Destination $Destination -Recurse -Force
Copy-Item default-policy.yml -Destination (Join-Path $Destination "default-policy.yml") -Force
Copy-Item config.yml -Destination (Join-Path $Destination "config.yml") -Force
$daemonTarget = Join-Path $Destination "daemon"
New-Item -ItemType Directory -Force -Path $daemonTarget | Out-Null
Copy-Item (Join-Path $daemonOut "*") -Destination $daemonTarget -Recurse -Force
$daemonBinaryName = if ($Rid.StartsWith("win-", [System.StringComparison]::OrdinalIgnoreCase)) { "AgentPowerShell.Daemon.exe" } else { "AgentPowerShell.Daemon" }
$daemonBinary = Join-Path $daemonTarget $daemonBinaryName
if ((Test-Path $daemonBinary) -and -not $SkipUserEnvironmentUpdate) {
[Environment]::SetEnvironmentVariable("AGENTPOWERSHELL_DAEMON_PATH", $daemonBinary, "User")
}
Write-Host "Installed AgentPowerShell to $Destination"
Write-Host "RID: $Rid"
if ((Test-Path $daemonBinary) -and -not $SkipUserEnvironmentUpdate) {
Write-Host "Configured AGENTPOWERSHELL_DAEMON_PATH for the current user."
} elseif ((Test-Path $daemonBinary) -and $SkipUserEnvironmentUpdate) {
Write-Host "Skipped AGENTPOWERSHELL_DAEMON_PATH user-environment update."
}