2020-03-29 01:42:21 +01:00
|
|
|
#!/usr/bin/with-contenv bash
|
2020-06-17 01:37:45 +02:00
|
|
|
DISABLE_WP_UPDATES="${ENFORCE_DISABLE_WP_UPDATES:-true}"
|
|
|
|
|
2020-03-29 01:46:30 +01:00
|
|
|
# Designed to replace original, overcomplicated entrypoint script from official wordpress docker repository
|
|
|
|
# Why not use already available tools instead?!
|
|
|
|
|
2021-03-19 19:34:19 +01:00
|
|
|
# Removes trailing zero if found
|
|
|
|
# This is required due to inconsistencies between WodPress docker image versioning and wp-cli core download
|
|
|
|
# If patch version is 0, it is not considered by wp-cli.
|
2022-07-25 23:51:18 +02:00
|
|
|
WP_VERSION=$(echo "${WP_VERSION}" | sed --expression='s/.0$//g');
|
2021-03-19 19:34:19 +01:00
|
|
|
|
2021-02-09 20:38:03 +01:00
|
|
|
function disableUpdatesPatch() {
|
|
|
|
if [ "${DISABLE_WP_UPDATES}" != "false" ]; then
|
|
|
|
echo "> Disabling WordPress updates..."
|
2021-09-27 03:29:55 +02:00
|
|
|
patch /var/www/html/wp-admin/update-core.php </etc/wp-mods/wp-admin-update-core.patch
|
2022-01-21 20:11:38 +01:00
|
|
|
echo "> Making the patched file read-only..."
|
|
|
|
chmod 0440 /var/www/html/wp-admin/update-core.php
|
2021-02-09 20:38:03 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteWordPress() {
|
|
|
|
echo "> Deleting WordPress installation (core files)"
|
|
|
|
|
|
|
|
# Instead of one-line find, we're taking a bit conservative approach and separating file and directory removal
|
|
|
|
# This is to ensure that this script never runs on unintended set of files as it's data loss risk
|
|
|
|
rm -rf "/var/www/${WEB_ROOT}/"{wp-includes,wp-admin}
|
2021-02-09 21:13:14 +01:00
|
|
|
rm -rf "/var/www/${WEB_ROOT}/"{.htaccess,index.php,license.txt,readme.html,wp-activate.php,wp-blog-header.php,wp-comments-post.php,wp-config-sample.php.php,wp-cron.php,wp-links-opml.php,wp-load.php,wp-login.php,wp-mail.php,wp-settings.php,wp-signup.php,wp-trackback.php,xmlrpc.php}
|
2020-03-29 01:42:21 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 01:37:45 +02:00
|
|
|
echo "> Verifying 'WordPress ${WP_VERSION}' installation..."
|
2021-02-09 20:38:03 +01:00
|
|
|
WP_INSTALLED_VERSION="$(wp core version)"
|
|
|
|
|
|
|
|
if [ -z "${WP_INSTALLED_VERSION}" ]; then
|
|
|
|
echo "> WordPress is not present"
|
2020-06-17 01:37:45 +02:00
|
|
|
echo "> Downloading 'WordPress ${WP_VERSION}'..."
|
2021-02-09 20:38:03 +01:00
|
|
|
deleteWordPress
|
2020-03-29 01:42:21 +01:00
|
|
|
wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}"
|
2021-02-09 20:38:03 +01:00
|
|
|
disableUpdatesPatch
|
|
|
|
elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then
|
|
|
|
echo "> WordPress version mismatch"
|
|
|
|
echo "> Expected version: ${WP_VERSION}"
|
|
|
|
echo "> Detected version: ${WP_INSTALLED_VERSION}"
|
|
|
|
echo "> Scraping current files"
|
|
|
|
deleteWordPress
|
|
|
|
echo "> Downloading WordPress version '${WP_VERSION}'..."
|
|
|
|
wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}"
|
|
|
|
disableUpdatesPatch
|
|
|
|
else
|
|
|
|
echo "> Identified 'WordPress ${WP_VERSION}'"
|
|
|
|
fi
|