#! /bin/sh -e

dpkg --assert-support-predepends

LIBDIR=/usr/share
OLDLIBDIR=/usr/lib/kbd

if [ -f /etc/default/console ] 
then
    # Removing obsolete configuration file /etc/default/console
    rm -f /etc/default/console
fi
if [ -f /etc/rc.boot/*console  -o -L /etc/rc.boot/*console ]
then
    #  Removing obsolete boot file script /etc/rc.boot
    rm -f /etc/rc.boot/*console
fi
if [ -f /etc/init.d/console ]
then
    #  Removing obsolete init script from /etc/init.d
    rm -f /etc/init.d/*console
fi

if [ -f /etc/rc.boot/0kbd ]
then
    # Removing obsolete boot script.
    rm -f /etc/rc.boot/0kbd
fi

# Remove obsolete /usr/lib/kbd directory ( kbd now use /usr/share )
if [ -d ${OLDLIBDIR} ]
then
    echo Moving any local data files for kbd from ${OLDLIBDIR}/ to /usr/local/share/ ...
    for d in keytables consolefonts consoletrans videomodes; do
	# if the dir exists and is not a link (into /usr/share)
	if [ -d ${OLDLIBDIR}/${d} -a ! -L ${OLDLIBDIR}/${d} ]
	then
	    # maybe create local dir
	    test -d /usr/local/share/${d} || mkdir -p /usr/local/share/${d}
	    mv ${OLDLIBDIR}/${d}/* /usr/local/share/${d}/ 2>/dev/null || true
	    rm -rf ${OLDLIBDIR}/${d}
	fi
	# remove an eventual symlink
	rm -f ${OLDLIBDIR}/${d}
    done
    # try to remove the old dir, but be nice when not empty
    rmdir ${OLDLIBDIR} 2>/dev/null || \
	echo -e "WARNING: ${OLDLIBDIR}/ not removed - other files there ?\nCheck this and remove it by hand."
fi

# Rename old local keymaps dir if any
if [ -d /usr/local/share/keytables ]
then
    mv /usr/local/share/keytables /usr/local/share/keymaps
fi

# turn around dpkg bug about symlink<->dir confusion on upgrade
if [ -d /usr/doc/kbd/ ]
then
    rm -rf /usr/doc/kbd/
fi



exit 0
