$ErrorActionPreference = "Stop"
# -------------------------------
# Logging Helpers
# -------------------------------
function Log-Info {
param([string]$msg)
Write-Output "[INFO] $msg"
}
function Log-Error {
param([string]$msg)
Write-Output "[ERROR] $msg"
}
function Log-Success {
param([string]$msg)
Write-Output "[SUCCESS] $msg"
}
# -------------------------------
# Paths
# -------------------------------
$FolderPath = "C:\Users\Public\netmaker-rac"
$FilePath = "$FolderPath\ctx.json"
$ExePath = ".\netmaker-desktop-installer.exe"
$AppPath = "C:\Program Files\Netmaker Desktop\netmaker-desktop.exe"
$TaskName = "NetmakerDesktopStartup"
# -------------------------------
# JSON content
# -------------------------------
$JsonContent = @'
{
"server": "server.domain"
}
'@
try {
# -------------------------------
# Create folder
# -------------------------------
Log-Info "Creating config directory..."
if (!(Test-Path $FolderPath)) {
New-Item -ItemType Directory -Path $FolderPath -Force | Out-Null
}
# -------------------------------
# Write JSON
# -------------------------------
Log-Info "Writing ctx.json..."
$JsonContent | Set-Content -Path $FilePath -Encoding ASCII -Force
# Validate JSON
Log-Info "Validating configuration..."
Get-Content $FilePath | ConvertFrom-Json | Out-Null
# -------------------------------
# Verify installer
# -------------------------------
Log-Info "Checking installer..."
if (!(Test-Path $ExePath)) {
Log-Error "Installer EXE not found"
exit 1
}
# -------------------------------
# Install
# -------------------------------
Log-Info "Installing Netmaker Desktop..."
Start-Process $ExePath -ArgumentList "/quiet /norestart" -Wait
# -------------------------------
# Verify install
# -------------------------------
Log-Info "Verifying installation..."
if (!(Test-Path $AppPath)) {
Log-Error "Netmaker executable not found after installation"
exit 1
}
# -------------------------------
# Scheduled Task
# -------------------------------
Log-Info "Configuring startup task..."
if (schtasks /Query /TN $TaskName 2>$null) {
schtasks /Delete /TN $TaskName /F | Out-Null
}
schtasks /Create `
/TN $TaskName `
/TR "`"$AppPath`"" `
/SC ONLOGON `
/RL HIGHEST `
/F | Out-Null
# -------------------------------
# Launch app
# -------------------------------
Log-Info "Launching Netmaker Desktop..."
Start-Process -FilePath $AppPath
Log-Success "Installation completed successfully"
exit 0
}
catch {
Log-Error $_.Exception.Message
exit 1
}