#!/bin/sh
# @(#)install_4.1.1patches	1.4 91/09/27 SMI
#
#         Copyright (C) 1991  Sun Microsystems, Inc
#                   All rights reserved.
#           Notice of copyright on this source code
#           product does not indicate publication.
# 
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by 
# the U.S. Government is subject to restrictions as set forth 
# in subparagraph (c)(1)(ii) of the Rights in Technical Data
# and Computer Software Clause at DFARS 252.227-7013 (Oct. 1988) 
# and FAR 52.227-19 (c) (June 1987).
#
# Sun Microsystems, Inc.
# 2550 Garcia Avenue
# Mountain View, California 94043
#
#  Install the .o's to fix the ld.so bug and the locale bug in 4.1.1
#########################################################################

PATH=:/usr/bin:/usr/ucb:/etc:/usr/etc
prog=$0
date_and_time=`date +%h%d.19%y.%T`


installer=`whoami`
if [ "$installer" != "root" ]; then
	echo
	echo "You must be root to run this script."
	echo
	echo "Please su to or login as root and try again."
	echo
	echo "The patches were not installed."
	echo
	exit 1
fi


# Patches only apply to sun4 and sun4c architectures.

ARCH=`arch -k`
if [ "$ARCH" != "sun4c" -a "$ARCH" != "sun4" ]; then
	echo
	echo "These patches are only applicable to sun4 and sun4c systems."
	echo
	echo "The patches were not installed."
	echo
	exit 0
fi


# Patches only apply to versions of SunOS 4.1.1.

os_version=`strings /vmunix | grep SunOS`
set $os_version
case "$3" in
4.1.1*)	;;
*)	echo
	echo "These patches are applicable only to versions of SunOS 4.1.1."
	echo
	echo "The patches were not installed."
	echo
	exit 0;;
esac


if [ ! -w /usr ]; then
	echo
	echo 'The patches could not be installed into /usr because it is'
	echo 'mounted read only.'
	echo
	echo 'See the OpenWindows version 3 Product Notes document and your'
	echo 'system administrator for details.'
	echo
	exit 1
fi


if [ -z "$OPENWINHOME" ]; then
	echo
	echo 'The patches could not be found because the environment variable'
	echo 'OPENWINHOME is undefined.'
	echo
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'that contains OpenWindows version 3 and rerun this script.'
	echo
	exit 1
fi


if [ ! -d $OPENWINHOME ]; then
	echo
	echo 'The patches installation failed because the environment variable'
	echo 'OPENWINHOME is set to'
	echo "\"$OPENWINHOME\","
	echo 'which is not a directory.'
	echo 'Please set OPENWINHOME to a directory that contains OpenWindows'
	echo 'version 3 and rerun this script.'
	echo
	exit 1
fi


PATCHDIR="${OPENWINHOME}/lib/OSpatches/sun4"

# Make sure the patches exist.

if [ ! -d $PATCHDIR ]; then
	echo
	echo 'The patches were not installed because the SunOS 4.1.1 patches'
	echo 'directory,'
	echo "\"$PATCHDIR\","
	echo 'was not found.'
	echo 'These patches are only available in OpenWindows version 3.'
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'containing this version.'
	echo
	exit 1
fi

if [ ! -f ${PATCHDIR}/ldd ]; then
	echo
	echo 'The file ldd was not found in the patch directory,'
	echo "\"$PATCHDIR\"."
	echo 'These patches are only available in OpenWindows version 3.'
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'containing this version.'
	echo
	exit 1
fi

if [ ! -f ${PATCHDIR}/ldconfig ]; then
	echo
	echo 'The file ldconfig was not found in the patch directory, '
	echo "\"$PATCHDIR\"."
	echo 'These patches are only available in OpenWindows version 3.'
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'containing this version.'
	echo
	exit 1
fi

if [ ! -f ${PATCHDIR}/ld.so ]; then
	echo
	echo 'The file ld.so was not found in the patch directory,'
	echo "\"$PATCHDIR\"."
	echo 'These patches are only available in OpenWindows version 3.'
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'containing this version.'
	echo
	exit 1
fi

if [ ! -f ${PATCHDIR}/C ]; then
	echo
	echo 'The file C was not found in the patch directory,'
	echo "\"$PATCHDIR\"."
	echo 'These patches are only available in OpenWindows version 3.'
	echo 'Please set the OPENWINHOME environment variable to a directory'
	echo 'containing this version.'
	echo
	exit 1
fi


# Install the patches.

mv /bin/ldd /bin/ldd.${date_and_time}
cp -p ${PATCHDIR}/ldd /bin/ldd

mv /usr/etc/ldconfig /usr/etc/ldconfig.${date_and_time}
cp -p ${PATCHDIR}/ldconfig /usr/etc/ldconfig

mv /usr/share/lib/locale/LC_CTYPE/C /usr/share/lib/locale/LC_CTYPE/C.${date_and_time}
cp -p ${PATCHDIR}/C /usr/share/lib/locale/LC_CTYPE/C

cp -p ${PATCHDIR}/ld.so /usr/lib/ld.so.NEW
(cd /usr/lib; mv ld.so ld.so.${date_and_time}; mv ld.so.NEW ld.so)

value=`date`
if [ -z "${value}" ]; then  # The installation of ld.so failed.
    	(cd /usr/lib; mv ld.so ld.so.NEW; mv ld.so.${date_and_time} ld.so)
    	echo
	echo 'The installation of the patched ld.so failed.'
    	echo 'The existing version was left in place.'
   	echo 'The patched versions of ldd, ldconfig, and C were installed.'
    	echo
	exit 1
fi

chown root.staff /bin/ldd /usr/etc/ldconfig /usr/lib/ld.so /usr/share/lib/locale/LC_CTYPE/C

chmod 755 /bin/ldd /usr/etc/ldconfig
chmod 555 /usr/lib/ld.so
chmod 644 /usr/share/lib/locale/LC_CTYPE/C

echo 
echo 'Patches installed successfully.'
echo

exit 0
