51 lines
1.8 KiB
PowerShell
51 lines
1.8 KiB
PowerShell
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location $scriptDir
|
|
|
|
function Test-EnvVarLine {
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$FilePath,
|
|
[Parameter(Mandatory = $true)][string]$Name
|
|
)
|
|
if (-not (Test-Path -LiteralPath $FilePath)) {
|
|
return $false
|
|
}
|
|
return [bool](Select-String -Path $FilePath -Pattern ("^\s*" + [regex]::Escape($Name) + "=") -Quiet)
|
|
}
|
|
|
|
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
|
$venvPython = Join-Path $scriptDir ".venv\Scripts\python.exe"
|
|
if (-not (Test-Path -LiteralPath $venvPython)) {
|
|
throw "Python was not found in PATH and .venv\\Scripts\\python.exe is missing. Install Python 3.11+ or create .venv first."
|
|
}
|
|
}
|
|
|
|
$pythonExe = $null
|
|
$venvPython = Join-Path $scriptDir ".venv\Scripts\python.exe"
|
|
if (Test-Path -LiteralPath $venvPython) {
|
|
$pythonExe = $venvPython
|
|
} else {
|
|
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
|
if ($null -eq $pythonCmd) {
|
|
throw "Python was not found in PATH. Install Python 3.11+ or create .venv first."
|
|
}
|
|
$pythonExe = $pythonCmd.Source
|
|
}
|
|
|
|
$envFile = Join-Path $scriptDir ".env"
|
|
if (-not (Test-Path -LiteralPath $envFile)) {
|
|
Write-Warning ".env was not found at $envFile. Server startup may fail if required vars are missing."
|
|
} else {
|
|
if (-not (Test-EnvVarLine -FilePath $envFile -Name "OPENAI_API_KEY")) {
|
|
Write-Warning ".env is missing OPENAI_API_KEY."
|
|
}
|
|
if (-not (Test-EnvVarLine -FilePath $envFile -Name "SCREENJOB_TOKEN")) {
|
|
Write-Warning ".env is missing SCREENJOB_TOKEN."
|
|
}
|
|
}
|
|
|
|
Write-Host "Starting ScreenJob backend on configured host/port..." -ForegroundColor Cyan
|
|
& $pythonExe main.py server
|