From 1fc95b184e1ac90901b703706d802afe0067e21f Mon Sep 17 00:00:00 2001
From: anima
Date: Fri, 23 Oct 2026 18:05:28 +0200
Subject: [PATCH] add update relevant replacements
---
init.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/init.sh b/init.sh
index 7f1b9b0..960c461 100644
--- a/init.sh
+++ b/init.sh
@@ -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