mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
e044fcf359
The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done: the workspace and checks, bakashrot-proto, bakashrot-pki and bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the server and the client library (every request but replication's, attachments and retention included), the C DLL with its C, PureBasic and Python bindings, and the bakashrot tool. Step 11 (replication) is next. OldSource/ is the old implementation, kept building and passing as the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
68 lines
2.6 KiB
PowerShell
68 lines
2.6 KiB
PowerShell
# ============================================================================
|
|
# BakaShrot example: starts the server with server.ini.
|
|
#
|
|
# In a window of its own by default (the server needs a console: it reads
|
|
# its commands there, and stops at once without one), then waits until it
|
|
# listens. Type "quit" in that window to stop it, "help" for the others.
|
|
#
|
|
# Usage: powershell -ExecutionPolicy Bypass -File Start-Server.ps1 [-BinDir <dir>] [-Here] [-Reset]
|
|
# -BinDir Where BakaShrot_Server.exe is, with libsodium.dll and
|
|
# sqlite3.dll: Build\ by default (Build.ps1), or a Release\<v>\.
|
|
# -Here Runs it in this console instead, until "quit".
|
|
# -Reset Deletes the example's database first: no messages, ids from 1.
|
|
#
|
|
# Its database, example.sqlite, goes next to this script.
|
|
# ============================================================================
|
|
|
|
param(
|
|
[string]$BinDir = (Join-Path $PSScriptRoot "..\..\Build"),
|
|
[switch]$Here,
|
|
[switch]$Reset
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$Server = Join-Path $BinDir "BakaShrot_Server.exe"
|
|
$Ini = Join-Path $PSScriptRoot "server.ini"
|
|
$Port = 12360
|
|
|
|
function Test-Port($Port) {
|
|
$Client = New-Object System.Net.Sockets.TcpClient
|
|
try {
|
|
$Async = $Client.BeginConnect("127.0.0.1", $Port, $null, $null)
|
|
return ($Async.AsyncWaitHandle.WaitOne(200) -and $Client.Connected)
|
|
} catch { return $false }
|
|
finally { $Client.Close() }
|
|
}
|
|
|
|
if (-not (Test-Path $Server)) {
|
|
throw "No ${Server}: build it first (Build.ps1), or pass -BinDir"
|
|
}
|
|
if (Test-Port $Port) {
|
|
throw "Something already listens on port $Port, the example server may already run"
|
|
}
|
|
|
|
if ($Reset) {
|
|
Get-ChildItem $PSScriptRoot -Filter "example.sqlite*" | Remove-Item -Confirm:$false
|
|
Write-Host "Deleted the example's database"
|
|
}
|
|
|
|
if ($Here) {
|
|
Push-Location $PSScriptRoot
|
|
try { & $Server $Ini }
|
|
finally { Pop-Location }
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
$Process = Start-Process -FilePath $Server -ArgumentList "`"$Ini`"" -WorkingDirectory $PSScriptRoot -PassThru
|
|
$Deadline = (Get-Date).AddSeconds(15)
|
|
while (-not (Test-Port $Port)) {
|
|
if ($Process.HasExited) { throw "The server stopped with code $($Process.ExitCode), see its log above" }
|
|
if ((Get-Date) -gt $Deadline) { throw "The server isn't listening on $Port after 15 s" }
|
|
Start-Sleep -Milliseconds 100
|
|
}
|
|
|
|
Write-Host "The server runs in its own window (process $($Process.Id)), on 127.0.0.1:$Port."
|
|
Write-Host "Try it with: powershell -ExecutionPolicy Bypass -File `"$(Join-Path $PSScriptRoot 'Run-Client.ps1')`""
|
|
Write-Host "Stop it by typing quit in its window."
|