#! /bin/sh
# @(#)install_modules.sh	1.5 92/01/31 install_modules 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
#

#
# This is the OpenWindows modules install script.
#
# This script must be run as superuser
#

PATH="/bin:/usr/ucb:/usr/bin:/etc"
NOOBJ=0
export PATH

if [ "root" != `whoami` ]
then
	echo "Installation failed - must be run in super-user mode."
	exit 1
fi

if [ "" = "$OPENWINHOME" ]
then
	echo 'Installation failed because $OPENWINHOME is undefined.'
	echo 'Please set $OPENWINHOME and rerun this script.'
	exit 1
fi

if [ ! -d "$OPENWINHOME" ]
then
	echo 'Installation failed because $OPENWINHOME is set to'
	echo \""$OPENWINHOME"\" 'which is not a directory.'
	echo 'Please check $OPENWINHOME and rerun this script.'
	exit 1
fi

if [ ! -d "$OPENWINHOME/modules" ]
then
	echo 'Installation failed because the directory $OPENWINHOME/modules'
	echo 'does not exist.'
	echo 'Please check $OPENWINHOME/modules and rerun this script.'
	exit 1
fi

#if [ ! -d "/sys/`arch -k`/OBJ" ]
#then
#	echo 'Installation failed because the directory'
#	echo '/usr/sys/'`arch -k`'/OBJ' does not exist.'
#	echo 'Please check your SunOS installation and rerun this script.'
#	exit 1
#fi

if [ -d "/sys/`arch -k`/OBJ" -a ! -w "/sys/`arch -k`/OBJ" -a ! -f "/sys/`arch -k`/OBJ/evqmod-sun4c.o" ]
then
	echo 'install_module: /usr/sys/'`arch -k`'/OBJ is not writable.'
	echo 'If this machine mounts /usr from an NFS file server, you'
	echo 'must also run the OpenWindows installation script on the'
	echo 'NFS file server.  There is no need to re-run the installation'
	echo 'on this machine.'
	NOOBJ=1

# if OBJ is not writable, but "evqmod-sun4c.o" exists, we'll assume that
# install_openwin has already been run on the NFS server
else if [ -d "/sys/`arch -k`/OBJ" -a ! -w "/sys/`arch -k`/OBJ" -a -f "/sys/`arch -k`/OBJ/evqmod-sun4c.o" ]
	then
		NOOBJ=1
	fi
fi

if [ ! -d "/etc/openwin/modules" ]
then
	echo 'Creating directory /etc/openwin/modules.'
	mkdir -p /etc/openwin/modules
	chmod -R 755 /etc/openwin
fi

echo "*************** Installing Openwindow Driver Modules"

if [ $NOOBJ = 0 ]
then
# create OBJ directories if the do not exist
	for i in /export/exec/kvm/sun4*sunos*
	do
		ARCH=`echo $i | sed -e "s;/export/exec/kvm/;;" | awk -F. '{print $1}'`
		if [ ! -d $i/sys/$ARCH/OBJ ]
		then
			mkdir -p $i/sys/$ARCH/OBJ
		fi
	done

# copy all of the driver modules to the OBJ directories
# 'for' loop is to take care of heterogeneous servers
	for i in /export/exec/kvm/sun4*sunos*/sys/sun4*/OBJ
	do
    		echo -n .
    		cp $OPENWINHOME/modules/*.o $i
	done

	echo -n .
fi

cp $OPENWINHOME/modules/*load /etc/openwin/modules

echo
echo "*************** Done with Openwindows Driver Modules installation"

exit 0
