| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/bin/bash
- #
- # uoj-db image preparation. Runs at *build* time and only stages files for
- # the mysql entrypoint, which executes /docker-entrypoint-initdb.d/* on the
- # first start (i.e. when ./uoj_data/db/mysql is empty).
- set -eu
- setLAMPConf(){
- printf "\n\n==> Setting mysqld config\n"
- # NOTE: the previous version wrote `init_connect` twice; mysqld keeps only
- # the last occurrence, so the connection charset was never applied.
- cat >/etc/mysql/conf.d/uoj_mysqld.cnf <<UOJEOF
- [mysqld]
- default-time-zone='+8:00'
- character-set-server=utf8mb4
- collation-server=utf8mb4_unicode_ci
- init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
- skip-character-set-client-handshake
- sql-mode=ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
- UOJEOF
- }
- setWebConf(){
- printf "\n\n==> Staging database init scripts\n"
- cat >/docker-entrypoint-initdb.d/000-native_password.sql <<UOJEOF
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
- UOJEOF
- for f in app_uoj233.sql add_judger.sql; do
- if [ ! -s "$f" ]; then
- echo "ERROR: $f is missing or empty" >&2
- exit 1
- fi
- done
- # 001 is the current schema (30 tables, includes the WyOJ additions:
- # songs / pastes / rp / datum_* and the extra user_info columns).
- # See ../docker-compose.seed.yml to import a full dump instead.
- cp app_uoj233.sql /docker-entrypoint-initdb.d/001-app_uoj233.sql
- cp add_judger.sql /docker-entrypoint-initdb.d/002-add_judger.sql
- ls -l /docker-entrypoint-initdb.d/
- }
- echo 'Preparing UOJ System db environment...'
- setLAMPConf
- setWebConf
|