#!/bin/bash # 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" < "$DATA/review.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"