#
# ident "@(#)postinstall.src	1.11	05/05/18 SMI"
#
# Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin

if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi
if [ -z "$CLIENT_BASEDIR" ]; then CLIENT_BASEDIR="/"; fi
if [ -z "$BASEDIR" ]; then BASEDIR="$PKG_INSTALL_ROOT$CLIENT_BASEDIR"; fi

set -u

set -e

# Run utacleanup to initialize the symlinks.  Do this only if we're not
# doing an altroot install.  In the altroot case it'll all get taken care
# of when the client gets booted.
#
if [ -z "$PKG_INSTALL_ROOT" ]; then
  /etc/init.d/utacleanup
fi

# Clean up /var/opt/
#
# VAROPTDIR, the /var/opt path without the prepended PKG_INSTALL_ROOT
# path. ROOT_VAROPTDIR includes the PKG_INSTALL_ROOT path so that it
# does the right thing in an altroot install.

VAROPTDIR=/var/opt/SUNWut
ROOT_VAROPTDIR=$PKG_INSTALL_ROOT$VAROPTDIR

for dir in $ROOT_VAROPTDIR/log; do
  if [ -d "$dir" ]; then
    find $dir -type f -exec rm {} \;
  fi
done

OS=`uname -s`
if [ $OS = "Linux" ]; then 
    #
    # For Linux only.  We need to create the links to init.d files using
    # chkconfig.  This is something else we can't do in an altroot install,
    # but luckily Linux doesn't support altroot installs anyway.
    #
    INITFILES="utsyscfg utacleanup utsvc"
    for F in $INITFILES
    do
	chkconfig --add $F > /dev/null
    done
    #
    # On SuSE/JDS, chkconfig (based on insserv) does not create Kill links in
    # lower runlevels.  They must be created manually.
    #
    if [ -f /etc/SuSE-release ]; then
	# we are installing on either SuSE or JDS
	ETCINIT=/etc/rc.d
	KILLFILES="K31utsyscfg K15utacleanup K02utsvc"
    	for F in $KILLFILES
    	do
	    INITF=`echo $F | sed -e "s/^K..//"`
	    ln -s ../$INITF $ETCINIT/rc4.d/$F
	    ln -s ../$INITF $ETCINIT/rc3.d/$F
	    ln -s ../$INITF $ETCINIT/rc2.d/$F
	    ln -s ../$INITF $ETCINIT/rc1.d/$F
    	done
    fi
fi

# if gmSignature file exists, remove it!!  We don't want to use a
# leftover file.
#
rm -f $PKG_INSTALL_ROOT/etc/opt/SUNWut/gmSignature
umask 177
touch $PKG_INSTALL_ROOT/etc/opt/SUNWut/gmSignature
chown root $PKG_INSTALL_ROOT/etc/opt/SUNWut/gmSignature

exit 0
