1#!/bin/sh
2set -e
3
4engine=$(printf "%s" "${ZNOTE_SERVER_ENGINE:-TFS_10}" | tr '[:upper:]' '[:lower:]')
5schema="/schemas/${engine}.sql"
6
7if [ ! -f "$schema" ]; then
8 case "$engine" in
9 tfs_02)
10 echo "[znotex] No dedicated TFS 0.2.13+ schema is bundled; falling back to the TFS_03 schema (TFS 0.3.6+/0.4/OTX). Ultra-legacy tables some TFS_02-only pages use may be missing." >&2
11 schema="/schemas/tfs_03.sql"
12 ;;
13 *)
14 echo "[znotex] Unknown ZNOTE_SERVER_ENGINE '${ZNOTE_SERVER_ENGINE}', falling back to TFS_10." >&2
15 schema="/schemas/tfs_10.sql"
16 ;;
17 esac
18fi
19
20echo "[znotex] Importing game schema: $schema"
21mysql --user=root --password="$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" < "$schema"
22
23if [ "$engine" = "tfs_10" ] && [ -f /demo-data-tfs_10.sql ]; then
24 echo "[znotex] Importing TFS_10 demo accounts/players/guild."
25 mysql --user=root --password="$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" < /demo-data-tfs_10.sql
26else
27 echo "[znotex] No demo game data for engine '$engine' - the database will have ZnoteX's own tables only, no demo accounts/characters."
28fi
29
30echo "[znotex] Importing ZnoteX's own schema."
31mysql --user=root --password="$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" < /znote-schema.sql
32
33if [ "$engine" = "tfs_10" ]; then
34 echo "[znotex] Activating the demo account."
35 mysql --user=root --password="$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" \
36 -e "UPDATE znote_accounts SET active = 1, active_email = 1 WHERE account_id = 1;"
37fi
38