#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 18.3 $ generated on Fri Jun  1 01:11:43 MDT 2001
#
# (c)Copyright 1983-2001 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD configure script template for use with all patches.           #
#------------------------------------------------------------------#
# This file is optional for all patches.  The purpose of this      #
# script is to perform patch installation actions that cannot be   #
# accomplished by simple unconditional file extraction from the    #
# software source media.                                           #
#------------------------------------------------------------------#

_PATCHID=PHSS_23546

UTILS="/usr/lbin/sw/control_utils"

if [ ! -f $UTILS ]; then
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

. $UTILS
exitval=$SUCCESS

#####
##### Insert any code you may require right here.
##### Pay attention to the exitval variable and set appropriately
##### in your code.  If you are unsure as to what types of operations
##### are legal in this file and what types aren't, consult the 
##### "Guidelines for SD Control Scripts" document.
#####
##### START_CUSTOMIZATION_HERE
#
# Begin DDX-SAM
#
    SAM_DIR=${SW_ROOT_DIRECTORY}usr/lib/X11/Xserver/misc/sam
    SAMREG=/usr/sam/bin/samreg

    $SAMREG $SAM_DIR > /dev/null 2>&1
    if [[ $? -eq 1 ]]
    then
        $SAMREG -u $SAM_DIR > /dev/null 2>&1
        print -u2 "ERROR:   Failed to register SAM."
            exitval="$FAILURE"
    fi
#
# End DDX-SAM
#

#
# clean up IPD for tarball
#

GAGDIR=/opt/graphics/common/doc/GAG
GAGTAR=/opt/graphics/common/doc/GAG/GAG-11.0.tar
if [[ -s ${GAGTAR} ]]
then
   cd ${GAGDIR}
# Do NOT untar the GAG file now that SBDK is on the
# ISU media.  If the product is install and the
# is installed over it, swverify of SBDK fails
# because of SBDK GAG files are delivered with it.
##   rm -rf ${GAGDIR}/Web > /dev/null 2>&1
##   /sbin/tar -xpf ${GAGTAR} > /dev/null 2>&1
fi
rm -f ${GAGTAR} > /dev/null 2>&1

#  PHSS_13905 may (if system is being updated) or may not (if
#  the system is begin cold installed) be on the system.  
#  Check and swmodify as appropriate.

swlist -l file > /tmp/swlist.out 2>/dev/null
for file in ${GAGTAR}; do
    #####echo "$file"
    grepres=`grep $file /tmp/swlist.out`
    if [ $? -eq 0 ]                     # file is in IPD
    then
        grep $file /tmp/swlist.out | awk ' { print $1 } ' | sed -e "s/://" > /tmp/grep.out
        #####grep $file /tmp/swlist.out | sed -e "s:${file}.*$::" | sed -e "s/://" > /tmp/grep.out
        while read prod_fs
        do
            #####echo $prod_fs
            if [ ! -f $file ]           # file is not on system
            then
                swmodify -uxfiles="$file" $prod_fs
            else
                swmodify -xfiles="$file" $prod_fs
            fi
        done < /tmp/grep.out
    fi
done

rm -f /tmp/swlist.out /tmp/grep.out

#
# moved the rgb creation from the postinstall script
# whcih uses the SD unsupported command rgb
#
DESTOPT=/etc/X11
# run in separate shell to avoid directory problems
(
	cd $DESTOPT
	/usr/bin/X11/rgb < rgb.txt > /dev/null 2>&1
)


#
# put slsd in place if it's not there
#
if [ ! -s /etc/rc.config.d/slsd ]
then
    echo "#   ************* File:  /etc/rc.config.d/slsd ********************" > /etc/rc.config.d/slsd
    echo "# SLSd configuration.  See /usr/lib/X11/Xserver/info/screens/hp" >> /etc/rc.config.d/slsd
    echo "#" >> /etc/rc.config.d/slsd
    echo "# SLSD_DAEMON:    Set to 1 to start Distributed Single Logical Screen daemon" >> /etc/rc.config.d/slsd
    echo "#                 Set to 0 to disable Distributed Single Logical Screen daemon" >> /etc/rc.config.d/slsd
    echo "#" >> /etc/rc.config.d/slsd
    echo "#" >> /etc/rc.config.d/slsd
    echo "# Set this variable to save all Slave X server output into a" >> /etc/rc.config.d/slsd
    echo "# log file." >> /etc/rc.config.d/slsd
    echo "#" >> /etc/rc.config.d/slsd
    echo "# export SLSD_DAEMON_SLAVE_LOGFILE=/tmp/slsdDaemon.log" >> /etc/rc.config.d/slsd
    echo "" >> /etc/rc.config.d/slsd
    echo "SLSD_DAEMON=0" >> /etc/rc.config.d/slsd
    chown bin /etc/rc.config.d/slsd
    chgrp bin /etc/rc.config.d/slsd
    chmod 0555 /etc/rc.config.d/slsd
fi

exit $exitval
