#! /sbin/sh
########
# Product: Ignite-UX
# Fileset: IGNITE
# configure
# @(#) $Revision: 10.22 $
########
#
# (c) Copyright Hewlett-Packard Company 1994
#
########################################################################


UTILS=/usr/lbin/sw/control_utils
if [ -f $UTILS ]
then
    . $UTILS
else
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

if [[ -n $SW_DEFERRED_KERNBLD ]]
then
    echo "WARNING: Ignite-UX will not function from an NFS Diskless"
    echo "         client, although swlist(1M) will report the product"
    echo "         as installed."
    exit $WARNING
fi

INST_DIR=/opt/ignite
VAR_DIR=/var/opt/ignite

result=$SUCCESS

# Copy the ignite.defaults file
SW_LOCATION=/opt/ignite/ newconfig_cp $VAR_DIR/server/ignite.defs
SW_LOCATION=/opt/ignite/ newconfig_msgs $?

# Replace old full_recovery_info keyword in ignite.defaults file
# with new full_net_recovery_info keyword
sed 's/full_recovery_info/full_net_recovery_info/' \
    $VAR_DIR/server/ignite.defs >$VAR_DIR/server/ignite.defs.tmp
mv $VAR_DIR/server/ignite.defs.tmp $VAR_DIR/server/ignite.defs
chown bin:bin $VAR_DIR/server/ignite.defs

#
# Create the ignite preferences directory:
#
cond_mkdir 755 bin bin /var/opt/ignite/server/preferences

#
# Check to see if the OBAM-RUN fileset is required, and if so and
# it was not loaded, then give an error
#

case $(uname -r) in
*.10.00|*.10.01|*.10.10|*.10.20|*.10.30|*.11.00)
    # A new obam is needed on these releases.  If it was not loaded, then
    # complain.
    if [ ! -f $INST_DIR/obam.10/lib/libobam.1 ] ; then
        echo "\
ERROR:   The system does not appear to have the Ignite-UX.OBAM-RUN fileset
         installed.  It is necessary for the \"ignite\" user interface."
         result=$FAILURE
    fi
    ;;
*)
    # The original obam is sufficient on 11.10 and newer, so just check
    # to make sure it is here.
    if [ ! -f /usr/obam/lib/libobam.1 ] ; then
        echo "\
ERROR:   The system does not appear to have the SystemAdmin.OBAM-RUN fileset
         installed.  It is necessary for the \"ignite\" user interface."
         result=$FAILURE
    fi
    ;;
esac


# Now initialize the tool definitions for SCMgr
# Copy the tools so that SCMgr can add them after it is configured 
# with mxsetup. Make files and directories read only
mkdir -p /var/opt/mx/tools
if [[ $? != 0 ]]
then
    result=$FAILURE
fi
chmod 555 /var/opt/mx
chmod 555 /var/opt/mx/tools

if [[ -f /opt/ignite/mx/iux_tools.xml ]] 
then
    cp /opt/ignite/mx/iux_tools.xml /var/opt/mx/tools
    if [[ $? != 0 ]]
    then
    	result=$FAILURE
    fi
    chmod 444 /var/opt/mx/tools/iux_tools.xml
fi 

#
# In the off chance that SCMgr is already installed and configured, 
# add the tools now.  Since mxtool might not exist, and might not succeed (if
# mxsetup has not been run), ignore any errors.
# SCM 2.5 and below uses iux_tools.tdef file and the later versions use 
# iux_tools.xml. Check if the later version is present, if it is not present
# then check for the older version.
#
if [[ -x /opt/mx/lbin/add_tools && -f /var/opt/mx/tools/iux_tools.xml ]]; then
    /opt/mx/lbin/add_tools /var/opt/mx/tools/iux_tools.xml
elif [[ -x /opt/mx/bin/mxtool && -f /opt/ignite/mx/iux_tools.tdef ]]; then
    # This is for SCM 2.5 before, if it is present.
    cp /opt/ignite/mx/iux_tools.tdef /var/opt/mx/tools
    chmod 444 /var/opt/mx/tools/iux_tools.tdef
    mkdir -p /opt/webadmin/mx/icons
    for line in $(ls /opt/ignite/mx/icons)
    do
        cp /opt/ignite/mx/icons/$line /opt/webadmin/mx/icons
    done
    cp /opt/ignite/mx/icons/iuxicon.config /opt/webadmin/mx/icons

    /opt/mx/bin/mxtool -a -f /var/opt/mx/tools/swmtools.tdef > /dev/null 2>&1
    /opt/mx/bin/mxtool -m -i -f /var/opt/mx/tools/iux_tools.tdef > /dev/null 2>&1

fi


exit $result
