diff --git a/Start-OSE.ps1 b/Start-OSE.ps1 new file mode 100644 index 0000000..c36e5b0 --- /dev/null +++ b/Start-OSE.ps1 @@ -0,0 +1,36 @@ +param([Parameter(ValueFromRemainingArguments = $true)][string[]]$ServerArguments) +$ErrorActionPreference = 'Stop' +Set-Location -LiteralPath $PSScriptRoot +$environmentDirectory = Join-Path $PSScriptRoot '.venv' +$pythonExecutable = Join-Path $environmentDirectory 'Scripts\python.exe' +if (-not (Test-Path -LiteralPath $pythonExecutable)) { + Write-Host 'Preparing the Python environment...' + if (Get-Command py -ErrorAction SilentlyContinue) { + & py -3 -m venv $environmentDirectory + } elseif (Get-Command python -ErrorAction SilentlyContinue) { + & python -m venv $environmentDirectory + } else { + throw 'Install Python 3.10 or newer from python.org, then run this script again.' + } + if ($LASTEXITCODE -ne 0) { throw 'Could not create the Python environment.' } +} +& $pythonExecutable -c 'import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)' +if ($LASTEXITCODE -ne 0) { throw 'Python 3.10 or newer is required. Recreate .venv with a supported Python installation.' } +$requirements = Join-Path $PSScriptRoot 'requirements.txt' +$fingerprint = (Get-FileHash -LiteralPath $requirements -Algorithm SHA256).Hash +$marker = Join-Path $environmentDirectory 'ose-requirements.sha256' +$previous = if (Test-Path -LiteralPath $marker) { (Get-Content -LiteralPath $marker -Raw).Trim() } else { '' } +if ($previous -ne $fingerprint) { + Write-Host 'Installing the server dependencies. This may take a few minutes the first time...' + & $pythonExecutable -m pip install -r $requirements + if ($LASTEXITCODE -ne 0) { throw 'Dependency installation failed. Check the error above, then run this script again.' } + Set-Content -LiteralPath $marker -Value $fingerprint -Encoding Ascii +} +& $pythonExecutable -c 'from server_config import load_config; raise SystemExit(0 if load_config()["setup_complete"] else 1)' +if ($LASTEXITCODE -ne 0) { + & $pythonExecutable (Join-Path $PSScriptRoot 'manage.py') setup + if ($LASTEXITCODE -ne 0) { throw 'Setup was not completed. Run this script again when ready.' } +} +Write-Host 'Starting OSE. Press Ctrl+C in this window to stop it.' +& $pythonExecutable -u (Join-Path $PSScriptRoot 'server.py') @ServerArguments +exit $LASTEXITCODE