wordpress/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/run

65 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

#!/command/with-contenv bash
2024-05-17 01:52:44 +02:00
# shellcheck shell=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() {
2024-05-17 01:52:44 +02:00
local lastExitCode=$?
if [ "${lastExitCode}" = "0" ]; then
2024-05-17 01:37:37 +02:00
echo "Script finished successfully"
2024-05-17 01:52:44 +02:00
exit "${lastExitCode}"
2023-03-17 19:43:44 +01:00
fi
2022-07-26 21:33:28 +02:00
2024-05-17 01:37:37 +02:00
echo "Script finished with an error"
2024-05-17 01:52:44 +02:00
exit "${lastExitCode}"
2022-07-26 21:33:28 +02:00
}
function reportUnhealthy() {
2023-03-17 19:43:44 +01:00
echo "${1:?REASON is required}" >"/tmp/.wp-unhealthy"
}
2024-05-17 01:37:37 +02:00
# init-verify-wordpress main
function main() {
2024-05-17 01:37:37 +02:00
exec > >(while read -r line; do echo "[init-verify-wordpress] ${line}"; done) 2>&1
2024-05-17 01:37:37 +02:00
2024-05-17 01:52:44 +02:00
local wpCurrentVersion
local wpInstalledVersion
2023-03-17 19:43:44 +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.
2024-05-17 01:52:44 +02:00
wpCurrentVersion=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g')
2023-03-17 19:43:44 +01:00
2024-05-17 01:52:44 +02:00
echo "Verifying 'WordPress ${wpCurrentVersion}' installation..."
wpInstalledVersion="$(wp core version)"
2023-03-17 19:43:44 +01:00
set -e
rm -f "/tmp/.wp-unhealthy"
2024-05-17 01:52:44 +02:00
if [ -z "${wpInstalledVersion}" ]; then
2024-05-17 01:37:37 +02:00
echo "Error: WordPress installation does not seem to be present or valid. Continuing anyway..."
2023-03-17 19:43:44 +01:00
reportUnhealthy "WP_NOT_PRESENT"
return 0
2024-05-17 01:52:44 +02:00
elif [ "${wpInstalledVersion}" != "${wpCurrentVersion}" ]; then
2024-05-17 01:37:37 +02:00
echo "WARNING! WordPress version mismatch"
2024-05-17 01:52:44 +02:00
echo " Expected version: ${wpCurrentVersion}"
echo " Detected version: ${wpInstalledVersion}"
2024-05-17 01:37:37 +02:00
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."
2024-05-17 01:52:44 +02:00
echo " - Please make sure that you're running image: nlss/wordpress:${wpCurrentVersion}"
2023-03-17 19:43:44 +01:00
reportUnhealthy "WP_VERSION_MISMATCH"
return 0
fi
2024-05-17 01:52:44 +02:00
echo "Identified 'WordPress ${wpCurrentVersion}'"
}
main "${@}"