2020-03-29 01:42:21 +01:00
#!/usr/bin/with-contenv bash
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?!
2022-07-26 21:33:28 +02:00
# Register exit handler
trap scriptExitHandler EXIT
function scriptExitHandler() {
LAST_EXIT_CODE=$?
if [ "${LAST_EXIT_CODE}" = "0" ]; then
2022-07-26 21:34:35 +02:00
echo "> Script finished successfully"
2022-07-26 21:33:28 +02:00
exit "${LAST_EXIT_CODE}"
fi
echo "> Script finished with an error"
exit "${LAST_EXIT_CODE}"
}
2023-01-24 01:42:53 +01:00
function reportUnhealthy() {
echo "${1:?REASON is required}" > "/tmp/.wp-unhealthy"
}
2022-07-26 21:24:26 +02:00
# 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')
echo "> Verifying 'WordPress ${WP_VERSION}' installation..."
WP_INSTALLED_VERSION="$(wp core version)"
set -e
2023-01-24 01:42:53 +01:00
rm -f "/tmp/.wp-unhealthy"
2022-07-26 21:24:26 +02:00
if [ -z "${WP_INSTALLED_VERSION}" ]; then
2023-01-23 23:03:06 +01:00
echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..."
2023-01-24 01:42:53 +01:00
reportUnhealthy "WP_NOT_PRESENT"
2023-01-23 23:03:06 +01:00
return 0
2022-07-26 21:24:26 +02:00
elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then
2023-01-23 23:03:06 +01:00
echo "> WARNING! WordPress version mismatch"
echo " Expected version: ${WP_VERSION}"
echo " Detected version: ${WP_INSTALLED_VERSION}"
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:${WP_VERSION}"
2023-01-24 01:42:53 +01:00
reportUnhealthy "WP_VERSION_MISMATCH"
2023-01-23 23:03:06 +01:00
return 0
2022-07-26 21:24:26 +02:00
else
echo "> Identified 'WordPress ${WP_VERSION}'"
fi
}
main "${@}"
exit $?