70 lines
2.8 KiB
PowerShell
70 lines
2.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
OnEver Drive — Windows Agent Service Installer
|
|
.DESCRIPTION
|
|
Installs and configures the OnEver Drive Windows Agent as a background system service.
|
|
#>
|
|
|
|
param (
|
|
[string]$ServerUrl = "http://127.0.0.1:8000",
|
|
[string]$RegistrationCode = "",
|
|
[string]$ClientName = ""
|
|
)
|
|
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host " OnEver Drive — Windows Service Setup Script " -ForegroundColor Cyan
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
|
|
$CurrentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$AgentDir = Split-Path -Parent $CurrentDir
|
|
$PythonExe = (Get-Command python.exe -ErrorAction SilentlyContinue).Source
|
|
|
|
if (-not $PythonExe) {
|
|
Write-Error "Python 3.10+ was not found on PATH. Please install Python first."
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "[+] Detected Python executable: $PythonExe" -ForegroundColor Green
|
|
Write-Host "[+] Agent root directory: $AgentDir" -ForegroundColor Green
|
|
|
|
# 1. If registration code provided, perform initial registration
|
|
if ($RegistrationCode -ne "") {
|
|
Write-Host "[*] Registering agent against server: $ServerUrl..." -ForegroundColor Yellow
|
|
$RegArgs = @("$AgentDir\agent_cli.py", "register", "--server", $ServerUrl, "--code", $RegistrationCode)
|
|
if ($ClientName -ne "") {
|
|
$RegArgs += @("--name", $ClientName)
|
|
}
|
|
& $PythonExe $RegArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "Registration failed. Please check registration code and server connectivity."
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# 2. Service definition
|
|
$ServiceName = "OnEverDriveAgent"
|
|
$ServiceDisplayName = "OnEver Drive Backup Agent Service"
|
|
$ServiceDescription = "Enterprise chunked backup and sync daemon for OnEver Drive Proxmox platform."
|
|
$ServiceBinary = "`"$PythonExe`" `"$AgentDir\agent_cli.py`" daemon"
|
|
|
|
Write-Host "[*] Registering Windows Service: $ServiceName..." -ForegroundColor Yellow
|
|
|
|
# Stop and remove existing service if present
|
|
$ExistingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
if ($ExistingService) {
|
|
Write-Host "[-] Stopping and removing existing service..." -ForegroundColor Yellow
|
|
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
|
|
sc.exe delete $ServiceName
|
|
Start-Sleep -Seconds 2
|
|
}
|
|
|
|
# Create service using sc.exe
|
|
sc.exe create $ServiceName binPath= $ServiceBinary start= auto DisplayName= $ServiceDisplayName
|
|
sc.exe description $ServiceName $ServiceDescription
|
|
|
|
# Configure recovery options (restart service on crash)
|
|
sc.exe failure $ServiceName reset= 86400 actions= restart/60000/restart/60000/restart/60000
|
|
|
|
Write-Host "[+] Service '$ServiceName' registered successfully!" -ForegroundColor Green
|
|
Write-Host "[*] To start the service run: Start-Service $ServiceName" -ForegroundColor Cyan
|