You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
docker_dokuwiki/docker-startup.sh

68 lines
2.4 KiB

#!/bin/bash
set -eu
set -o pipefail
# Updating DokuWiki may need to change files in directories which we hold in
# volumes, e.g. `data` or `conf`. Therefore, we need to make sure these files
# are there when the container is started, not only when it is created. We do
# this by keeping track which version we last installed and update as necessary,
# or fully populate these folders if this is the first run.
dokudir=/dokuwiki
verfile=.last-version
if [ ! -d "$dokudir" ]; then
echo "DokuWiki does not appear to be installed correctly at: $dokudir." >&2
exit 1
fi
# Unpack a temporary copy
tmpdir=/tmp/dokuwiki
mkdir "$tmpdir"
tar -zxf /dokuwiki.tgz -C "$tmpdir" --strip-components 1
containerver="$(date -f <(awk '{print $1}' "$tmpdir/VERSION" | tr -d '[:alpha:]') +%s)"
# Check for downgrade/overwrite parameters
if [ "$1" = 'downgrade' ]; then downgrade=1; else downgrade=0; fi
if [ "$1" = 'overwrite' ]; then overwrite=1; else overwrite=0; fi
if [ "$1" = 'run' ] || [ "$1" = 'downgrade' ] || [ "$1" = 'overwrite' ]; then
# Check each volume directory in turn
for d in conf data lib/plugins lib/tpl; do
if [ -f "$dokudir/$d/$verfile" ]; then
volumever="$(date -f <(awk '{print $1}' "$dokudir/$d/$verfile" | tr -d '[:alpha:]') +%s)"
else
volumever=0
fi
if [ "$volumever" -eq "$containerver" ] && [ ! "$overwrite" -eq 1 ]; then
# Do nothing for equal versions
continue
elif [ "$volumever" -lt "$containerver" ] || [ "$downgrade" -eq 1 ] || [ "$overwrite" -eq 1 ]; then
# Update if the container version is newer than the volume version
# Or if overridden using `downgrade`
echo "Migrating $d..."
cp -r "$tmpdir/$d/"* "$dokudir/$d/"
cp "$tmpdir/VERSION" "$dokudir/$d/$verfile"
elif [ "$volumever" -gt "$containerver" ]; then
# Otherwise print an error message and stop
cat >&2 <<EOM
This volume has perviously been used with a newer version of DokuWiki.
If you want to force a downgrade (at your own risk!), run the \`downgrade\` command:
docker run ... andreipoe/dokuwiki donwgrade
EOM
exit 2
fi
done
# Ensure persmissions are set correctly
chown -R www-data:www-data "$dokudir"
# Run the web server
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
else
# Handle custom commands otherwise
exec "$@"
fi