2026-03-04 22:49:01 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
2026-03-05 00:12:31 +00:00
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
# 1️⃣ Generate wp-config.php if it does not exist (your original logic)
|
|
|
|
|
|
# -----------------------------------------------------------------
|
2026-03-04 22:49:01 +00:00
|
|
|
|
if [ ! -f /var/www/html/wp-config.php ]; then
|
|
|
|
|
|
wp config create \
|
|
|
|
|
|
--dbname="${WORDPRESS_DB_NAME}" \
|
|
|
|
|
|
--dbuser="${WORDPRESS_DB_USER}" \
|
|
|
|
|
|
--dbpass="${WORDPRESS_DB_PASSWORD}" \
|
|
|
|
|
|
--dbhost="${WORDPRESS_DB_HOST}" \
|
|
|
|
|
|
--path=/var/www/html \
|
|
|
|
|
|
--allow-root
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2026-03-05 00:12:31 +00:00
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
# 2️⃣ Helper: does the DB already have WordPress tables?
|
|
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
db_is_empty() {
|
|
|
|
|
|
# `wp db check` returns 0 when tables exist, non‑zero otherwise
|
|
|
|
|
|
wp db check > /dev/null 2>&1
|
|
|
|
|
|
return $?
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
# 3️⃣ If the DB is empty, perform a fresh install and import the XML
|
|
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
if ! db_is_empty; then
|
|
|
|
|
|
echo "⚡ Database empty – installing WordPress and importing XML …"
|
|
|
|
|
|
|
|
|
|
|
|
# Core install (adjust URL, title, admin credentials as needed)
|
|
|
|
|
|
wp core install \
|
|
|
|
|
|
--url="http://localhost" \
|
|
|
|
|
|
--title="IndyMedia" \
|
|
|
|
|
|
--admin_user=admin \
|
|
|
|
|
|
--admin_password=admin123 \
|
|
|
|
|
|
--admin_email=admin@example.com \
|
|
|
|
|
|
--skip-email \
|
|
|
|
|
|
--allow-root
|
|
|
|
|
|
|
|
|
|
|
|
# Import the exported content
|
|
|
|
|
|
wp import /tmp/site-export.xml --authors=create --skip=image_resize --allow-root
|
|
|
|
|
|
|
|
|
|
|
|
# Flush rewrite rules so permalinks work
|
|
|
|
|
|
wp rewrite flush --hard --allow-root
|
|
|
|
|
|
|
|
|
|
|
|
echo "✅ Import complete."
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
# 4️⃣ Hand over to the official WordPress entrypoint (starts Apache)
|
|
|
|
|
|
# -----------------------------------------------------------------
|
|
|
|
|
|
exec /usr/local/bin/docker-entrypoint.sh "$@"
|