Files
html/downloads/blade-install.ps1
opus ffdaec3464
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync-0310
2026-04-20 03:10:02 +02:00

113 lines
5.8 KiB
PowerShell

# WEVIA Blade Install v4.0 — DEFINITIVE persistent install
# Run as Administrator in PowerShell:
# irm https://weval-consulting.com/downloads/blade-install.ps1 | iex
$ErrorActionPreference = "Continue"
$ProgressPreference = "SilentlyContinue"
$BASE = "https://weval-consulting.com"
$INSTALL_DIR = "C:\ProgramData\WEVAL"
New-Item -ItemType Directory -Path $INSTALL_DIR -Force -ErrorAction SilentlyContinue | Out-Null
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host " WEVIA Blade Agent v4.0 - DEFINITIVE INSTALL" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
# STEP 1: Kill all existing WEVIA/Sentinel agents
Write-Host "`n[1/6] Killing existing agents..." -ForegroundColor Yellow
Get-Process -Name powershell, pwsh -ErrorAction SilentlyContinue | Where-Object {
try { $_.CommandLine -match "sentinel-agent|blade-agent|wevia-agent" } catch { $false }
} | Stop-Process -Force -ErrorAction SilentlyContinue
Get-ScheduledTask -TaskName "WEVIA*", "Sentinel*", "Blade*" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false -ErrorAction SilentlyContinue
Write-Host " Done." -ForegroundColor Green
# STEP 2: Download agent v4
Write-Host "`n[2/6] Downloading agent v4..." -ForegroundColor Yellow
$agentPath = "$INSTALL_DIR\wevia-agent-v4.ps1"
try {
Invoke-WebRequest -Uri "$BASE/api/blade-tasks/wevia-agent-v4.ps1" -OutFile $agentPath -UseBasicParsing
Write-Host " Downloaded: $agentPath ($((Get-Item $agentPath).Length) bytes)" -ForegroundColor Green
} catch {
Write-Host " FAILED download: $_" -ForegroundColor Red
exit 1
}
# STEP 3: Register as scheduled task (runs at logon + every 5 min watchdog check)
Write-Host "`n[3/6] Registering scheduled task (auto-start at logon + 5min watchdog)..." -ForegroundColor Yellow
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$agentPath`""
$trigger1 = New-ScheduledTaskTrigger -AtLogOn
$trigger2 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 5)
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RestartCount 99 -RestartInterval (New-TimeSpan -Minutes 1)
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive -RunLevel Highest
Register-ScheduledTask -TaskName "WEVIA-Agent-v4" -Action $action -Trigger @($trigger1, $trigger2) -Settings $settings -Principal $principal -Force | Out-Null
Write-Host " Scheduled task registered (AtLogon + 5min watchdog)." -ForegroundColor Green
# STEP 4: Create watchdog script that relaunches agent if dead
Write-Host "`n[4/6] Installing watchdog..." -ForegroundColor Yellow
$watchdogPath = "$INSTALL_DIR\watchdog.ps1"
$watchdogScript = @'
# Relaunches agent if not heartbeating
$ErrorActionPreference = "Continue"
$wdFile = "C:\ProgramData\WEVAL\agent-v4.watchdog"
$agentPath = "C:\ProgramData\WEVAL\wevia-agent-v4.ps1"
if (Test-Path $wdFile) {
$lastTicks = [int64](Get-Content $wdFile -Raw).Trim()
$lastBeat = [DateTime]::new($lastTicks)
$delta = ((Get-Date) - $lastBeat).TotalSeconds
if ($delta -lt 120) {
# Agent alive, nothing to do
exit 0
}
}
# Agent dead or never started - launch it
$existing = Get-Process powershell -ErrorAction SilentlyContinue | Where-Object {
try { $_.CommandLine -match "wevia-agent-v4" } catch { $false }
}
if (!$existing) {
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$agentPath`"" -WindowStyle Hidden
Add-Content -Path "C:\ProgramData\WEVAL\watchdog.log" -Value "[$(Get-Date -Format 'o')] Relaunched agent"
}
'@
Set-Content -Path $watchdogPath -Value $watchdogScript -Force
Write-Host " Watchdog installed: $watchdogPath" -ForegroundColor Green
# STEP 5: Start the agent immediately
Write-Host "`n[5/6] Starting agent v4 NOW..." -ForegroundColor Yellow
Start-ScheduledTask -TaskName "WEVIA-Agent-v4" -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
$running = Get-Process powershell -ErrorAction SilentlyContinue | Where-Object {
try { $_.CommandLine -match "wevia-agent-v4" } catch { $false }
}
if ($running) {
Write-Host " Agent running (PID=$($running.Id))." -ForegroundColor Green
} else {
Write-Host " Agent did not start via task, launching direct..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$agentPath`"" -WindowStyle Hidden
}
# STEP 6: Verify heartbeat reaches server
Write-Host "`n[6/6] Verifying heartbeat to server..." -ForegroundColor Yellow
Start-Sleep -Seconds 10
try {
$status = Invoke-RestMethod -Uri "$BASE/api/blade-api.php?k=BLADE2026&action=status" -TimeoutSec 10
$reportedVersion = $status.blade.heartbeat.agent_version
if ($reportedVersion -eq "4.0") {
Write-Host " SUCCESS: Server reports agent_version=4.0" -ForegroundColor Green
} else {
Write-Host " WARNING: Server reports agent_version=$reportedVersion (expected 4.0)" -ForegroundColor Yellow
Write-Host " Wait 30s and re-run status check" -ForegroundColor Yellow
}
} catch {
Write-Host " Status check failed: $_" -ForegroundColor Red
}
Write-Host "`n============================================================" -ForegroundColor Cyan
Write-Host " INSTALL COMPLETE" -ForegroundColor Cyan
Write-Host " Logs: $INSTALL_DIR\agent-v4.log" -ForegroundColor Gray
Write-Host " Watchdog: runs every 5 min via scheduler" -ForegroundColor Gray
Write-Host " Agent restarts automatically on logoff/reboot" -ForegroundColor Gray
Write-Host "============================================================" -ForegroundColor Cyan