143 lines
6.5 KiB
Bash
Executable file
143 lines
6.5 KiB
Bash
Executable file
#!/bin/bash
|
|
# The MIT License (MIT)
|
|
#
|
|
# Copyright (C) 2026 Scott Duensing
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to
|
|
# deal in the Software without restriction, including without limitation the
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
# IN THE SOFTWARE.
|
|
|
|
# serve.sh DATA PORT FIXTURES DVXPKG USER PASSWORD -- the package server for the DOS tests (runDos.sh starts it
|
|
# for a "# REQUIRES: PKGSERVER" script and stops it by its PID). In DATA, from nothing:
|
|
#
|
|
# REPO.KEY / REPO.SEC a test repository key, made for this run
|
|
# guest/ what goes into the test DVX before it starts: the repository's public key
|
|
# in SYSTEM\KEYS, DVX's own record (kpunch.dvx, this DVX's version), and Sky
|
|
# 1.0 (FIXTURES/sky), both installed with the package tool
|
|
# server/ the DVX package server on 127.0.0.1:PORT (the guest's 10.0.2.2), holding
|
|
# Star (FIXTURES/star, which needs Sky), Sky 1.1 (FIXTURES/sky11), and the
|
|
# next patch version of DVX itself, each uploaded and approved with
|
|
# tools/review.lua as an operator would, and an account (USER, PASSWORD)
|
|
# the guest publishes with, registered and its mail link followed
|
|
# ready written once all that is done; server.log the server's output
|
|
#
|
|
# Then it waits for the server, and stops it when it is stopped. It exits at once, with a reason,
|
|
# when calog or singemaster is not there.
|
|
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
CALOG=${CALOG:-$HOME/claude/calog/bin/calog}
|
|
SINGE=${SINGE_HOME:-$(cd ../../singemaster 2>/dev/null && pwd)}
|
|
DATA=$1
|
|
PORT=$2
|
|
FIX=$3
|
|
DVXPKG=$4
|
|
USER_EMAIL=$5
|
|
USER_PASSWORD=$6
|
|
GUEST=$DATA/guest
|
|
ADMIN=$(head -c 16 /dev/urandom | xxd -p)
|
|
SERVER=""
|
|
|
|
fail() {
|
|
echo "serve.sh: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
stop() {
|
|
if [ -n "$SERVER" ]; then
|
|
kill "$SERVER" 2>/dev/null
|
|
wait "$SERVER" 2>/dev/null
|
|
SERVER=""
|
|
fi
|
|
}
|
|
|
|
trap 'stop; exit 0' TERM INT
|
|
trap stop EXIT
|
|
|
|
[ -x "$CALOG" ] || fail "calog is not at $CALOG (set CALOG)"
|
|
if [ -z "$SINGE" ] || [ ! -f "$SINGE/lib/service.lua" ]; then
|
|
fail "singemaster is not beside this repository (set SINGE_HOME)"
|
|
fi
|
|
[ -x "$DVXPKG" ] || fail "the package tool is not at $DVXPKG"
|
|
|
|
rm -rf "$DATA" && mkdir -p "$DATA/server" "$DATA/empty" "$DATA/next/SYSTEM" "$GUEST/SYSTEM/KEYS"
|
|
|
|
# The repository's key, and the guest's trust in it
|
|
"$DVXPKG" keygen "DVX Test Repository" "$DATA/REPO" > /dev/null || fail "keygen failed"
|
|
cp "$DATA/REPO.KEY" "$GUEST/SYSTEM/KEYS/TESTREPO.KEY"
|
|
|
|
# The guest's DVX record (a package of no files) and Sky 1.0, as the package tool installs them
|
|
"$DVXPKG" dvx "$DATA/dvx.ini" || fail "the package tool did not write DVX's template"
|
|
"$DVXPKG" build "$DATA/dvx.ini" "$DATA/empty" "$DATA/dvxnow.dpk" > /dev/null || fail "DVX's record package did not build"
|
|
"$DVXPKG" sign "$DATA/dvxnow.dpk" "$DATA/REPO.SEC" -d > /dev/null || fail "DVX's record package was not signed"
|
|
"$DVXPKG" install "$DATA/dvxnow.dpk" -r "$GUEST" -y > /dev/null || fail "DVX's record was not installed"
|
|
"$DVXPKG" build "$FIX/sky/PACKAGE.INI" "$FIX/sky" "$DATA/sky.dpk" > /dev/null || fail "Sky 1.0 did not build"
|
|
"$DVXPKG" install "$DATA/sky.dpk" -r "$GUEST" -y > /dev/null || fail "Sky 1.0 was not installed"
|
|
|
|
# What the server will hold: Star, Sky 1.1, and DVX's next patch version (one file of its own)
|
|
"$DVXPKG" build "$FIX/star/PACKAGE.INI" "$FIX/star" "$DATA/star.dpk" > /dev/null || fail "Star did not build"
|
|
"$DVXPKG" build "$FIX/sky11/PACKAGE.INI" "$FIX/sky11" "$DATA/sky11.dpk" > /dev/null || fail "Sky 1.1 did not build"
|
|
IFS=. read -r MAJOR MINOR PATCH < <(sed -n 's/^version *= *\([0-9.]*\).*/\1/p' "$DATA/dvx.ini")
|
|
sed "s/^version *= *[0-9.]*/version = $MAJOR.$MINOR.$((PATCH + 1))/" "$DATA/dvx.ini" > "$DATA/dvxnext.ini"
|
|
printf 'The DVX update of the DOS tests\r\n' > "$DATA/next/SYSTEM/UPDTEST.TXT"
|
|
"$DVXPKG" build "$DATA/dvxnext.ini" "$DATA/next" "$DATA/dvxnext.dpk" > /dev/null || fail "DVX's next version did not build"
|
|
|
|
cat > "$DATA/dvx.conf" <<CONF
|
|
bindHost = 127.0.0.1
|
|
bindPort = $PORT
|
|
publicOrigin = http://10.0.2.2:$PORT
|
|
dataDir = $DATA/server
|
|
database = $DATA/server/dvx.db
|
|
pbkdf2Iterations = 1000
|
|
mailFrom = test@example.com
|
|
dvxpkg = $DVXPKG
|
|
repoKey = $DATA/REPO.KEY
|
|
serveContexts = 3
|
|
uploadMax = 67108864
|
|
adminToken = $ADMIN
|
|
CONF
|
|
cat > "$DATA/review.conf" <<CONF
|
|
server = http://127.0.0.1:$PORT
|
|
token = $ADMIN
|
|
dvxpkg = $DVXPKG
|
|
secret = $DATA/REPO.SEC
|
|
work = $DATA/review
|
|
CONF
|
|
|
|
"$CALOG" dvxserver.lua -- "singe=$SINGE" "$DATA/dvx.conf" > "$DATA/server.log" 2>&1 &
|
|
SERVER=$!
|
|
|
|
for _ in $(seq 1 40); do
|
|
curl -s -m 1 "http://127.0.0.1:$PORT/v1/health" > /dev/null 2>&1 && break
|
|
sleep 0.25
|
|
done
|
|
|
|
curl -s -m 1 "http://127.0.0.1:$PORT/v1/health" > /dev/null 2>&1 || fail "the server did not start (see $DATA/server.log)"
|
|
|
|
# Each uploaded by the operator and approved with the review tool
|
|
for pkg in star sky11 dvxnext; do
|
|
status=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/octet-stream" --data-binary "@$DATA/$pkg.dpk" "http://127.0.0.1:$PORT/v1/upload")
|
|
[ "$status" = "202" ] || fail "uploading $pkg answered $status"
|
|
read -r id version _ < <("$DVXPKG" info "$DATA/$pkg.dpk")
|
|
"$CALOG" tools/review.lua -- "singe=$SINGE" "$DATA/review.conf" approve "$id" "$version" > "$DATA/review-$pkg.log" 2>&1 || fail "approving $pkg failed (see $DATA/review-$pkg.log)"
|
|
done
|
|
|
|
# The account the guest publishes with
|
|
"$CALOG" test/account.lua -- "http://127.0.0.1:$PORT" "$DATA/server/dvx.db" "$USER_EMAIL" "$USER_PASSWORD" > "$DATA/account.log" 2>&1 || fail "the account was not made (see $DATA/account.log)"
|
|
|
|
touch "$DATA/ready"
|
|
wait "$SERVER"
|