#
# This script fixes several problems with the iBCS2 package.
#

#
# The default language for SCO is english/us/ascii, but since we didn't
# have code to create a .ascii file, we didn't.  Create a link from the
# .ascii file to the .8859 file (it's not 100% correct, but it should do
# in a pinch).
#
if [ ! -h /usr/lib/lang/english/us/ascii ]
then
	ln -s ascii /usr/lib/lang/english/us/8859
fi

#
# /usr/lib/lang/C/C/C is the default lang file & should be linked to 
# /usr/lib/lang/english/us/ascii, but instead it got linked to usr/lib/....
# (no leading slash).  If it still exists as a link (ie. user hasn't already
# fixed it), remove it & re-link it.
#
if [ -h /usr/lib/lang/C/C/C ]
then
	rm -f /usr/lib/lang/C/C/C
	ln -s ../../english/us/ascii /usr/lib/lang/C/C/C
fi

#
# The SCO locales were called ascii instead of 8859 like they should be.
# The fix is to list each ascii directory (except english/us),  pipe that
# to sed to strip off the pathname & move the ascii directory to 8859.
#

eval `find /usr/lib/lang -name us -prune -o -name ascii -print | \
sed 's/\(.*\)ascii/mvdir \1\/ascii \1\/8859;/'`

#
# Since there are no more .ascii files in the SCO directory, remove the
# Solaris equivalents.  The .8859 variants already exist so we don't need
# to create them.
#
rm -f /usr/lib/locale/*.ascii

#
# The catman directory appears as a link.  It should be a directory.
# If it still exists as a link (ie. user hasn't fixed it), then remove the
# link here then create the directory.
#
if [ -h /usr/catman ]
then
	rm -f /usr/catman
	mkdir /usr/catman
	chown root /usr/catman
	chgrp sys /usr/catman
	chmod 755 /usr/catman
fi

#
# The /usr/lbin directory wasn't on the FCS cut.  If the user attempted to
# install a package that tried to copy files to the usr/lbin directory,
# then /usr/lbin now exists as a file.  Check for this & remove it if
# necessary.  Pkgmap will create the directory if it doesn't exist.
#
if [ -f /usr/lbin ]
then
	rm -f /usr/lbin
fi

#
# Same story as /usr/lbin, only this is /usr/local/bin.
#
if [ -f /usr/local/bin ]
then
	rm -f /usr/local/bin
fi

#
# Same story as /usr/lbin, only this is /usr/local/lib.
#
if [ -f /usr/local/lib ]
then
	rm -f /usr/local/lib
fi


#
# Creation of /etc/default/lang was documented in LBN for FCS.  If it exists,
# the user must have created one so back it up so it doesn't get overwritten
# by the one in this patch.  Post install will restore the backed-up version.
#
if [ -f /etc/default/lang ]
then
	mv /etc/default/lang /etc/default/lang.orig
fi

#
# The permissions on the socksys device are wrong.
#
chmod 666 /devices/pseudo/socksys@0:socksys
