#!/bin/ksh
#
#
# Copyright (c) 1992-1999 Sun Microsystems, Inc.  All Rights Reserved.
#
# setupLauncher
#
#

# Interactive install occurs first
# Only run this if interactive install is successful

LOG_FILE=disk0_install.log
WIZDIR=/webstart/wizards/apps
WIZBINDIR=/webstart/wizards/bin
LAUNCHDIR=/a/var/sadm/webstart
DISPATCH_TABLE=${LAUNCHDIR}/dispatch_table
CD_ID=`$WIZBINDIR/find_device -c`
PLATFORM=`uname -p`

# save find_device results for launcher
# intel OS cd's use p0 as the slice that contains the Solaris products.
# bugid 4239378
if [ $PLATFORM = "i386" ];then
  CD_ID=`echo $CD_ID | sed -e 's:s:p:g'`
fi
echo $CD_ID > /tmp/find_device.out

#echo "In setupLauncher" >> /tmp/$LOG_FILE
date >> /tmp/$LOG_FILE

# run script here to make dispatch_table, if appropriate
cd ${WIZDIR}
${WIZBINDIR}/parsePackagesToBeAdded
${WIZBINDIR}/create_dispatch_table

# If there is a dispatch_table, we need to set up to run the
# launcher after the system reboot. Copy over the necessary 
# files and set up rc script to run.
#


if [ -f ${DISPATCH_TABLE} ];then
    #echo "dispatch_table has been created" >> /tmp/$LOG_FILE

    #
    # need check for java here in case core was installed 
    #

    if [ -f /a/usr/java/bin/java ]
    then
        mkdir -p ${LAUNCHDIR}/bin
        if [ -z "${DISPLAY}" ] ; then
            touch ${LAUNCHDIR}/.nodisplay
            #
            # if we will be running launcher in tty mode,
            # we want the locale to be set to C if the user
            # has selected an asian system locale. Look for
            # LC_MESSAGES, then LANG in /a/etc/default/init 
            # to decide if we have an asian locale. Then, 
            # make a temporary /etc/default/init by getting 
            # rid of all LC_ and LANG lines and add LANG=C
            #
            locale=`grep "^LC_MESSAGES=" /a/etc/default/init 2>/dev/null \
                         | cut -d= -f2  | sed -e 's:"::g'`
            if [ "X$locale" = "X" ]
            then
               locale=`grep "^LANG=" /a/etc/default/init 2>/dev/null \
                          | cut -d= -f2 \
                          | sed -e 's:"::g'`
            fi

            asian=NO
            if [ "X$locale" != "X" ]
            then
                echo $locale | /usr/bin/egrep -s "^ja" 2>&1
                if [ $? -eq 0 ]
                then
                    asian=YES
                else 
                    echo $locale | /usr/bin/egrep -s "^zh" 2>&1
                    if [ $? -eq 0 ]
                    then
                        asian=YES
                    else 
                        echo $locale | /usr/bin/egrep -s "^ko" 2>&1
                        if [ $? -eq 0 ]
                        then
                            asian=YES
                        fi
                    fi
                fi
            fi

            if [ "$asian" = "YES" ]
            then
                /usr/bin/sed -e '/^LC_/d' -e '/^LANG/d' \
                           /a/etc/default/init > /a/etc/default/init.new
                echo "LANG=C" >> /a/etc/default/init.new
	        cp /a/etc/default/init /a/etc/default/init.save
	        cp /a/etc/default/init.new /a/etc/default/init
                rm /a/etc/default/init.new 2>/dev/null
            fi


        fi
        cp launcher.class ${LAUNCHDIR}
        mkdir -p ${LAUNCHDIR}/com/sun/launcher
        if [ -d com/sun/launcher ]; then
          cp -r com/sun/launcher ${LAUNCHDIR}/com/sun
        fi
        cp /tmp/find_device.out ${LAUNCHDIR} 
        cp ${WIZBINDIR}/getVold ${LAUNCHDIR}/bin
        cp ${WIZBINDIR}/runwebstart ${LAUNCHDIR}/bin
        cp ${WIZBINDIR}/setupRoot ${LAUNCHDIR}/bin
        chmod a+x ${LAUNCHDIR}/bin/*
        cp ${WIZBINDIR}/s96webstart /a/etc/init.d/webstart
        ln /a/etc/init.d/webstart /a/etc/rc2.d/S96webstart
      
        cd ${LAUNCHDIR}
        mkdir -p ${LAUNCHDIR}/.mrInstallsComplete
        #echo "RC scripts setup complete" >> /tmp/$LOG_FILE
     
    else
        #echo "Java is not installed. No RC script setup reqd" >> /tmp/$LOG_FILE
        gettext "Unable to run Launcher without Java.\n"
        gettext "The following CDs will not be installed:\n"
        /usr/bin/grep CDName ${DISPATCH_TABLE} | /usr/bin/cut -d= -f2 
    fi

fi
  

if [ -d /a/var/sadm/system/logs ];then
	cp /tmp/$LOG_FILE  /a/var/sadm/system/logs/$LOG_FILE > /dev/null 2>&1
fi
