#!/bin/bash
if [ -f /etc/libreoffice/registry/main.xcd ]; then
    config_file="/etc/libreoffice/registry/main.xcd"
    if [ -f /usr/lib/libreoffice/share/.registry/main.xcd ]; then
        cp -af /usr/lib/libreoffice/share/.registry/main.xcd /etc/libreoffice/registry/
	if awk '/<prop oor:name="UseSystemFileDialog"/ {flag=1} flag && /<\/prop>/ {flag=0} flag && /<value>/ {if ($0 ~ /true/) {print "true"; exit}}' "$config_file" | grep -q "true"; then
    	    /usr/bin/sed -i '/<prop oor:name="UseSystemFileDialog" oor:type="xs:boolean" oor:nillable="false">/,/<\/prop>/s/<value>true<\/value>/<value>false<\/value>/' /etc/libreoffice/registry/main.xcd
	fi
    fi
fi
