install.sh 1.6 KB

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