#!/command/with-contenv bash # shellcheck shell=bash # Designed to replace original, overcomplicated entrypoint script from official wordpress docker repository # Why not use already available tools instead?! # Register exit handler trap scriptExitHandler EXIT function scriptExitHandler() { local lastExitCode=$? if [ "${lastExitCode}" = "0" ]; then echo "Script finished successfully" exit "${lastExitCode}" fi echo "Script finished with an error" exit "${lastExitCode}" } function reportUnhealthy() { echo "${1:?REASON is required}" >"/tmp/.wp-unhealthy" } # init-verify-wordpress main function main() { exec > >(while read -r line; do echo "[init-verify-wordpress] ${line}"; done) 2>&1 local wpCurrentVersion local wpInstalledVersion # 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. wpCurrentVersion=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g') echo "Verifying 'WordPress ${wpCurrentVersion}' installation..." wpInstalledVersion="$(wp core version)" set -e rm -f "/tmp/.wp-unhealthy" if [ -z "${wpInstalledVersion}" ]; then echo "Error: WordPress installation does not seem to be present or valid. Continuing anyway..." reportUnhealthy "WP_NOT_PRESENT" return 0 elif [ "${wpInstalledVersion}" != "${wpCurrentVersion}" ]; then echo "WARNING! WordPress version mismatch" echo " Expected version: ${wpCurrentVersion}" echo " Detected version: ${wpInstalledVersion}" echo "Seems like WordPress installation got updated outside image scope" echo " - This is dangerous as changes will not persist when container is recreated which might lead to inconsistencies between installation and the database." echo " - You should assume that recreating the container will render the website inoperable." echo " - Please make sure that you're running image: nlss/wordpress:${wpCurrentVersion}" reportUnhealthy "WP_VERSION_MISMATCH" return 0 fi echo "Identified 'WordPress ${wpCurrentVersion}'" } main "${@}"