#!/usr/bin/env bash
set -euo pipefail

cd /tmp/sublb-clean74-build/backend
test -f internal/web/dist/index.html
sed -n '1,20p' internal/web/dist/index.html
echo '--- BUILD ---'

VERSION=$(tr -d '\r\n' < ./cmd/server/VERSION)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -tags embed -ldflags="-s -w -X main.Version=${VERSION}" -trimpath -o /tmp/sublb-clean74-build/server-clean-74 ./cmd/server

ls -lh /tmp/sublb-clean74-build/server-clean-74

python3 - <<'PY'
from pathlib import Path
p = Path('/tmp/sublb-clean74-build/server-clean-74')
data = p.read_bytes()
for needle in [b'window.__APP_CONFIG__', b'__CSP_NONCE_VALUE__', b'nonce="3hCthC8t0XSNzpp5jzxHTg=="']:
    print(needle.decode('utf-8', 'ignore'), data.find(needle))
PY
