mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2024-11-23 13:03:28 +01:00
69 lines
1.8 KiB
Plaintext
Executable File
69 lines
1.8 KiB
Plaintext
Executable File
#!/command/with-contenv bash
|
|
# shellcheck shell=bash
|
|
|
|
await_database() {
|
|
# Settings
|
|
local interval="1"
|
|
local status
|
|
|
|
# For loop
|
|
for i in {1..30}
|
|
do
|
|
# Check if database is reachable
|
|
status="$(wp core is-installed 2>&1)"
|
|
|
|
# Check if status contains database connection (partial match)
|
|
if echo "${status}" | grep -q "Error establishing"; then
|
|
echo "Database is not reachable, retrying in ${interval} seconds [${i}/30]"
|
|
sleep "${interval}"
|
|
continue
|
|
fi
|
|
|
|
return 0
|
|
done
|
|
}
|
|
|
|
# init-install-wordpress main
|
|
main() {
|
|
# This will prepend service name to all output from here
|
|
exec > >(while read -r line; do echo "[init-install-wordpress] ${line}"; done) 2>&1
|
|
|
|
if [ "${WORDPRESS_INIT_ENABLE:-false}" = "false" ]; then
|
|
echo "WordPress init is disabled"
|
|
return 0
|
|
fi
|
|
|
|
# Check if WordPress is already installed
|
|
if wp core is-installed 2>&1; then
|
|
echo "WordPress is already installed"
|
|
return 0
|
|
fi
|
|
|
|
if ! await_database; then
|
|
echo "Error: Database is not reachable"
|
|
return 1
|
|
fi
|
|
|
|
source /usr/local/bin/load_secrets
|
|
|
|
s6-envdir /run/secrets_normalized wp core install \
|
|
--url="${WORDPRESS_INIT_SITE_URL:?}" \
|
|
--title="${WORDPRESS_INIT_SITE_TITLE:-WordPress}" \
|
|
--admin_user="${WORDPRESS_INIT_ADMIN_USER:?}" \
|
|
--admin_password="${WORDPRESS_INIT_ADMIN_PASSWORD:?}" \
|
|
--admin_email="${WORDPRESS_INIT_ADMIN_EMAIL:?}" \
|
|
--skip-email
|
|
|
|
sleep 0.5
|
|
|
|
# Check if WordPress is already installed
|
|
if wp core is-installed 2>&1; then
|
|
echo "WordPress installed successfully at ${WORDPRESS_INIT_SITE_URL}"
|
|
return 0
|
|
fi
|
|
|
|
echo "Error: WordPress installation failed"
|
|
return 1
|
|
}
|
|
main
|