#!/bin/sh
#ident	"@(#)pkg.ls:ls/preremove	1.3"

#
#  preremove file for Language Supplement.
#

#
LSVAR=/var/opt/ls
PKGMSG=ls.pkg
ICONV=/usr/lib/iconv
if [ -f $LSVAR/config ] ; then
	. $LSVAR/config > /dev/null 2>&1
fi

#  Reset the font to PC437 and reset the keyboard
#  to the default
#
#tput clear
pfmt -s nostd -g ${PKGMSG}:1 "Resetting console, keyboard, and display font to defaults...\n"

defadm locale LANG=C > /dev/null
if [ -x /usr/bin/pcfont ] ; then
	/usr/bin/pcfont > /dev/null 2> /dev/null
fi
defadm -d cofont COFONT
defadm coterm TERM="AT386"
defadm coterm-M TERM="AT386-M"

if [ -x /usr/bin/mapkey ] ; then
	/usr/bin/mapkey > /dev/null 2> /dev/null
fi
#
#  Reset the mapchan mappings
#
/usr/bin/mapchan -n > /dev/null 2> /dev/null

defadm -d keyboard KEYBOARD XKEYBOARD MAPCHAN NUMLOCK 2> /dev/null
defadm -d Xim XMODIFIERS XNLSPATH 2> /dev/null



#  Check to see if we need to restore an iconv_data file
#
if [ "$ICONV_SAVE" = "YES" ] ; then
	mv $LSVAR/iconv_data.ls $ICONV/iconv_data > /dev/null 2>&1
else
	removef ls $ICONV/iconv_data
	removef -f ls
	rm -f $ICONV/iconv_data
fi

if [ "$GRAPHICS" != "YES" ]; then
   exit 0
fi
    
#
# Remove the lines we inserted into the C-locale's ol_locale_def.
#

/usr/bin/ed /usr/X/lib/locale/C/ol_locale_def <<EOSS >/dev/null 2>&1
g/!Next line installed by ls/.,+1d
w
q
EOSS

#
# undo the fonts.alias file.  fonts.alias.gen works like a pkgadd build file.
#
if [ -r /usr/X/lib/fonts/misc/fonts.alias.gen ]
then
	sh /usr/X/lib/fonts/misc/fonts.alias.gen  >/tmp/fonts.alias
	mv /tmp/fonts.alias /usr/X/lib/fonts/misc/fonts.alias
fi

cat $LSVAR/loc.map | cut -f5 -d" " | xargs rm -rf


#  Exit with the correct code
exit 0
