#!/bin/bash set -euo pipefail PLUGIN_DIR="$(cd "$(dirname "$0")/.." && pwd)" SCRIPT="$PLUGIN_DIR/scripts/setup/roundcube_repair_config.sh" TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT fail() { echo "FAIL: $*" >&2 exit 1 } mkdir -p "$TMP_DIR/mariadb/bin" "$TMP_DIR/roundcube" cat > "$TMP_DIR/roundcube/config.inc.php" <<'PHP' "$TMP_DIR/alt-mariadb.env" < "$TMP_DIR/alt-mysql.conf" < "$TMP_DIR/plugin-settings.conf" </dev/null grep -Fq "BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE" "$TMP_DIR/roundcube/config.inc.php" \ || fail "managed block missing" grep -Fq "127.0.0.1:4407/roundcube" "$TMP_DIR/roundcube/config.inc.php" \ || fail "alt endpoint not written" grep -Fq "BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE" "$TMP_DIR/custombuild/custom/roundcube/config.inc.php" \ || fail "managed block missing from CustomBuild Roundcube config" grep -Fq "127.0.0.1:4407/roundcube" "$TMP_DIR/custombuild/custom/roundcube/config.inc.php" \ || fail "alt endpoint not written to CustomBuild Roundcube config" grep -Fq "password=" "$TMP_DIR/alt-roundcube.conf" || fail "password file not created" ROUNDCUBE_SETTINGS_FILE="$TMP_DIR/plugin-settings.conf" bash "$SCRIPT" >/dev/null COUNT="$(grep -c "BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE" "$TMP_DIR/roundcube/config.inc.php")" [ "$COUNT" = "1" ] || fail "managed block is not idempotent" CUSTOM_COUNT="$(grep -c "BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE" "$TMP_DIR/custombuild/custom/roundcube/config.inc.php")" [ "$CUSTOM_COUNT" = "1" ] || fail "CustomBuild managed block is not idempotent" echo "roundcube_repair_config_test: OK"