Use indent of 4 spaces

This commit is contained in:
Aleksandar Puharic 2023-03-17 19:43:44 +01:00
parent a8f2aadab2
commit e2ed315ff2
Signed by: xZero707
GPG Key ID: 3CC53DCAA9C237BB
2 changed files with 100 additions and 100 deletions

@ -6,51 +6,51 @@
trap scriptExitHandler EXIT trap scriptExitHandler EXIT
function scriptExitHandler() { function scriptExitHandler() {
LAST_EXIT_CODE=$? LAST_EXIT_CODE=$?
if [ "${LAST_EXIT_CODE}" = "0" ]; then if [ "${LAST_EXIT_CODE}" = "0" ]; then
echo "> Script finished successfully" echo "> Script finished successfully"
exit "${LAST_EXIT_CODE}" exit "${LAST_EXIT_CODE}"
fi fi
echo "> Script finished with an error" echo "> Script finished with an error"
exit "${LAST_EXIT_CODE}" exit "${LAST_EXIT_CODE}"
} }
function reportUnhealthy() { function reportUnhealthy() {
echo "${1:?REASON is required}" > "/tmp/.wp-unhealthy" echo "${1:?REASON is required}" >"/tmp/.wp-unhealthy"
} }
# Main function # Main function
function main() { function main() {
# Removes trailing zero if found # Removes trailing zero if found
# This is required due to inconsistencies between WodPress docker image versioning and wp-cli core download # 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. # If patch version is 0, it is not considered by wp-cli.
WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g') WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g')
echo "> Verifying 'WordPress ${WP_VERSION}' installation..." echo "> Verifying 'WordPress ${WP_VERSION}' installation..."
WP_INSTALLED_VERSION="$(wp core version)" WP_INSTALLED_VERSION="$(wp core version)"
set -e set -e
rm -f "/tmp/.wp-unhealthy" rm -f "/tmp/.wp-unhealthy"
if [ -z "${WP_INSTALLED_VERSION}" ]; then if [ -z "${WP_INSTALLED_VERSION}" ]; then
echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..." echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..."
reportUnhealthy "WP_NOT_PRESENT" reportUnhealthy "WP_NOT_PRESENT"
return 0 return 0
elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then
echo "> WARNING! WordPress version mismatch" echo "> WARNING! WordPress version mismatch"
echo " Expected version: ${WP_VERSION}" echo " Expected version: ${WP_VERSION}"
echo " Detected version: ${WP_INSTALLED_VERSION}" echo " Detected version: ${WP_INSTALLED_VERSION}"
echo "> Seems like WordPress installation got updated outside image scope" 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 " - 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 " - 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}" echo " - Please make sure that you're running image: nlss/wordpress:${WP_VERSION}"
reportUnhealthy "WP_VERSION_MISMATCH" reportUnhealthy "WP_VERSION_MISMATCH"
return 0 return 0
else else
echo "> Identified 'WordPress ${WP_VERSION}'" echo "> Identified 'WordPress ${WP_VERSION}'"
fi fi
} }
main "${@}" main "${@}"

