#!/bin/sh

# Script to generate REST API credentials. These will be written to stdout,
# you can redirect stdout to etc/restapi.secret

# Exit on any error:
set -e

# The API URL is derived from the configured base URL, so that a judgedaemon
# talks to the installation this file belongs to. DOMJUDGE_RESTAPIURL is
# passed in by the makefiles; the fallback applies when run by hand.
RESTAPIURL="${DOMJUDGE_RESTAPIURL:-http://localhost/domjudge/api}"

echo "# Randomly generated on host `hostname`, `date`"
echo "# Format: '<ID> <API url> <user> <password>'"

printf "default\\t%s\\tjudgehost\\t" "$RESTAPIURL"
        head -c24 /dev/urandom | base64 | head -c32 | tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~'
echo
