Commit 2fa27243 authored by Andreas Dueren's avatar Andreas Dueren
Browse files

Fix homeserver domain configuration for existing configs

parent 89d86b3f
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ EOF
    
    if [ -n "${CLOUDRON_APP_DOMAIN:-}" ]; then
        echo "=> Configuring homeserver and appservice settings"
        # For whatsapp.matrix.as.ci -> matrix.as.ci and domain as.ci
        BASE_DOMAIN=$(echo "$CLOUDRON_APP_DOMAIN" | cut -d. -f2-)
        
        # Update homeserver configuration
@@ -103,9 +104,9 @@ EOF
    echo "   5. Authenticate with WhatsApp using QR code scanning"
else
    echo "=> Using existing configuration"
    # Fix logging configuration in existing config if needed
    # Fix configuration in existing config if needed
    if [ -f "$CONFIG_PATH" ]; then
        # Check if config has problematic logging path and fix it
        # Fix logging configuration
        if grep -q "filename.*logs/" "$CONFIG_PATH" 2>/dev/null || ! grep -q "/app/data/" "$CONFIG_PATH" 2>/dev/null; then
            echo "=> Fixing logging configuration in existing config"
            # Ensure logging goes to the writable /app/data directory
@@ -114,6 +115,18 @@ else
            yq -i ".logging.handlers.console.format = \"json\"" "$CONFIG_PATH" 2>/dev/null || true
            yq -i ".logging.level = \"info\"" "$CONFIG_PATH" 2>/dev/null || true
        fi
        
        # Fix homeserver domain configuration
        if [ -n "${CLOUDRON_APP_DOMAIN:-}" ]; then
            BASE_DOMAIN=$(echo "$CLOUDRON_APP_DOMAIN" | cut -d. -f2-)
            CURRENT_DOMAIN=$(yq -r ".homeserver.domain // empty" "$CONFIG_PATH" 2>/dev/null)
            if [ "$CURRENT_DOMAIN" != "$BASE_DOMAIN" ] || [ -z "$CURRENT_DOMAIN" ]; then
                echo "=> Fixing homeserver domain configuration"
                yq -i ".homeserver.address = \"https://matrix.$BASE_DOMAIN\"" "$CONFIG_PATH"
                yq -i ".homeserver.domain = \"$BASE_DOMAIN\"" "$CONFIG_PATH"
                yq -i ".appservice.address = \"https://$CLOUDRON_APP_DOMAIN\"" "$CONFIG_PATH"
            fi
        fi
    fi
fi