2020-04-07 18:09:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-04-02 13:41:06 +00:00
|
|
|
set -eu
|
|
|
|
|
2022-04-01 13:27:47 +00:00
|
|
|
# If WordPress is installed and the page "ready" exists, we bail the initialization.
|
|
|
|
if [ $(wp --allow-root core is-installed) ] && [ $(wp --allow-root post exists $(wp --allow-root post list --format=ids --post_name=ready)) ];
|
2020-04-02 13:41:06 +00:00
|
|
|
then
|
|
|
|
echo "The environment has already been initialized."
|
|
|
|
exit 0
|
2022-04-01 13:28:19 +00:00
|
|
|
else
|
|
|
|
echo "Initializing the environment..."
|
2020-04-02 13:41:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
chown xfs:xfs /var/www/html/wp-content
|
|
|
|
chown xfs:xfs /var/www/html/wp-content/plugins
|
|
|
|
|
|
|
|
## switch user
|
|
|
|
if [ $UID -eq 0 ]; then
|
|
|
|
user=xfs
|
|
|
|
dir=/var/www/html
|
|
|
|
cd "$dir"
|
|
|
|
exec su -s /bin/bash "$user" "$0" -- "$@"
|
|
|
|
# nothing will be executed beyond that line,
|
|
|
|
# because exec replaces running process with the new one
|
|
|
|
fi
|
|
|
|
|
|
|
|
declare -p WORDPRESS_PORT
|
|
|
|
[[ "${WORDPRESS_PORT}" == 80 ]] && \
|
|
|
|
URL="http://localhost" || \
|
|
|
|
URL="http://localhost:${WORDPRESS_PORT}"
|
|
|
|
|
2022-04-01 13:28:19 +00:00
|
|
|
declare -p WORDPRESS_TITLE >/dev/null
|
|
|
|
declare -p WORDPRESS_LOGIN >/dev/null
|
|
|
|
declare -p WORDPRESS_PASSWORD >/dev/null
|
|
|
|
declare -p WORDPRESS_EMAIL >/dev/null
|
|
|
|
echo "Installing WordPress..."
|
|
|
|
wp core install \
|
|
|
|
--url=${URL} \
|
|
|
|
--title="$WORDPRESS_TITLE" \
|
|
|
|
--admin_user=${WORDPRESS_LOGIN} \
|
|
|
|
--admin_password=${WORDPRESS_PASSWORD} \
|
|
|
|
--admin_email=${WORDPRESS_EMAIL} \
|
|
|
|
--skip-email
|
2020-04-02 13:41:06 +00:00
|
|
|
|
|
|
|
## Check for an initialization script.
|
|
|
|
declare -r INIT_SCRIPT=$(command -v initialize.sh)
|
|
|
|
|
|
|
|
if [[ -x ${INIT_SCRIPT} ]]; then
|
|
|
|
. "$INIT_SCRIPT"
|
|
|
|
fi
|
|
|
|
|
|
|
|
declare -r CURRENT_DOMAIN=$(wp option get siteurl)
|
|
|
|
|
|
|
|
if ! [[ ${CURRENT_DOMAIN} == ${URL} ]]; then
|
|
|
|
echo "Replacing ${CURRENT_DOMAIN} with ${URL} in database..."
|
|
|
|
wp search-replace ${CURRENT_DOMAIN} ${URL}
|
|
|
|
fi
|
|
|
|
|
2022-04-01 13:28:19 +00:00
|
|
|
wp post create \
|
|
|
|
--url=${URL} \
|
|
|
|
--post_type=page \
|
|
|
|
--post_status=publish \
|
|
|
|
--post_title='Ready' \
|
|
|
|
--post_content='E2E-tests.'
|
2020-06-16 15:29:43 +00:00
|
|
|
|
2020-04-02 13:41:06 +00:00
|
|
|
echo "Visit $(wp option get siteurl)"
|