docker-dotclear/docker-entrypoint.sh

98 lines
3.8 KiB
Bash
Raw Normal View History

2024-11-02 13:47:50 +00:00
#!/bin/sh
2024-11-12 22:45:50 +00:00
# docker-dotclear:*
2024-11-11 16:56:16 +00:00
# Container starting script
2024-11-02 13:47:50 +00:00
set -e
2024-11-11 16:56:16 +00:00
# Read image version
2024-11-24 19:47:38 +00:00
if [ "$CNL_DOTCLEAR" == "stable" ]; then
# stable = x.xx.x => x.xx.x
export COMPARE_HAYSTACK="s/^\s*\"release_version\":\s*\"\(.*\)\",/\1/p"
else
# testing : x.xx.x-pxxxxxxxx.xxxx, unstable : x.xx.x-dev-rxxxxxxxx.xxxx => xxxxxxxx.xxxx.0
export COMPARE_HAYSTACK="s/^\s*\"release_version\":\s*\"\(.*\)\(-p\|-r\)\(.*\)\",/\3.0/p"
fi
export COMPARE_IMAGE=$(sed -n "${COMPARE_HAYSTACK}" /usr/src/dotclear/release.json)
export VERSION_IMAGE=$(sed -n "s/^\s*\"release_version\":\s*\"\(.*\)\",/\1/p" /usr/src/dotclear/release.json)
2024-11-11 16:56:16 +00:00
# Simple versions comparison function that fits all releases
function version { echo "$@" | awk -F. '{ printf("%d%04d%03d\n", $1,$2,$3); }'; }
2024-11-11 16:56:16 +00:00
2024-11-23 17:28:07 +00:00
# Update Docker structure
echo >&2 "Updating Docker structure..."
2024-11-25 20:16:01 +00:00
mkdir -p /var/www/dotclear/app \
/var/www/dotclear/blogs \
2024-11-30 13:16:33 +00:00
/var/www/dotclear/blogs/default \
2024-11-25 20:16:01 +00:00
/var/www/dotclear/cache \
/var/www/dotclear/plugins \
/var/www/dotclear/servers \
/var/www/dotclear/themes \
/var/www/dotclear/var
2024-11-30 13:16:33 +00:00
# Always replace image plugins
cp -rf /var/lib/dotclear/plugins/* /var/www/dotclear/plugins
# Copy nginx server conf only if not exists
cp -n /var/lib/dotclear/servers/subdomain.conf /var/www/dotclear/servers/
cp -n /var/lib/dotclear/servers/subfolder.conf /var/www/dotclear/servers/
2024-11-23 17:28:07 +00:00
2024-11-11 16:56:16 +00:00
# Check if Dotclear is already on system
2024-11-02 13:47:50 +00:00
if ! [ -e index.php -a -e src/App.php ]; then
# First installation
echo >&2 "Dotclear not found in $(pwd) - copying now..."
if [ "$(ls -A)" ]; then
echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!"
( set -x; ls -A; sleep 5 )
fi
echo >&2 "Copying Dotclear files..."
tar cf - --one-file-system -C /usr/src/dotclear . | tar xf -
echo >&2 "Complete! Dotclear has been successfully copied to $(pwd)"
else
# Check if Dotclear needs upgrade
2024-11-24 19:47:38 +00:00
COMPARE_VOLUME=$(sed -n "${COMPARE_HAYSTACK}" release.json)
VERSION_VOLUME=$(sed -n "s/^\s*\"release_version\":\s*\"\(.*\)\",/\1/p" release.json)
2024-11-24 20:01:35 +00:00
echo >&2 "Dotclear ${VERSION_VOLUME} found in $(pwd), checking upgrade..."
2024-11-24 19:47:38 +00:00
if [ $(version $COMPARE_IMAGE) -gt $(version $COMPARE_VOLUME) ]; then
echo >&2 "Upgrading Dotclear files from ${VERSION_VOLUME} to ${VERSION_IMAGE}, please wait..."
2024-11-02 13:47:50 +00:00
tar cf - --one-file-system -C /usr/src/dotclear . | tar xf -
2024-11-24 19:47:38 +00:00
echo >&2 "Complete! Dotclear files have been successfully upgraded to ${VERSION_IMAGE}"
2024-11-02 13:47:50 +00:00
else
2024-11-24 19:47:38 +00:00
echo >&2 "No need to upgrade Dotclear ${VERSION_IMAGE}"
2024-11-02 13:47:50 +00:00
fi
fi
2024-11-23 17:28:07 +00:00
# Update Docker structure
echo >&2 "Updating Dotclear common themes..."
2024-11-25 20:16:01 +00:00
cp -rf /var/www/dotclear/app/themes/* /var/www/dotclear/themes
2024-11-23 17:28:07 +00:00
# DEBUG mode for non stable releases
2024-11-16 12:43:18 +00:00
if [ "$CNL_DOTCLEAR" == "stable" ]; then
2024-11-12 20:12:07 +00:00
echo >&2 "Disabling Dotclear DEBUG mode"
sed -i -e "s/ \/\/\*== DC_DEBUG ==/ \/\*== DC_DEBUG ==/g" /var/www/dotclear/app/src/Config.php
2024-11-16 12:43:18 +00:00
else
echo >&2 "Enabling Dotclear DEBUG mode"
sed -i -e "s/ \/\*== DC_DEBUG ==/ \/\/\*== DC_DEBUG ==/g" /var/www/dotclear/app/src/Config.php
2024-11-12 20:12:07 +00:00
fi
2024-11-23 17:28:07 +00:00
# Various cleanup. Sorry not sorry.
## Remove template cache files
rm -Rf /var/www/dotclear/cache/*
## first version of docker-dotclear uses default.conf but next there are 2 config
rm -f /var/www/dotclear/servers/default.conf
2024-11-11 16:56:16 +00:00
# Fix www permissions
2024-11-02 13:47:50 +00:00
echo >&2 "Setting up permissions..."
2024-11-11 16:56:16 +00:00
chown -R www:www /var/www/dotclear
2024-12-12 21:41:31 +00:00
[ -e /var/www/dotclear/config.php ] && chmod 600 /var/www/dotclear/config.php
2024-12-12 23:44:41 +00:00
chmod 600 -R /var/www/dotclear/servers
2024-11-02 13:47:50 +00:00
2024-11-11 16:56:16 +00:00
# Print summary to docker logs
2024-11-24 20:01:35 +00:00
VERSION_INSTALLED=$(sed -n "s/^\s*\"release_version\":\s*\"\(.*\)\",/\1/p" release.json)
2024-12-12 21:42:07 +00:00
echo >&2 '┌──'
echo >&2 "│ Summary: "
echo >&2 "│ ◦ Alpine $(cat /etc/alpine-release)"
echo >&2 "│ ◦ Nginx $(nginx -v 2>&1 | sed 's/nginx version: nginx\///')"
echo >&2 "│ ◦ PHP $(php84 -r "echo PHP_VERSION;")"
echo >&2 "│ ◦ Dotclear ${VERSION_INSTALLED}"
echo >&2 '└──'
2024-11-02 13:47:50 +00:00
exec "$@"