From 8b388ae1163fe4e0423542e3c5e847a3f9b0937e Mon Sep 17 00:00:00 2001 From: xZero707 Date: Tue, 26 Jul 2022 21:24:26 +0200 Subject: [PATCH] Cleanup the code and use strict environment variables --- rootfs/etc/cont-init.d/10-init-wordpress | 64 ++++++++++++++---------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/rootfs/etc/cont-init.d/10-init-wordpress b/rootfs/etc/cont-init.d/10-init-wordpress index 43540b2..fa9304e 100644 --- a/rootfs/etc/cont-init.d/10-init-wordpress +++ b/rootfs/etc/cont-init.d/10-init-wordpress @@ -1,15 +1,10 @@ #!/usr/bin/with-contenv bash -DISABLE_WP_UPDATES="${ENFORCE_DISABLE_WP_UPDATES:-true}" - # Designed to replace original, overcomplicated entrypoint script from official wordpress docker repository # Why not use already available tools instead?! -# 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. -WP_VERSION=$(echo "${WP_VERSION}" | sed --expression='s/.0$//g'); - +# Applies patch for making WordPress updates impossible function disableUpdatesPatch() { + DISABLE_WP_UPDATES="${ENFORCE_DISABLE_WP_UPDATES:-true}" if [ "${DISABLE_WP_UPDATES}" != "false" ]; then echo "> Disabling WordPress updates..." patch /var/www/html/wp-admin/update-core.php Deleting WordPress installation (core files)" @@ -27,24 +23,38 @@ function deleteWordPress() { 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} } -echo "> Verifying 'WordPress ${WP_VERSION}' installation..." -WP_INSTALLED_VERSION="$(wp core version)" +# Main function +function main() { + # 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. + WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g') + WP_LOCALE="${WP_LOCALE:?}" -if [ -z "${WP_INSTALLED_VERSION}" ]; then - echo "> WordPress is not present" - echo "> Downloading 'WordPress ${WP_VERSION}'..." - deleteWordPress - wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}" - 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 + echo "> Verifying 'WordPress ${WP_VERSION}' installation..." + WP_INSTALLED_VERSION="$(wp core version)" + + set -e + + if [ -z "${WP_INSTALLED_VERSION}" ]; then + echo "> WordPress is not present" + echo "> Downloading 'WordPress ${WP_VERSION}'..." + deleteWordPress + wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}" + 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 +} + +main "${@}" +exit $?