#!/bin/sh # # Register (or update) this judger in the web database. Run it on the *host*, # after `docker compose up`, whenever JUDGER_PASSWORD / JUDGER_SOCKET_* change. # # ./judger/register-judger.sh # ./judger/register-judger.sh main_judger 'my-secret' uoj-judger # # It is an upsert, so it is safe to re-run. # # judger_name must equal JUDGER_NAME in the judger container (see # docker-compose.yml); ip is what /judge/sync-judge-client dials, so for # compose that is the service name `uoj-judger`. set -eu JUDGER_NAME="${1:-${JUDGER_NAME:-main_judger}}" JUDGER_PASSWORD="${2:-${JUDGER_PASSWORD:-_judger_password_}}" JUDGER_IP="${3:-${JUDGER_IP:-uoj-judger}}" DB_CONTAINER="${DB_CONTAINER:-uoj-db}" DB_NAME="${DATABASE_NAME:-app_uoj233}" DB_USER="${DATABASE_USER:-root}" DB_PASSWORD="${DATABASE_PASSWORD:-root}" # Keep passwords free of single quotes: they are embedded in SQL below. case "$JUDGER_NAME$JUDGER_PASSWORD$JUDGER_IP" in *"'"*) echo "ERROR: passwords/names must not contain a single quote" >&2 exit 1 ;; esac docker exec -i "$DB_CONTAINER" \ mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" <