You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
80 lines
3.0 KiB
# GeoNetAgent - Install atau update ke %ProgramData%\GeoNetAgent |
|
# Unduh dari https://agent.gisportal.id/install atau -SourcePath lokal |
|
[CmdletBinding()] |
|
param( |
|
[string]$BaseUrl = 'https://agent.gisportal.id/install', |
|
[string]$InstallRoot = (Join-Path $env:ProgramData 'GeoNetAgent'), |
|
[string]$AgentToken, |
|
[string]$SourcePath, |
|
[switch]$SkipScheduledTask, |
|
[switch]$SkipInitialRun, |
|
[int]$ScheduleHours = 3 |
|
) |
|
|
|
$ErrorActionPreference = 'Stop' |
|
$core = Join-Path $PSScriptRoot 'lib\Agent-InstallCore.ps1' |
|
if (-not (Test-Path $core)) { |
|
$core = Join-Path $InstallRoot 'lib\Agent-InstallCore.ps1' |
|
} |
|
if (-not (Test-Path $core)) { |
|
throw "Agent-InstallCore.ps1 tidak ditemukan (cari di $PSScriptRoot\lib dan $InstallRoot\lib)." |
|
} |
|
. $core |
|
|
|
$base = Get-GeoNetInstallBaseUrl -Url $BaseUrl |
|
Write-Host "GeoNetAgent install/update" -ForegroundColor Cyan |
|
Write-Host " Target: $InstallRoot" |
|
|
|
if (-not (Test-Path $InstallRoot)) { |
|
New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null |
|
} |
|
|
|
if ($SourcePath) { |
|
$sourceRoot = Resolve-Path $SourcePath |
|
$manifestPath = Join-Path $sourceRoot 'install\manifest.json' |
|
if (-not (Test-Path $manifestPath)) { |
|
$manifestPath = Join-Path $sourceRoot 'manifest.json' |
|
} |
|
if (-not (Test-Path $manifestPath)) { |
|
throw "manifest.json tidak ditemukan di $SourcePath" |
|
} |
|
$manifest = Get-Content $manifestPath -Raw | ConvertFrom-Json |
|
Write-Host "Salin dari lokal v$($manifest.version) ..." |
|
Copy-GeoNetAgentPayload -SourceRoot $sourceRoot -DestinationRoot $InstallRoot -Manifest $manifest |
|
Set-GeoNetAgentConfig -InstallRoot $InstallRoot -Base $base -Token $AgentToken -UseRemoteConfig:$false |
|
} |
|
else { |
|
Write-Host "Unduh dari $base ..." |
|
$manifest = Get-GeoNetRemoteJson -Url "$base/manifest.json" |
|
Write-Host "Paket v$($manifest.version) ($($manifest.files.Count) file)" |
|
Install-GeoNetAgentPayload -Base $base -DestinationRoot $InstallRoot -Manifest $manifest |
|
$remoteConfig = $false |
|
try { |
|
$null = Invoke-WebRequest -Uri "$base/config.json" -Method Head -UseBasicParsing |
|
$remoteConfig = $true |
|
} |
|
catch { } |
|
Set-GeoNetAgentConfig -InstallRoot $InstallRoot -Base $base -Token $AgentToken -UseRemoteConfig:$remoteConfig |
|
} |
|
|
|
Set-GeoNetLocalAgentVersion -InstallRoot $InstallRoot -Version $manifest.version |
|
|
|
if (-not $SkipScheduledTask) { |
|
if (-not (Test-GeoNetAdmin)) { |
|
Write-Warning 'Bukan Administrator - file terpasang, tetapi Scheduled Task dilewati. Jalankan ulang sebagai Admin.' |
|
} |
|
else { |
|
Write-Host 'Mendaftarkan Scheduled Task (SYSTEM: startup + tiap' $ScheduleHours 'jam) ...' |
|
Register-GeoNetAgentTask -InstallRoot $InstallRoot -Hours $ScheduleHours |
|
Write-Host 'Scheduled Task OK: GeoNetAgent-Report, GeoNetAgent-Report-Startup' -ForegroundColor Green |
|
} |
|
} |
|
|
|
if (-not $SkipInitialRun) { |
|
Write-Host 'Menjalankan laporan awal ...' -ForegroundColor Cyan |
|
& (Join-Path $InstallRoot 'UserAgent.ps1') |
|
exit $LASTEXITCODE |
|
} |
|
|
|
Write-Host 'Selesai.' -ForegroundColor Green |
|
exit 0
|
|
|