mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2024-11-23 15:22:29 +01:00
Use local variables
This commit is contained in:
parent
4cb7286fc4
commit
e6110e37f2
|
@ -1,9 +1,11 @@
|
||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# Install plugin
|
# Install plugin
|
||||||
installPlugin() {
|
installPlugin() {
|
||||||
ARCHIVE="$(wp-plugin download "${@}" 2>/dev/null)"
|
local pluginArchive
|
||||||
if [ -z "${ARCHIVE}" ]; then
|
pluginArchive="$(wp-plugin download "${@}" 2>/dev/null)"
|
||||||
|
if [ -z "${pluginArchive}" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -12,27 +14,30 @@ installPlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkInstalled() {
|
checkInstalled() {
|
||||||
FAILED_COUNT=0
|
local failedCount=0
|
||||||
|
local pluginSlug
|
||||||
|
local pluginExpr
|
||||||
|
local plugin
|
||||||
|
|
||||||
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
|
for pluginExpr in ${PLUGIN_LIST}; do
|
||||||
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
|
IFS=':' read -ra plugin <<<"${pluginExpr}"
|
||||||
|
|
||||||
PLUGIN_SLUG="${PLUGIN[0]}"
|
pluginSlug="${plugin[0]}"
|
||||||
|
|
||||||
if wp-plugin check "${PLUGIN_SLUG}"; then
|
if wp-plugin check "${pluginSlug}"; then
|
||||||
echo "Plugin '${PLUGIN_SLUG}' installed"
|
echo "Plugin '${pluginSlug}' installed"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
((FAILED_COUNT = FAILED_COUNT + 1))
|
((failedCount = failedCount + 1))
|
||||||
echo "Warning: Plugin '${PLUGIN_SLUG}' failed to install"
|
echo "Warning: Plugin '${pluginSlug}' failed to install"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "${FAILED_COUNT}" = "0" ]; then
|
if [ "${failedCount}" = "0" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Total of ${FAILED_COUNT} plugins failed to install"
|
echo "Total of ${failedCount} plugins failed to install"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +45,11 @@ checkInstalled() {
|
||||||
function taskInstallPlugins() {
|
function taskInstallPlugins() {
|
||||||
export WP_PLUGINS_PATH
|
export WP_PLUGINS_PATH
|
||||||
|
|
||||||
CONCURRENCY_LIMIT="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
|
local concurrencyLimit="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
|
||||||
|
local pluginSlug
|
||||||
|
local pluginVersion
|
||||||
|
local pluginExpr
|
||||||
|
local plugin
|
||||||
|
|
||||||
echo "Automated WordPress Plugins Installer"
|
echo "Automated WordPress Plugins Installer"
|
||||||
if [ -z "${PLUGIN_LIST}" ]; then
|
if [ -z "${PLUGIN_LIST}" ]; then
|
||||||
|
@ -49,30 +58,30 @@ function taskInstallPlugins() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "About to install defined plugins"
|
echo "About to install defined plugins"
|
||||||
for PLUGIN_EXPR in ${PLUGIN_LIST}; do
|
for pluginExpr in ${PLUGIN_LIST}; do
|
||||||
|
|
||||||
# Split plugin name and version
|
# Split plugin name and version
|
||||||
IFS=':' read -ra PLUGIN <<<"${PLUGIN_EXPR}"
|
IFS=':' read -ra plugin <<<"${pluginExpr}"
|
||||||
|
|
||||||
PLUGIN_SLUG="${PLUGIN[0]}"
|
pluginSlug="${plugin[0]}"
|
||||||
PLUGIN_VERSION="${PLUGIN[1]:-}"
|
pluginVersion="${plugin[1]:-}"
|
||||||
|
|
||||||
if wp-plugin check "${PLUGIN_SLUG}"; then
|
if wp-plugin check "${pluginSlug}"; then
|
||||||
echo "Plugin '${PLUGIN_SLUG}' already installed and will be skipped."
|
echo "Plugin '${pluginSlug}' already installed and will be skipped."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${PLUGIN_VERSION}" ]; then
|
if [ -n "${pluginVersion}" ]; then
|
||||||
echo "Installing plugin '${PLUGIN_SLUG}' version '${PLUGIN_VERSION}'"
|
echo "Installing plugin '${pluginSlug}' version '${pluginVersion}'"
|
||||||
installPlugin "${PLUGIN_SLUG}" "${PLUGIN_VERSION}" &
|
installPlugin "${pluginSlug}" "${pluginVersion}" &
|
||||||
else
|
else
|
||||||
echo "Installing plugin '${PLUGIN_SLUG}'"
|
echo "Installing plugin '${pluginSlug}'"
|
||||||
installPlugin "${PLUGIN_SLUG}" &
|
installPlugin "${pluginSlug}" &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run maximum of X plugin installs in parallel
|
# Run maximum of X plugin installs in parallel
|
||||||
while [ "$(jobs | wc -l)" -ge "${CONCURRENCY_LIMIT}" ]; do
|
while [ "$(jobs | wc -l)" -ge "${concurrencyLimit}" ]; do
|
||||||
echo " Waiting for batch of ${CONCURRENCY_LIMIT} plugins to install..."
|
echo " Waiting for batch of ${concurrencyLimit} plugins to install..."
|
||||||
wait
|
wait
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
@ -104,7 +113,6 @@ main() {
|
||||||
|
|
||||||
export WP_CONTENT_PATH
|
export WP_CONTENT_PATH
|
||||||
|
|
||||||
|
|
||||||
WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
|
WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
|
||||||
export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY
|
export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY
|
||||||
taskInstallPlugins "${@}" &
|
taskInstallPlugins "${@}" &
|
||||||
|
@ -115,4 +123,4 @@ main() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
main "${@}"
|
main "${@}"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# Designed to replace original, overcomplicated entrypoint script from official wordpress docker repository
|
# Designed to replace original, overcomplicated entrypoint script from official wordpress docker repository
|
||||||
# Why not use already available tools instead?!
|
# Why not use already available tools instead?!
|
||||||
|
|
||||||
|
@ -6,14 +8,14 @@
|
||||||
trap scriptExitHandler EXIT
|
trap scriptExitHandler EXIT
|
||||||
|
|
||||||
function scriptExitHandler() {
|
function scriptExitHandler() {
|
||||||
LAST_EXIT_CODE=$?
|
local lastExitCode=$?
|
||||||
if [ "${LAST_EXIT_CODE}" = "0" ]; then
|
if [ "${lastExitCode}" = "0" ]; then
|
||||||
echo "Script finished successfully"
|
echo "Script finished successfully"
|
||||||
exit "${LAST_EXIT_CODE}"
|
exit "${lastExitCode}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Script finished with an error"
|
echo "Script finished with an error"
|
||||||
exit "${LAST_EXIT_CODE}"
|
exit "${lastExitCode}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportUnhealthy() {
|
function reportUnhealthy() {
|
||||||
|
@ -25,35 +27,38 @@ function main() {
|
||||||
|
|
||||||
exec > >(while read line; do echo "[init-verify-wordpress] ${line}"; done) 2>&1
|
exec > >(while read line; do echo "[init-verify-wordpress] ${line}"; done) 2>&1
|
||||||
|
|
||||||
|
local wpCurrentVersion
|
||||||
|
local wpInstalledVersion
|
||||||
|
|
||||||
# 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')
|
wpCurrentVersion=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g')
|
||||||
|
|
||||||
echo "Verifying 'WordPress ${WP_VERSION}' installation..."
|
echo "Verifying 'WordPress ${wpCurrentVersion}' installation..."
|
||||||
WP_INSTALLED_VERSION="$(wp core version)"
|
wpInstalledVersion="$(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 "${wpInstalledVersion}" ]; 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 [ "${wpInstalledVersion}" != "${wpCurrentVersion}" ]; then
|
||||||
echo "WARNING! WordPress version mismatch"
|
echo "WARNING! WordPress version mismatch"
|
||||||
echo " Expected version: ${WP_VERSION}"
|
echo " Expected version: ${wpCurrentVersion}"
|
||||||
echo " Detected version: ${WP_INSTALLED_VERSION}"
|
echo " Detected version: ${wpInstalledVersion}"
|
||||||
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:${wpCurrentVersion}"
|
||||||
reportUnhealthy "WP_VERSION_MISMATCH"
|
reportUnhealthy "WP_VERSION_MISMATCH"
|
||||||
return 0
|
return 0
|
||||||
else
|
|
||||||
echo "Identified 'WordPress ${WP_VERSION}'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Identified 'WordPress ${wpCurrentVersion}'"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "${@}"
|
main "${@}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user