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

127 lines
3.2 KiB
Plaintext
Raw Normal View History

#!/command/with-contenv bash
2024-05-17 01:52:44 +02:00
# shellcheck shell=bash
# Install plugin
installPlugin() {
2024-05-17 01:52:44 +02:00
local pluginArchive
pluginArchive="$(wp-plugin download "${@}" 2>/dev/null)"
if [ -z "${pluginArchive}" ]; then
return 1
2023-03-17 19:43:44 +01:00
fi
wp-plugin unpack "${@}"
return $?
}
checkInstalled() {
2024-05-17 01:52:44 +02:00
local failedCount=0
local pluginSlug
local pluginExpr
local plugin
2024-05-17 01:52:44 +02:00
for pluginExpr in ${PLUGIN_LIST}; do
IFS=':' read -ra plugin <<<"${pluginExpr}"
2024-05-17 01:52:44 +02:00
pluginSlug="${plugin[0]}"
2024-05-17 01:52:44 +02:00
if wp-plugin check "${pluginSlug}"; then
echo "Plugin '${pluginSlug}' installed"
continue
fi
2024-05-17 01:52:44 +02:00
((failedCount = failedCount + 1))
echo "Warning: Plugin '${pluginSlug}' failed to install"
done
2024-05-17 01:52:44 +02:00
if [ "${failedCount}" = "0" ]; then
return 0
fi
2024-05-17 01:52:44 +02:00
echo "Total of ${failedCount} plugins failed to install"
return 1
}
2021-02-09 21:27:12 +01:00
# Plugins installer
function taskInstallPlugins() {
export WP_PLUGINS_PATH
2024-05-17 01:52:44 +02:00
local concurrencyLimit="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
local pluginSlug
local pluginVersion
local pluginExpr
local plugin
2024-05-17 01:37:37 +02:00
echo "Automated WordPress Plugins Installer"
2023-03-17 19:43:44 +01:00
if [ -z "${PLUGIN_LIST}" ]; then
2024-05-17 01:37:37 +02:00
echo "No plugins defined. Skipping installation."
2023-03-17 19:43:44 +01:00
return 0
fi
2021-02-09 21:27:12 +01:00
2024-05-17 01:37:37 +02:00
echo "About to install defined plugins"
2024-05-17 01:52:44 +02:00
for pluginExpr in ${PLUGIN_LIST}; do
# Split plugin name and version
2024-05-17 01:52:44 +02:00
IFS=':' read -ra plugin <<<"${pluginExpr}"
2021-02-09 21:27:12 +01:00
2024-05-17 01:52:44 +02:00
pluginSlug="${plugin[0]}"
pluginVersion="${plugin[1]:-}"
2024-05-17 01:52:44 +02:00
if wp-plugin check "${pluginSlug}"; then
echo "Plugin '${pluginSlug}' already installed and will be skipped."
2023-03-17 19:43:44 +01:00
continue
fi
2024-05-17 01:52:44 +02:00
if [ -n "${pluginVersion}" ]; then
echo "Installing plugin '${pluginSlug}' version '${pluginVersion}'"
installPlugin "${pluginSlug}" "${pluginVersion}" &
else
2024-05-17 01:52:44 +02:00
echo "Installing plugin '${pluginSlug}'"
installPlugin "${pluginSlug}" &
2023-03-17 19:43:44 +01:00
fi
2021-02-15 01:17:40 +01:00
2023-03-17 21:14:26 +01:00
# Run maximum of X plugin installs in parallel
2024-05-17 01:52:44 +02:00
while [ "$(jobs | wc -l)" -ge "${concurrencyLimit}" ]; do
echo " Waiting for batch of ${concurrencyLimit} plugins to install..."
wait
done
2023-03-17 19:43:44 +01:00
done
2024-05-17 01:37:37 +02:00
echo "Waiting for all tasks to finish..."
2023-03-17 19:43:44 +01:00
wait
2023-03-17 19:43:44 +01:00
# Plugins are installed concurrently, so we need to verify if installed, separately
2024-05-17 01:37:37 +02:00
echo "About to verify install of defined plugins"
if ! checkInstalled; then
2024-05-17 01:37:37 +02:00
echo "Some plugins failed to install"
return 0
2023-03-17 19:43:44 +01:00
fi
2024-05-17 01:37:37 +02:00
echo "All plugins installed successfully"
return 0
2022-07-26 21:38:26 +02:00
}
2024-05-17 01:37:37 +02:00
# init-install-resources main
main() {
exec > >(while read -r line; do echo "[init-install-resources] ${line}"; done) 2>&1
2024-05-17 01:37:37 +02:00
PLUGIN_LIST="${WORDPRESS_PLUGIN_LIST:-}"
WP_CONTENT_PATH="/var/www/html/wp-content"
WP_PLUGINS_PATH="${WP_CONTENT_PATH}/plugins"
2024-05-17 01:37:37 +02:00
echo "Automated WordPress Resources Installer"
export WP_CONTENT_PATH
WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY
taskInstallPlugins "${@}" &
sleep 1
2024-05-17 01:37:37 +02:00
echo "Waiting for all tasks to complete"
wait
return 0
}
2024-05-17 01:52:44 +02:00
main "${@}"