@ -4,91 +4,91 @@
trap scriptExitHandler EXIT trap scriptExitHandler EXIT
function scriptExitHandler() { function scriptExitHandler() {
LAST_EXIT_CODE=$? LAST_EXIT_CODE=$?
if [ "${LAST_EXIT_CODE}" = "0" ]; then if [ "${LAST_EXIT_CODE}" = "0" ]; then
echo "> Script finished successfully" echo "> Script finished successfully"
exit "${LAST_EXIT_CODE}" exit "${LAST_EXIT_CODE}"
fi fi
echo "> Script finished with an error" echo "> Script finished with an error"
exit "${LAST_EXIT_CODE}" exit "${LAST_EXIT_CODE}"
} }
# Check if plugin installed. This is very basic check that doesn't involve database # Check if plugin installed. This is very basic check that doesn't involve database
function isPluginInstalled() { function isPluginInstalled() {
if [ -d "${PLUGIN_PATH}" ] || [ -f "${PLUGIN_PATH}.php" ]; then if [ -d "${PLUGIN_PATH}" ] || [ -f "${PLUGIN_PATH}.php" ]; then
return 0 return 0
fi fi
return 1 return 1
} }
# Install plugin # Install plugin
function installPlugin() { function installPlugin() {
wp plugin install "${@}" >/dev/null 2>&1 wp plugin install "${@}" >/dev/null 2>&1
sleep 0.5 sleep 0.5
} }
# Main function # Main function
function main() { function main() {
PLUGIN_LIST="${WORDPRESS_PLUGIN_LIST:-}" PLUGIN_LIST="${WORDPRESS_PLUGIN_LIST:-}"
PLUGIN_STRICT_INSTALL="${WORDPRESS_PLUGIN_INSTALL_STRICT:-false}" PLUGIN_STRICT_INSTALL="${WORDPRESS_PLUGIN_INSTALL_STRICT:-false}"
WP_CONTENT_PATH="/var/www/html/wp-content" WP_CONTENT_PATH="/var/www/html/wp-content"
echo "> Automated WordPress Plugin Installer" echo "> Automated WordPress Plugin Installer"
if [ -z "${PLUGIN_LIST}" ]; then if [ -z "${PLUGIN_LIST}" ]; then
echo "> No plugins defined. Skipping installation." echo "> No plugins defined. Skipping installation."
return 0 return 0
fi
echo "> About to install defined plugins"
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
PLUGIN_PATH="${WP_CONTENT_PATH}/plugins/${PLUGIN[0]}"
if isPluginInstalled; then
echo "> Plugin '${PLUGIN[0]}' already installed and will be skipped."
continue
fi fi
WP_PLUGIN_INSTALL_ARGS="${PLUGIN[0]}" echo "> About to install defined plugins"
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
if [ -n "${PLUGIN[1]}" ]; then PLUGIN_PATH="${WP_CONTENT_PATH}/plugins/${PLUGIN[0]}"
WP_PLUGIN_INSTALL_ARGS="${WP_PLUGIN_INSTALL_ARGS} --version=${PLUGIN[1]}"
if isPluginInstalled; then
echo "> Plugin '${PLUGIN[0]}' already installed and will be skipped."
continue
fi
WP_PLUGIN_INSTALL_ARGS="${PLUGIN[0]}"
if [ -n "${PLUGIN[1]}" ]; then
WP_PLUGIN_INSTALL_ARGS="${WP_PLUGIN_INSTALL_ARGS} --version=${PLUGIN[1]}"
fi
echo "> Installing plugin '${PLUGIN[0]}' version '${PLUGIN[1]}'"
installPlugin "${WP_PLUGIN_INSTALL_ARGS}" &
done
echo "> Waiting for all plugins to install..."
wait
# Plugins are installed concurrently, so we need to verify if installed, separately
echo "> About to verify install of defined plugins"
FAILED_COUNT=0
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
PLUGIN_PATH="${WP_CONTENT_PATH}/plugins/${PLUGIN[0]}"
if isPluginInstalled; then
echo "> Plugin '${PLUGIN[0]}' installed"
continue
fi
((FAILED_COUNT = FAILED_COUNT + 1))
echo "> Warning: Plugin '${PLUGIN[0]}' failed to install"
done
echo "> Total of ${FAILED_COUNT} plugins failed to install"
if [ "${PLUGIN_STRICT_INSTALL}" = "true" ] && [ ${FAILED_COUNT} != "0" ]; then
echo "> WORDPRESS_PLUGIN_INSTALL_STRICT is set to true. Terminating with non-zero exit code"
return 1
fi fi
echo "> Installing plugin '${PLUGIN[0]}' version '${PLUGIN[1]}'"
installPlugin "${WP_PLUGIN_INSTALL_ARGS}" &
done
echo "> Waiting for all plugins to install..."
wait
# Plugins are installed concurrently, so we need to verify if installed, separately
echo "> About to verify install of defined plugins"
FAILED_COUNT=0
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
PLUGIN_PATH="${WP_CONTENT_PATH}/plugins/${PLUGIN[0]}"
if isPluginInstalled; then
echo "> Plugin '${PLUGIN[0]}' installed"
continue
fi
((FAILED_COUNT = FAILED_COUNT + 1))
echo "> Warning: Plugin '${PLUGIN[0]}' failed to install"
done
echo "> Total of ${FAILED_COUNT} plugins failed to install"
if [ "${PLUGIN_STRICT_INSTALL}" = "true" ] && [ ${FAILED_COUNT} != "0" ]; then
echo "> WORDPRESS_PLUGIN_INSTALL_STRICT is set to true. Terminating with non-zero exit code"
return 1
fi
} }
main "${@}" main "${@}"