#!/usr/bin/env bash # Align wp_options siteurl/home with WORDPRESS_PUBLIC_URL (fixes wp-login redirects # when the DB still has localhost from an early install). Runs MariaDB inside the # Compose network. No-op outside /opt/news-platform or when URL is still local. set -euo pipefail APP_DIR="${APP_DIR:-/opt/news-platform}" WP_DIR="$APP_DIR/wordpress" ENV_FILE="$WP_DIR/.env" log() { echo "[wordpress-sync-options-url] $*"; } if [ "$APP_DIR" != "/opt/news-platform" ]; then exit 0 fi if [ ! -f "$ENV_FILE" ]; then exit 0 fi set -a # shellcheck disable=SC1090 source "$ENV_FILE" set +a URL="${WORDPRESS_PUBLIC_URL:-}" URL="${URL%/}" if [ -z "$URL" ]; then exit 0 fi if [[ "$URL" == *"localhost"* ]] || [[ "$URL" == *"127.0.0.1"* ]]; then exit 0 fi PREFIX="${WORDPRESS_TABLE_PREFIX:-wp_}" TABLE="${PREFIX}options" cd "$WP_DIR" if ! docker compose ps -q db >/dev/null 2>&1; then exit 0 fi if [ -z "$(docker compose ps -q db --status running 2>/dev/null || true)" ]; then log "db container not running, skip" exit 0 fi escaped="${URL//\'/\'\\\'\'}" docker compose exec -T db mariadb -uwordpress -p"${MYSQL_PASSWORD}" wordpress \ -e "UPDATE ${TABLE} SET option_value='${escaped}' WHERE option_name IN ('siteurl','home');" log "Updated ${TABLE} siteurl/home → ${URL}"