indy-wp/entrypoint.sh

55 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
# -----------------------------------------------------------------
# 1⃣ Generate wp-config.php if it does not exist (your original logic)
# -----------------------------------------------------------------
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
# -----------------------------------------------------------------
# 2⃣ Helper: does the DB already have WordPress tables?
# -----------------------------------------------------------------
db_is_empty() {
# `wp db check` returns 0 when tables exist, nonzero 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 "$@"