diff --git a/deploy.sh b/deploy.sh index 5d5616f..739326e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -891,6 +891,24 @@ apply_server_config(){ fi } +update_realmlist(){ + info "Updating realmlist in database with current SERVER_ADDRESS and REALM_PORT..." + + local update_script="$ROOT_DIR/scripts/bash/update-realmlist.sh" + if [ ! -x "$update_script" ]; then + warn "Realmlist update script not found or not executable: $update_script" + return 0 + fi + + # Run the update script + if bash "$update_script"; then + ok "Realmlist updated successfully" + else + warn "Could not update realmlist - this is normal if database is still initializing" + info "The realmlist will be updated on next deployment or you can run: ./scripts/bash/update-realmlist.sh" + fi +} + main(){ if [ "$ASSUME_YES" -ne 1 ]; then if [ -t 0 ]; then @@ -947,29 +965,32 @@ main(){ fi fi - show_step 1 4 "Checking build requirements" + show_step 1 7 "Checking build requirements" if ! prompt_build_if_needed; then err "Build required but not completed. Deployment cancelled." exit 1 fi if [ "$KEEP_RUNNING" -ne 1 ]; then - show_step 2 4 "Stopping runtime stack" + show_step 2 7 "Stopping runtime stack" stop_runtime_stack fi - show_step 3 5 "Importing user database files" + show_step 3 7 "Importing user database files" info "Checking for database files in ./import/db/ and ./database-import/" bash "$ROOT_DIR/scripts/bash/import-database-files.sh" - show_step 4 6 "Bringing your realm online" + show_step 4 7 "Bringing your realm online" info "Pulling images and waiting for containers to become healthy; this may take a few minutes on first deploy." stage_runtime - show_step 5 6 "Applying server configuration" + show_step 5 7 "Applying server configuration" apply_server_config - show_step 6 6 "Finalizing deployment" + show_step 6 7 "Updating realmlist" + update_realmlist + + show_step 7 7 "Finalizing deployment" mark_deployment_complete show_realm_ready diff --git a/scripts/bash/update-realmlist.sh b/scripts/bash/update-realmlist.sh new file mode 100644 index 0000000..3592c61 --- /dev/null +++ b/scripts/bash/update-realmlist.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# Updates the realmlist table in the database with current SERVER_ADDRESS and REALM_PORT from .env +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +# Source colors and functions +BLUE='\033[0;34m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' + +info() { printf '%b\n' "${BLUE}ℹ️ $*${NC}"; } +ok() { printf '%b\n' "${GREEN}✅ $*${NC}"; } +warn() { printf '%b\n' "${YELLOW}⚠️ $*${NC}"; } +err() { printf '%b\n' "${RED}❌ $*${NC}"; } + +# Load environment variables from .env +if [ -f "$ROOT_DIR/.env" ]; then + # shellcheck disable=SC1091 + set -a + source "$ROOT_DIR/.env" + set +a +else + err "No .env file found at $ROOT_DIR/.env" + exit 1 +fi + +# Check required variables +if [ -z "$SERVER_ADDRESS" ]; then + err "SERVER_ADDRESS not set in .env" + exit 1 +fi + +if [ -z "$REALM_PORT" ]; then + err "REALM_PORT not set in .env" + exit 1 +fi + +if [ -z "$MYSQL_HOST" ]; then + err "MYSQL_HOST not set in .env" + exit 1 +fi + +if [ -z "$MYSQL_USER" ]; then + err "MYSQL_USER not set in .env" + exit 1 +fi + +if [ -z "$MYSQL_ROOT_PASSWORD" ]; then + err "MYSQL_ROOT_PASSWORD not set in .env" + exit 1 +fi + +if [ -z "$DB_AUTH_NAME" ]; then + err "DB_AUTH_NAME not set in .env" + exit 1 +fi + +info "Updating realmlist table..." +info " Address: $SERVER_ADDRESS" +info " Port: $REALM_PORT" + +# Try to update the database +if mysql -h "${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_ROOT_PASSWORD}" --skip-ssl-verify "${DB_AUTH_NAME}" \ + -e "UPDATE realmlist SET address='${SERVER_ADDRESS}', port=${REALM_PORT} WHERE id=1;" 2>/dev/null; then + ok "Realmlist updated successfully" + + # Show the current realmlist entry + mysql -h "${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_ROOT_PASSWORD}" --skip-ssl-verify "${DB_AUTH_NAME}" \ + -e "SELECT id, name, address, port FROM realmlist WHERE id=1;" 2>/dev/null || true + + exit 0 +else + warn "Could not update realmlist table" + warn "This is normal if the database is not yet initialized or MySQL is not running" + exit 1 +fi