#!/bin/sh
#
#ident "@(#)postinstall	1.7 15 Jul 1993 SMI"
#
# Copyright 1993 Sun Microsystems, Inc. All Rights Reserved
#
#  Postinstall script for package: <to be defined> 
#  

# Exit codes for installation scripts 
e_ok=0      
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above

# Trap interrupt
trap `exit $e_int` 15
#
# Who set the path ??? (security issue)
# PATH="/bin:/etc:/usr/sbin"

#
# For kernel package we just need to add_drv teh different modules
#	- Check first if its not already done, on /etc/name_to_major
#	- We don't run add_drv if the driver are already installed
#
# DRVS="oopi otpi oclt otcl otmr"		# List of drivers to install
DRVS="oopi otpi oclt otmr"		# List of drivers to install

NAME_DRV="/etc/name_to_major"

#
# *** 	the /usr/sbin/add_drv script uses BASEDIR variable to
#	acces /etc/name_to_major.
#	We should redifined this variable to be independant of
#	the value used by pkgadd
#
BASEDIR=/ ; export BASEDIR
#
# Checking for driver installation
#
echo "checking for drivers installation"
grep '^set[ \t]*kobj_map_space_len' /etc/system > /dev/null
if [ $? -ne 0 ] ; then
	echo "set kobj_map_space_len=2097152" >> /etc/system
	echo " "
	echo "WARNING :"
	echo "Your /etc/system file has been changed to support the OSI installation."
	echo "You MUST REBOOT your system and do the pkgadd again"
	echo " "
	exit $e_fatal
fi
#
# Drivers installation
#

echo "Installing the OSI drivers ..."

if [ ! -r "$NAME_DRV" ]; then
	echo "Cannot access $NAME_DRV"
	echo "Please contact your system administrator"
	exit $e_fatal
fi

for D in $DRVS ; do 
	if egrep "^$D" "$NAME_DRV" 2>&1 >/dev/null ; then
		echo "$D already define on this system"
	else
		# Create driver with proper permissions!
		echo "adding $D driver, permissions: 0666 root sys"
		/usr/sbin/add_drv -m '* 0666 root sys' $D
	 	if [ $? -ne 0 ]; then
			exit $e_fatal
	 	fi

	fi
done	
#
# Adding specific OSI stuff
#	- Creating  /dev/oopi0 and /dev/oopi1
# Should be done by the ddi_create_minor on the 
# Streams attach function
#

MAJOR=`grep oopi $NAME_DRV | awk '{ print $2 }'`
if [ ! -c /dev/oopi0 ]; then
	/etc/mknod /dev/oopi0 c $MAJOR 0 
fi
if [ ! -c /dev/oopi1 ]; then
	/etc/mknod /dev/oopi1 c $MAJOR 1 
fi

chmod 666 /dev/otpi /dev/oclt /dev/oopi

#
# Licensing
#

# @(#)postinstall_prod	1.6 11/19/92 Copyright 1993 SMI
# Copyright (c) 1993 Sun Microsystems, Inc.  All Rights Reserved.
# Sun considers its source code as an unpublished, proprietary trade
# secret, and it is available only under strict license provisions.
# This copyright notice is placed here only to protect Sun in the event
# the source is deemed a published work.
#
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
# 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 52.227-7013 and in similar clauses in the FAR and
# NASA FAR Supplement.
#
# Post-install template for unbundled products using FLEXlm
# Copies all licenses over from the standard directory - $licdir -

###########################################
# The following lines should be modified for use by individual products
###########################################
# Identifies the basename of the license file and license
# location file, before the ,loc or,lic are attached to it
# e.g., if license_file=featfile
# the license file will then be called featfile,lic

license_file=osistk8.0

# Identifies the path to the license once it is installed
# in the product, excluding the basedir and the license file name
# e.g., if dirloc=SUNWspro/lib, the license file would be placed in
# $BASEDIR/SUNWspro/lib

dirloc=/etc/opt/licenses

#
# Add (Osman.)
#
mkdir -p $dirloc 2>&1 >/dev/null

####################################################
# Subsequent lines should not be modified by individual products
#####################################################
licdir="/etc/opt/licenses"
licfile=${license_file}.lic
locfile=${license_file}.loc

if [ ! -d ${BASEDIR}/${dirloc} ]
then
	echo Cannot Access license location directory ${BASEDIR}/${dirloc}  - Exiting
	exit 1
fi

#
# Find new names for existing new license files in licdir
#
if [ -f  ${licdir}/${licfile}* ]
then 
	for infile in `ls ${licdir}/${licfile}*`
	do

		i=0
		notdone=0
		while [ $notdone -eq 0 ]
		do
			outputfile=$BASEDIR/$dirloc/$licfile,$i
			if [ ! -f $outputfile ]
			then
				notdone=1
			else
				i=`expr $i + 1`
			fi
		done
		
# Get the basename, just in case we don't know the formate of this name
		basefile=`basename ${infile}`
		cp ${licdir}/${basefile} $outputfile
		if [ $? -ne 0 ]
		then
			echo Exiting
			exit 1
		fi
		rm ${licdir}/${basefile}
	done
	echo Licenses copied to $BASEDIR/$dirloc
else
	echo No licenses available to insert.
	echo Make sure to run the license insertion tool or the license \
configuration script on this machine.
fi

echo $BASEDIR/${dirloc} > ${licdir}/${locfile}
if [ $? -ne 0 ]
then
	echo Cannot Access license location file ${licdir}/${locfile}  - Exiting
	exit 1
fi

#
# Happy End
exit $e_ok
