#!/bin/sh
# SPDX-License-Identifier: MIT
# Nginx Proxy Manager on the bench: the first account, created the way the first-run setup screen
# creates it (POST /api/users while no user exists yet, which makes it an administrator). Runs in
# the measured container, in /opt/banc/app. The simulated users of the profiles are the visitors of
# the proxied sites, not accounts.
#
#   comptes.sh N     writes /opt/banc/comptes.json for the load generator
set -eu
N=$1
P=$(head -c 18 /dev/urandom | base64 | tr -d '/+=\n')
code=$(curl -s -o /dev/null -w '%{http_code}' -X POST http://10.30.0.207:81/api/users \
  -H 'Content-Type: application/json' \
  -d "{\"name\":\"Bench Admin\",\"nickname\":\"bench\",\"email\":\"bench-admin@example.com\",\"auth\":{\"type\":\"password\",\"secret\":\"$P\"}}")
[ "$code" = 201 ] || { echo "first account: HTTP $code" >&2; exit 1; }
printf '{"api":"http://10.30.0.207:81/api","front":"10.30.0.207","email":"bench-admin@example.com","pass":"%s","n":%d}\n' "$P" "$N" > /opt/banc/comptes.json
