This commit is contained in:
@@ -3,6 +3,71 @@
|
||||
ICINGAWEB2_FILE_APACHE_DEFAULT=/etc/apache2/sites-available/000-default.conf
|
||||
ICINGAWEB2_FILE_APACHE_PORTS=/etc/apache2/ports.conf
|
||||
ICINGAWEB2_PORT=8080
|
||||
ICINGAWEB2_WEBROOT=/data/usr/icingaweb2
|
||||
ICINGAWEB2_WEBROOT_INIT=/data-init/usr/icingaweb2
|
||||
|
||||
## the webroot under /data is code from the image, config and state live in
|
||||
## /data/etc/icingaweb2 and the database. when the image ships another icingaweb2
|
||||
## version, the webroot has to follow, otherwise old assets, templates and modules
|
||||
## run against the new php library (e.g. missing css/icinga/csp-config-editor.less).
|
||||
## modules which are not part of the image stay untouched
|
||||
icingaweb2_update_webroot() {
|
||||
local version_old version_new module_path module
|
||||
|
||||
## nothing to compare without the webroot template from the image
|
||||
[ -d "$ICINGAWEB2_WEBROOT_INIT" ] || return 0
|
||||
|
||||
if [ ! -d "$ICINGAWEB2_WEBROOT" ]; then
|
||||
echo create icingaweb2 webroot from image
|
||||
mkdir -p "$ICINGAWEB2_WEBROOT"
|
||||
cp -a "$ICINGAWEB2_WEBROOT_INIT"/. "$ICINGAWEB2_WEBROOT"/
|
||||
chown -R 33:33 "$ICINGAWEB2_WEBROOT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
version_old="$(cat "$ICINGAWEB2_WEBROOT/VERSION" 2>/dev/null)"
|
||||
version_new="$(cat "$ICINGAWEB2_WEBROOT_INIT/VERSION" 2>/dev/null)"
|
||||
|
||||
## skip when the image carries no version to compare against
|
||||
[ -n "$version_new" ] || return 0
|
||||
|
||||
## skip when the webroot already runs the version from the image
|
||||
[ "$version_old" != "$version_new" ] || return 0
|
||||
|
||||
echo "replace icingaweb2 webroot: ${version_old:-unknown} -> $version_new"
|
||||
|
||||
## keep one backup of the replaced webroot for comparisons
|
||||
rm -rf "${ICINGAWEB2_WEBROOT}.bak"
|
||||
if ! cp -ax "$ICINGAWEB2_WEBROOT" "${ICINGAWEB2_WEBROOT}.bak"; then
|
||||
echo "backup of $ICINGAWEB2_WEBROOT failed, keeping the current webroot" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
## replace the modules shipped by the image, self installed ones are kept
|
||||
for module_path in "$ICINGAWEB2_WEBROOT_INIT"/modules/*/; do
|
||||
[ -d "$module_path" ] || continue
|
||||
module="$(basename "$module_path")"
|
||||
echo "replace module $module"
|
||||
rm -rf "$ICINGAWEB2_WEBROOT/modules/$module"
|
||||
done
|
||||
|
||||
## VERSION is the marker of this replacement, so it is replaced too
|
||||
rm -rf "$ICINGAWEB2_WEBROOT"/application \
|
||||
"$ICINGAWEB2_WEBROOT"/public \
|
||||
"$ICINGAWEB2_WEBROOT"/schema \
|
||||
"$ICINGAWEB2_WEBROOT"/doc \
|
||||
"$ICINGAWEB2_WEBROOT"/VERSION
|
||||
cp -a "$ICINGAWEB2_WEBROOT_INIT"/. "$ICINGAWEB2_WEBROOT"/
|
||||
|
||||
chown -R 33:33 "$ICINGAWEB2_WEBROOT"
|
||||
|
||||
for module_path in "$ICINGAWEB2_WEBROOT"/modules/*/; do
|
||||
[ -d "$module_path" ] || continue
|
||||
module="$(basename "$module_path")"
|
||||
[ -d "$ICINGAWEB2_WEBROOT_INIT/modules/$module" ] \
|
||||
|| echo "keep module $module (not part of the image)"
|
||||
done
|
||||
}
|
||||
|
||||
## init icinga config files if need
|
||||
if [ -z "$(ls -A /data)" ]; then
|
||||
@@ -32,6 +97,11 @@ if [ -z "$(ls -A /data)" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
## follow the icingaweb2 version of the image, also when /data is already populated
|
||||
if ! icingaweb2_update_webroot; then
|
||||
echo "warning: icingaweb2 webroot does not match the image version" >&2
|
||||
fi
|
||||
|
||||
## apache setup
|
||||
if [ ! -z "$ICINGAWEB2_PORT" ]; then
|
||||
echo set icingaweb2 apache ports
|
||||
|
||||
Reference in New Issue
Block a user