Files
news-platform/deploy/scripts/wordpress-sync-options-url.sh
T
Artur Moreira 5e14e2df47 fix(deploy): auto-set WordPress public URL and sync wp_options on LXC
Add wordpress-ensure-public-url.sh (exit 2 when .env updated) and
wordpress-sync-options-url.sh to align siteurl/home with HTTPS. Wire
into deploy.sh and webhook-deploy.sh for /opt/news-platform only so
the board does not need manual .env or SQL for BIT-470/BIT-471.

Made-with: Cursor
2026-03-24 19:02:10 +00:00

56 lines
1.3 KiB
Bash
Executable File

#!/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}"