65 lines
2.4 KiB
PowerShell
65 lines
2.4 KiB
PowerShell
# First-time LAN deploy: bootstrap, craftshop-remote-lan.env, deploy-ssh.ps1 -All, systemd.
|
|
# Prerequisites: SSH to root works with key (see register-ssh-key-for-root.ps1).
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$scriptsDir = $PSScriptRoot
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptsDir "..")).Path
|
|
$deployEnv = Join-Path $scriptsDir "deploy.env"
|
|
|
|
if (-not (Test-Path $deployEnv)) {
|
|
Write-Error "Missing scripts/deploy.env - copy deploy.env.example and set DEPLOY_HOST."
|
|
}
|
|
|
|
. "$PSScriptRoot\read-deploy-env.ps1"
|
|
Import-DeployDotEnv $deployEnv
|
|
|
|
$deployHost = [Environment]::GetEnvironmentVariable("DEPLOY_HOST", "Process")
|
|
$user = [Environment]::GetEnvironmentVariable("DEPLOY_USER", "Process")
|
|
if ([string]::IsNullOrWhiteSpace($user)) { $user = "root" }
|
|
if ([string]::IsNullOrWhiteSpace($deployHost)) {
|
|
Write-Error "DEPLOY_HOST is missing in scripts/deploy.env."
|
|
}
|
|
|
|
$remote = "${user}@${deployHost}"
|
|
$bootstrap = Join-Path $scriptsDir "server-bootstrap.sh"
|
|
$lanEnv = Join-Path $scriptsDir "craftshop-remote-lan.env"
|
|
|
|
if (-not (Test-Path $bootstrap)) {
|
|
Write-Error "Bootstrap script not found: $bootstrap"
|
|
}
|
|
|
|
if (-not (Test-Path $lanEnv)) {
|
|
Write-Error "Missing scripts/craftshop-remote-lan.env (gitignored). Create it or copy from server/.env.example."
|
|
}
|
|
|
|
ssh -o BatchMode=yes -o ConnectTimeout=8 $remote "echo ok" 2>$null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Passwordless SSH to $remote failed. Run .\scripts\register-ssh-key-for-root.ps1 first."
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ">>> scp bootstrap"
|
|
scp -o StrictHostKeyChecking=accept-new $bootstrap "${remote}:/root/server-bootstrap.sh"
|
|
|
|
Write-Host ">>> run bootstrap on server"
|
|
ssh $remote "bash /root/server-bootstrap.sh"
|
|
|
|
Write-Host ">>> scp server .env"
|
|
scp -o StrictHostKeyChecking=accept-new $lanEnv "${remote}:/opt/craftshop/server/.env"
|
|
|
|
Write-Host ">>> chmod .env (owner = same as /opt/craftshop/server, deploy or root)"
|
|
ssh $remote "chown --reference=/opt/craftshop/server /opt/craftshop/server/.env || chown root:root /opt/craftshop/server/.env; chmod 600 /opt/craftshop/server/.env"
|
|
|
|
Set-Location $repoRoot
|
|
Write-Host ">>> deploy-ssh.ps1 -All"
|
|
& (Join-Path $scriptsDir "deploy-ssh.ps1") -All
|
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
|
|
Write-Host ">>> systemd enable craftshop-api"
|
|
ssh $remote "systemctl enable --now craftshop-api"
|
|
|
|
Write-Host ">>> health check"
|
|
ssh $remote "curl -sS http://127.0.0.1:3333/health"
|
|
|
|
Write-Host "Done. Open http://${deployHost}/"
|