#!/bin/sh
## ----------------------------------------------------------------------
## debian/postinst : postinstallation script for sgml-base
## ----------------------------------------------------------------------

## ----------------------------------------------------------------------
set -e

## ----------------------------------------------------------------------
if [ "$1" = "configure" ]
then

    ## ------------------------------------------------------------------
    ## clean up /usr/lib/sgml
    if [ -d /usr/lib/sgml ]
    then

	## --------------------------------------------------------------
	## remove symlink to /etc/sgml/catalog
	rm -f /usr/lib/sgml/catalog

        ## --------------------------------------------------------------
	## move transitional SGML catalog to /etc/sgml
	TRANSCAT=transitional.cat
	if [ -f /usr/lib/sgml/${TRANSCAT} ]
	then
	    mv -f /usr/lib/sgml/${TRANSCAT} /etc/sgml/${TRANSCAT}
	    if [ -f /usr/lib/sgml/${TRANSCAT}.old ]
	    then
		mv -f /usr/lib/sgml/${TRANSCAT}.old /etc/sgml/${TRANSCAT}.old
	    fi
	fi

        ## --------------------------------------------------------------
        ## remove /usr/lib/sgml
	cd /usr/lib
	rmdir --ignore-fail-on-non-empty sgml
	cd - >/dev/null

    fi

    ## ------------------------------------------------------------------
    ## evolve legacy /etc/sgml.catalog
    OCATALOG=/etc/sgml.catalog
    if [ -f ${OCATALOG} ]
    then
	TRANSCAT=/etc/sgml/transitional.cat
	if [ -f ${TRANSCAT} ]
	then
	    cp ${TRANSCAT} ${TRANSCAT}.old
	else
	    cp /usr/share/sgml-base/transitional.cat ${TRANSCAT}
	fi
	sed -e '1,10d' <${OCATALOG} >>${TRANSCAT}
	rm -f ${OCATALOG}
	if [ -f ${OCATALOG}.old ]
	then
	    sed -e '1,10d' <${OCATALOG}.old >>${TRANSCAT}.old
	    rm -f ${OCATALOG}.old
	fi
    fi

    ## ------------------------------------------------------------------
    update-catalog --quiet --update-super
    ln -sf /var/lib/sgml-base/supercatalog /etc/sgml/catalog
fi
if [ "$1" = "triggered" ]
then
    update-catalog --quiet --update-super
fi

## ---------------------------------------------------------------------- 
## automatically generated debhelper commands
# Automatically added by dh_usrlocal/13.9.1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ]; then
(
	default_mode=0755
	default_user=root
	default_group=root
	if [ -e /etc/staff-group-for-usr-local ]; then
		default_mode=02775
		default_group=staff
	fi
	while read line; do
		set -- $line
		dir="$1"; mode="$2"; user="$3"; group="$4"
		if [ "$mode" = "default" ]; then
			mode="$default_mode"
			user="$default_user"
			group="$default_group"
		fi
		if [ ! -e "$dir" ]; then
			if mkdir "$dir" 2>/dev/null; then
				if chown "$user":"$group" "$dir" ; then
					chmod "$mode" "$dir" || true
				fi
			fi
		fi
	done
) << DATA
/usr/local/share default
/usr/local/share/sgml default
/usr/local/share/sgml/declaration default
/usr/local/share/sgml/dtd default
/usr/local/share/sgml/entities default
/usr/local/share/sgml/misc default
/usr/local/share/sgml/stylesheet default
DATA
fi
# End automatically added section


exit 0

## ----------------------------------------------------------------------
