#!/bin/sh
# @(#)wabi	2.111	28 Oct 1994
#
#	wabi:	Wabi startup script.
#
#		Set WABIDIR env var, $HOME/wabi is the default.
#
#		Create WABIDIR if necessary.
#
#		Create WABIDIR/fc if necessary.
#
#		Invoke wabiprog.
#
#	Copyright (c) 1991, Sun Microsystems, Inc.  All Rights Reserved
#	Sun considers its source code as an unpublished, proprietary
#	trade secret, and it is available only under strict licens
#	provisions.  This copyright notice is placed here only to protect
#	Sun in the event the source is deemed a published work.  Dissassembly,
#	decompilation, or other means of reducing the object code to human
#	readable form is prohibited by the license agreement under which
#	this code is provided to the user or company in possession of this
#	copy.
# 
#	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.

FILE_CHECK=/etc/.vold.wabi


NAWK=/usr/bin/nawk
GREP=/usr/bin/grep
CAT=/bin/cat
ECHO=/bin/echo
UNAME=/usr/bin/uname
PS=/usr/bin/ps
CKYORN=/usr/bin/ckyorn
SH=/usr/bin/sh

change_volmgt()
{
	#
	# change_volmgt() -
	#	check to see if /etc/vold.conf should change.
	#	return FALSE if there is no reason to change (e.g., no volmgt 
	#	    running)
	#	return TRUE if we should ask user to change
	#


	#
	# if this is already fixed, don't even continue
	#
		
	if [ -f $FILE_CHECK ]
	then
		$ECHO FALSE
		return
	fi	

	#
	# only change 5.4 systems (should we do this?)
	#

	if [ "`$UNAME -r`" != "5.4" ]
	then
		$ECHO FALSE
		return
	fi

	#
	# only do this is they have a floppy
	#

	if [ ! -c /dev/rdiskette ]
	then
		$ECHO FALSE
		return
	fi

	# 
	# are they even running vold?
	#

	PID=`$PS -ef | $GREP /usr/sbin/vold | $GREP -v $GREP | $NAWK '{ print $2 }'`

	if [ -z "$PID" ]
	then
		$ECHO FALSE
		return
	fi

	#
	# look to see if line exists in /etc/vold.conf
	#

	$CAT /etc/vold.conf | $NAWK '
	    BEGIN { FOUND = 0 } 
	    {
	    	if(($1 == "use") && ($2 == "floppy") && ($3 == "drive")) 
		    FOUND = 1
	    }
	    END { 
		exit (FOUND == 1)
	    } 
	'
	RET="$?"

	if [ "$RET" = "1" ]
	then
		$ECHO TRUE	# if we have found the line to change
	else
		$ECHO FALSE
	fi
}

# Command
if [ -x /usr/bin/cp ]; then
	CP="/usr/bin/cp"
else
	CP="/bin/cp"
fi

if [ -x /usr/bin/rm ]; then
	RM="/usr/bin/rm -f"
else
	RM="/bin/rm -f"
fi

if [ -x /usr/bin/mkdir ]; then
	MKDIR="/usr/bin/mkdir"
else
	MKDIR="/bin/mkdir"
fi

if [ -x /usr/bin/df ]; then
	DF="env LANG=C /usr/bin/df -k"
else
if [ -x /usr/bin/bdf ]; then
	DF="/usr/bin/bdf"
else
	DF="/bin/df -k"
fi
fi

if [ -x /usr/bin/awk ]; then
	AWK="/usr/bin/awk"
else
	AWK="/bin/awk"
fi

if [ -x /usr/bin/touch ]; then
	TOUCH="/usr/bin/touch"
else
	TOUCH="/bin/touch"
fi

if [ -x /usr/bin/ln ]; then
	LN="/usr/bin/ln -s"
else
	LN="/bin/ln -s"
fi

if [ -x /usr/bin/grep ]; then
	GREP="/usr/bin/grep"
else
	GREP="/bin/grep"
fi

if [ -x /usr/bin/diff ]; then
	DIFF="/usr/bin/diff"
else
	DIFF="/bin/diff"
fi

if [ -x /usr/bin/mv ]; then
	MV="/usr/bin/mv"
else
	MV="/bin/mv"
fi

SWAP="/usr/sbin/swap -s"

if [ -x /etc/pstat ]; then
	PSTAT="/etc/pstat -s"
else
	PSTAT="pstat -s"
fi

if [ -x /usr/bin/pkginfo ]; then
	PKGINFO="/usr/bin/pkginfo"
else
	PKGINFO="/bin/pkginfo"
fi

if [ -x /usr/bin/uname ]; then
	UNAME="/usr/bin/uname"
else
	UNAME="/bin/uname"
fi

if [ -x /usr/bin/sed ]; then
	SED="/usr/bin/sed"
else
	SED="/bin/sed"
fi

#setup arguments
IFLAG="no"
if [ $# != 0 ]
then
	FIRSTFLAG=`echo $* | $AWK '{ print $1 }'`
	# echo $FIRSTFLAG
	if [ $FIRSTFLAG = -i ]
	then
		IFLAG="yes"
	fi
fi
	

# Swap space required to start wabi, 20M bytes.
SWAPREQD=20000

# WABIDIR directory space requirement for initial installation, 1M bytes.
WABIDIRREQD=1000

# Determine HOSTNAME
if [ ! -f /kernel/unix -a ! -f /unix -a ! -f /platform/`$UNAME -m`/kernel/unix ]
then
    HOSTNAME="`hostname`"
else
    HOSTNAME="`$UNAME -n`"
fi

# Determine WABIDIR
if [ -z "$WABIDIR" ]
then
    WABIDIR="$HOME/wabi"
    export WABIDIR
fi

# BETA ISSUE: Solaris 2.4 has volmgt problems which we haven't worked
# around 
#
# if S2.4 and running volmgt, suggest they turn it off
#

# if [ "`$UNAME -r`" = "5.4" ]
# then
#         VOLMGTPID=`/usr/bin/ps -ef | grep /usr/sbin/vold | grep -v grep | awk '{print $2}'`
#         if [ ! -z "$VOLMGTPID" ] ;  then
#                 echo 
# 		echo "To use diskettes, please disable the volume manager"
# 		echo "as superuser, type: /etc/init.d/volmgt stop"
# 		echo
#         fi
# fi
# Record the starting point so we can return after determining WABIHOME.
INITIAL_DIR=`pwd`

# Find out where this script lives to determine WABIHOME.
FROM_PATH=`echo "$0" | $GREP "/"`
 
if [ -n "$FROM_PATH" ]
then
	#in this case $0 is a directory component.
	FIRSTARG=`echo ${FROM_PATH} | $AWK -F/ '{ print $1 }'`
 
	if [ -z "$FIRSTARG" ]
	then
		SOURCE3=`echo ${0} | $AWK -F/ '{ for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
	else
		SOURCE3=`echo ${0} | $AWK -F/ '{ if ($1 == "") printf "/"; for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
	fi
else
	#in this case $0 is not a directory component.
	SOURCE3="./"
fi
 
cd "$SOURCE3"
cd ..
WABIHOME=`pwd`
export WABIHOME

if [ "`$UNAME`" = "SunOS" ]
then
	RET="`change_volmgt`"
	if [ "$RET" = "TRUE" ]
	then
		$ECHO
		$ECHO "To use your diskette drive under Wabi, we recommend that you"
		$ECHO "disable Volume Manager's control of the diskette drive. To do"
		$ECHO "this, enter the following command as superuser:"
		$ECHO "	$WABIHOME/bin/vold.switch -disable"
		$ECHO
		$ECHO "See the Wabi 2.0 Release Notes for more detailed information."
		$ECHO
	fi
fi

# Check for adequate swap space to start Wabi.
case "`$UNAME`" in
	
	SunOS )
		if [ ! -f /kernel/unix -a ! -f /unix -a ! -f /platform/`$UNAME -m`/kernel/unix ]
		then
    		PSTATS=`$PSTAT $KERNEL_PATH 2> /dev/null`
    		SWAPAVAIL=`echo ${PSTATS} | $AWK '{ print $9 }' | $AWK -Fk '{ print $1 }'`
    		if [ -z "$SWAPAVAIL" ]
    		then
				SWAPAVAIL=0
    		fi

    		if [ "$SWAPAVAIL" -lt "$SWAPREQD" ]
    		then
				echo "There is not enough swap space on your system to run the wabi software."
				echo ""$SWAPAVAIL" Kbytes are available, "$SWAPREQD" Kbytes are required."
        		exit 1
    		fi
		else
    		SWAPS=`$SWAP`
    		SWAPAVAIL=`echo ${SWAPS} | $AWK '{ print $11 }' | $AWK -Fk '{ print $1 }'`
    		if [ -z "$SWAPAVAIL" ]
    		then
				SWAPAVAIL=0
    		fi
		fi

# Physical memory space recommended to run wabi, Sparc: 32M bytes; i86: 24M bytes
		if [ `$UNAME -m` -eq "i86pc" ]
		then
		    MEMREQD=24
		else
		    MEMREQD=32
		fi

		MEMAVAIL=`/usr/sbin/prtconf|/bin/nawk ' {
		if($1 == "Memory" && $2 == "size:") print $3 }'`
    		if [ -z "$MEMAVAIL" ]
    		then
				MEMAVAIL=0
    		fi

    		if [ "$MEMAVAIL" -lt "$MEMREQD" ]
   		then
				echo "Warning: The memory size is less than "$MEMREQD" Mbytes recommended for Wabi."
				echo "Warning: Wabi performance may be affected."
		fi
		;;

	SCO_SV )
		# Size of required swap space in 512 byte blocks (20 Mb)
		SWAPREQD=40000
		SWAPAVAIL=`/etc/swap -l | $GREP /dev/swap | $AWK '{ print $4 }'`
		FAKE_INIT=
    	if [ -z "$SWAPAVAIL" ]
    	then
			FAKE_INIT=1
			SWAPAVAIL=$SWAPREQD
    	fi

    	if [ "$SWAPAVAIL" -lt "$SWAPREQD" ]
    	then
			echo "There may not be enough swap space on your system to run the wabi software."
			echo ""$SWAPAVAIL" 512 byte blocks are available, "$SWAPREQD" Kbytes are required."
			echo "To increase the amount of swap space, see your system administrator."
			echo "Swap space can be increased through the use of the swap and marry commands."
			SWAPAVAIL=$SWAPREQD
    	fi
		;;

	AIX )
# Need to use lsps to get real swap numbers...
		DF="/bin/df"
		SWAPAVAIL=$SWAPREQD
		;;

	HP-UX )
# Have no clue here.
		SWAPAVAIL=$SWAPREQD
		;;

	UNIX_SV )
# Have no clue here either.
		SWAPAVAIL=$SWAPREQD
		;;

	$HOSTNAME )
# Have no clue here.
		SWAPAVAIL=$SWAPREQD
		;;
		
esac

if [ "$SWAPAVAIL" -lt "$SWAPREQD" ]
then
    echo "There is not enough swap space on your system to run the wabi software."
    echo ""$SWAPAVAIL" Kbytes are available, "$SWAPREQD" Kbytes are required."
    exit 1
fi


# Create the user's wabi directory, if necessary.
if [ ! -d "$WABIDIR" ]
then  
    echo "Creating $WABIDIR"
    $MKDIR "$WABIDIR"
 
    DISKFREE=`$DF $WABIDIR 2> /dev/null`
    if [ -z "$DISKFREE" ]
    then
	# Failed to make $WABIDIR.
	echo "Could not create directory $WABIDIR; check files and permissions."
	exit 1
    fi

	if [ "`$UNAME`" = "SCO_SV" ]
	then
    	WABIDIRAVAIL=`echo ${DISKFREE} | $AWK -F" " '{ print $4 }'`
		WABIDIRAVAIL=`expr ${WABIDIRAVAIL} / 2`
	else
    	WABIDIRAVAIL=`echo ${DISKFREE} | $AWK -F" " '{ print $11 }'`
	fi

    if [ "$WABIDIRAVAIL" -lt "$WABIDIRREQD" ]
    then
	echo "There is not enough space in the $WABIDIR directory to run the wabi software."
	echo " "
	echo ""$WABIDIRAVAIL" Kbytes are available, "$WABIDIRREQD" Kbytes are required."
	exit 1
    fi
fi

#
#	write some system information into ~/wabi 
#

if [ -w $WABIDIR ] 
then
	/bin/rm -f $WABIDIR/sysinfo.txt
	(
		PATH=/usr/sbin:/bin
		export PATH
		echo "USER: `/bin/who am i|/bin/sed -e 's/ .*//'`"
		echo "HOST: `$UNAME -n`"
		echo "DISPLAY: $DISPLAY"
		echo "OS: `$UNAME -r`"
		echo "ARCH: `$UNAME -m`"
		case "`$UNAME`" in
		    SunOS )
			echo "FB: `/bin/file -h /dev/fb|/bin/sed -e 's/.*://'\
		    	|/bin/sed -e 's/symbolic link to \.\///'`"
			/usr/sbin/prtconf|/bin/nawk ' {
		    	if($1 == "Memory" && $2 == "size:") print "MEMORY: " $3 "MB"
			}'
			/usr/sbin/sysdef|/bin/nawk 'BEGIN { IN = 0 } {
			    if($1 == "swapfile") IN = 1;
			    if($1 == "*" && IN == 1) IN = 0;
			    if(IN) SUM += $5
			} END {
			    print "SWAP: " SUM/2048 "MB"
			}'
			break;;
		    *)
			echo "FB: unknown"
			echo "MEMORY: unknown"
			echo "SWAP: unknown"
			break;
		esac
	) > $WABIDIR/sysinfo.txt
	
fi


# Check for adequate swap space to start Wabi.
# To reduce the amount of space required for the user's WABIDIR, we create symbolic links
# for static files. However, to allow the user's WABIDIR to be independent of a particular
# system, we determine the symbolic link WABIDIR/wabihome each time this script is run.
# The relative symbolic links in the user's WABIDIR/windows and WABIDIR/windows/system
# are resolved through the WABIDIR/wabihome symbolic link pointing to WABIHOME.
$RM "$WABIDIR/wabihome"
$LN "$WABIHOME" "$WABIDIR/wabihome"
MERGEFILE="$WABIHOME/bin/mergefile"

#Set CHECK Flag for updating 
CHECK="yes"
if [ "`$UNAME`" != "UNIX_SV" ]
then
    WINFLG="no"
fi

# Create the users windows directory if necessary.
if [ ! -d "$WABIDIR/windows" ]
then
    $MKDIR "$WABIDIR/windows"
fi


# Copy default wabi.ini file to the windows directory.
if [ ! -f "$WABIDIR/windows/wabi.ini" ]
then
    $CP "$WABIHOME/wbin/wabi.ini" "$WABIDIR/windows"
else
    CURVERSION="`$GREP Config= $WABIDIR/windows/wabi.ini`"
    CURVERSION=`expr "$CURVERSION" : '.*=\([1-9][0-9\.]*.*\)[
]$'`
  
    if [ "$CURVERSION" = "2.0" ]
    then
	# Set this flag on only for testing.
	CHECK="no"

	# Put this condition only for testing.
    	MERGEFLG=`echo ${WABIMERGE}`
    	if [ -z "$MERGEFLG" ]
    	then
	    MERGE="no"
    	else
	    if [ "$MERGEFLG" = "1" ]
	    then
	    	MERGE="yes"
		CHECK="yes"
		# Check if window is installed
		if [ "`$UNAME`" != "UNIX_SV" ]
		then
            	    if [ -f "$WABIDIR/windows/system/setup.inf" ]
            	    then
           		WINFLG="yes" 
	    	    fi   
        	fi
	    fi
    	fi

	# Check if window is installed.
	if [ "`$UNAME`" != "UNIX_SV" ]
	then
            if [ -f "$WABIDIR/windows/system/setup.inf" ]
            then
           	WINFLG="yes" 
	    fi   
        fi
    else
	MERGE="yes"
        # Check if window is installed.
	if [ "`$UNAME`" != "UNIX_SV" ]
	then
            if [ -f "$WABIDIR/windows/system/setup.inf" ]
            then
           	WINFLG="yes" 
	    fi   
        fi
    fi

	
    if [ $MERGE = yes ]
    then
	$MV "$WABIDIR/windows/wabi.ini" "$WABIDIR/windows/wabi.ini.bak"
	$MERGEFILE "$WABIDIR/windows/wabi.ini.bak" "$WABIHOME/wbin/wabi.ini" "$WABIDIR/windows/wabi.ini"
	echo "Saving existing wabi.ini to wabi.ini.bak and updating wabi.ini."
    fi
fi

#
# Define all subroutines that need to be used for changing shell variables.
#

Change_Shell_Wininst()
{
    $SED '/shell/d' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp"
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"
    $SED '/boot/ a\
shell=win_inst.exe' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	
}


Change_Shell_Regist()
{
    $SED '/shell/d' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp"
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	
    $SED '/boot/ a\
shell=regiwabi.exe' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	
}


Add_NeedWindows_Yes()
{
    $SED '/shell/ a\
NeedWindows=Yes' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 		
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	    
}


Add_NeedWindows_No()
{
    $SED '/shell/ a\
NeedWindows=No' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 		
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	    
}


Remove_More_NeedWindows()
{
    $SED '/NeedWindows/d' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 		
    $RM "$WABIDIR/windows/system.ini"
    $MV "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	    
}

#
# Define subroutines end
#

# Copy system.ini to $WABIDIR/windows
if [ ! -f "$WABIDIR/windows/system.ini" ]
then
    $CP "$WABIHOME/wbin/system.ini" "$WABIDIR/windows"

    if [ "$WINFLG" = "no" ]
    then
	if [ "`$UNAME`" = "SunOS" ]
	then
	    Change_Shell_Regist
	    Add_NeedWindows_Yes
	else
	    Change_Shell_Wininst
	fi
    fi
else
    if [ $MERGE = yes ]
    then
	$MV "$WABIDIR/windows/system.ini" "$WABIDIR/windows/system.ini.bak"
	$MERGEFILE "$WABIDIR/windows/system.ini.bak" "$WABIHOME/wbin/system.ini" "$WABIDIR/windows/system.ini"
	echo "Saving existing system.ini to system.ini.bak and updating system.ini."
        if [ "`$UNAME`" = "SunOS" ]
	then
	    Change_Shell_Regist

	    if [ "$WINFLG" = "no" ]
            then
		Remove_More_NeedWindows
		Add_NeedWindows_Yes
            fi
		
	    if [ "$WINFLG" = "yes" ]
	    then
	        Remove_More_NeedWindows
		Add_NeedWindows_No
            fi
	else
	    if [ "$WINFLG" = "no" ]
	    then 
		Change_Shell_Wininst
	    fi
	fi
    else
	if [ "$WINFLG" = "no" ]
	then
	    Change_Shell_Wininst
	fi
    fi
fi


if [ $CHECK = yes ]
then
    # commdlz.dll and shellz.dll are moved to $WABIDIR/windows/system
    $RM "$WABIDIR/windows/commdlz.dll"
    $RM "$WABIDIR/windows/shellz.dll"

    # We no longer need appman.hlp, viewer.hlp and helpview.exe files
    $RM "$WABIDIR/windows/appman.hlp"
    $RM "$WABIDIR/windows/viewer.hlp"
    $RM "$WABIDIR/windows/helpview.exe"
    $RM "$WABIDIR/windows/atm.ini"


    # Copy autoexec.bat file to $WABIDIR
    if [ ! -f "$WABIDIR/autoexec.bat" ]
    then
        $CP "$WABIHOME/wbin/autoexec.bat" "$WABIDIR"
    fi


    # Copy config.sys file to $WABIDIR
    if [ ! -f "$WABIDIR/config.sys" ]
    then
        $CP "$WABIHOME/wbin/config.sys" "$WABIDIR"
    fi


    # Copy win.ini to $WABIDIR/windows
    if [ ! -f "$WABIDIR/windows/win.ini" ]
    then
    	$CP "$WABIHOME/wbin/win.ini" "$WABIDIR/windows"
    else
	if [ $MERGE = yes ]  
	then
	    $MV "$WABIDIR/windows/win.ini" "$WABIDIR/windows/win.ini.bak"
	    $MERGEFILE "$WABIDIR/windows/win.ini.bak" "$WABIHOME/wbin/win.ini" "$WABIDIR/windows/win.ini"
	    echo "Saving existing win.ini to win.ini.bak and updating win.ini."
        fi
    fi


    # Copy progman.ini file to the windows directory.
    if [ ! -f "$WABIDIR/windows/progman.ini" ]
    then
        $CP "$WABIHOME/wbin/progman.ini" "$WABIDIR/windows"
    fi


    # Copy reg.dat to $WABIDIR/windows
    if [ ! -f "$WABIDIR/windows/reg.dat" ]
    then
        $CP "$WABIHOME/wbin/reg.dat" "$WABIDIR/windows"
    fi

#   In the case of an upgrade from 1.X to 2.0, we should not move
#   in our version of reg.dat over the user's.

    # Copy wabi.grp file to the windows directory.
    if [ ! -f "$WABIDIR/windows/wabi.grp" ]
    then
        $CP "$WABIHOME/wbin/wabi.grp" "$WABIDIR/windows"
    else
	if [ $MERGE = yes ]
	then
     	    $MV "$WABIDIR/windows/wabi.grp" "$WABIDIR/windows/wabi.grp.bak"
	    $CP "$WABIHOME/wbin/wabi.grp" "$WABIDIR/windows"
	    echo "Saving existing wabi.grp to wabi.grp.bak and updating wabi.grp."
	fi
    fi


    # Copy wabireg.dat file to the windows directory.
    if [ ! -f "$WABIDIR/windows/wabireg.dat" ]
    then
        $CP "$WABIHOME/wbin/wabireg.dat" "$WABIDIR/windows"
    fi


    # Link dosprmpt.pif to $WABIHOME/wbin to start a PC/DOS Emulator session when called.
    if [ ! -f "$WABIDIR/windows/dosprmpt.pif" ]
    then
        $LN "../wabihome/wbin/dosprmpt.pif" "$WABIDIR/windows/dosprmpt.pif"
    fi


    # Link pwi.dll to WABIHOME/wbin.
    if [ ! -f "$WABIDIR/windows/pwi.dll" ]
    then
        $LN "../wabihome/wbin/pwi.dll" "$WABIDIR/windows/pwi.dll"
    fi


    # Link helpdll.dll to WABIHOME/wbin.
    if [ ! -f "$WABIDIR/windows/helpdll.dll" ]
    then
        $LN "../wabihome/wbin/helpdll.dll" "$WABIDIR/windows/helpdll.dll"
    fi

    
    # Link vwhlpdsp.dll to WABIHOME/wbin.
    if [ ! -f "$WABIDIR/windows/vwhlpdsp.dll" ]
    then
        $LN "../wabihome/wbin/vwhlpdsp.dll" "$WABIDIR/windows/vwhlpdsp.dll"
    fi

    
#   # Copy netbios.ini file to the windows directory.
#   if [ ! -f "$WABIDIR/windows/netbios.ini" ]
#   then
#       $CP "$WABIHOME/wbin/netbios.ini" "$WABIDIR/windows"
#   fi


    # Copy colorset.ini file to the windows directory.
    if [ ! -f "$WABIDIR/windows/colorset.ini" ]
    then
        $CP "$WABIHOME/wbin/colorset.ini" "$WABIDIR/windows"
    fi


    # Copy winver.exe file to the windows directory.
    if [ ! -f "$WABIDIR/windows/winver.exe" ]
    then
        $CP "$WABIHOME/wbin/winver.exe" "$WABIDIR/windows/winver.exe"
    fi


    # Copy winver.exe file to the windows directory.
    if [ ! -f "$WABIDIR/windows/control.exe" ]
    then
        $CP "$WABIHOME/wbin/control.exe" "$WABIDIR/windows/control.exe"
    fi


#    # Copy helpview.exe file to the windows directory
#    if [ ! -f "$WABIDIR/windows/winhelp.exe" ]
#    then
#        $CP "$WABIHOME/wbin/helpview.exe" "$WABIDIR/windows/winhelp.exe"
#    fi

   
    # Copy share.exe file to the windows directory
    if [ ! -f "$WABIDIR/windows/share.exe" ]
    then
        $CP "$WABIHOME/wbin/share.exe" "$WABIDIR/windows/share.exe"
    fi


    # Link wriview.exe to $WABIHOME/wbin
    if [ ! -f "$WABIDIR/windows/wriview.exe" ]
    then
        $LN "../wabihome/wbin/wriview.exe" "$WABIDIR/windows/wriview.exe"
    fi


    # Link appman.exe to $WABIHOME/wbin
    if [ ! -f "$WABIDIR/windows/appman.exe" ]
    then
        $LN "../wabihome/wbin/appman.exe" "$WABIDIR/windows/appman.exe"
    fi


    # Create progman.exe symbolic link to appman.exe
    if [ ! -f "$WABIDIR/windows/progman.exe" ]
    then
        $LN "../wabihome/wbin/appman.exe" "$WABIDIR/windows/progman.exe"
    fi


    # Create write.exe symbolic link to wriview.exe
    if [ ! -f "$WABIDIR/windows/write.exe" ]
    then
        $LN "../wabihome/wbin/wriview.exe" "$WABIDIR/windows/write.exe"
    fi


    # Create notepad.exe symbolic link to wriview.exe
    if [ ! -f "$WABIDIR/windows/notepad.exe" ]
    then
        $LN "../wabihome/wbin/wriview.exe" "$WABIDIR/windows/notepad.exe"
    fi


#    # Create helpview.exe symbolic link to helpview.exe
#    if [ ! -f "$WABIDIR/windows/helpview.exe" ]
#    then
#        $LN "../wabihome/wbin/helpview.exe" "$WABIDIR/windows/helpview.exe"
#    fi


    # Create win_inst.exe symbolic link to win_inst.exe
    if [ ! -f "$WABIDIR/windows/win_inst.exe" ]
    then
        $LN "../wabihome/wbin/win_inst.exe" "$WABIDIR/windows/win_inst.exe"
    fi

   
    # Create regiwabi.exe symbolic link to regiwabi.exe
    if [ "`$UNAME`" = "SunOS" ]
    then
    	if [ ! -f "$WABIDIR/windows/regiwabi.exe" ]
    	then
            $LN "../wabihome/wbin/regiwabi.exe" "$WABIDIR/windows/regiwabi.exe"
    	fi
    fi


    # Copy regloaz.exe to the windows directory as regedit.exe
    if [ ! -f "$WABIDIR/windows/regedit.exe" ]
    then
    	$CP "$WABIHOME/wbin/regloaz.exe" "$WABIDIR/windows/regedit.exe"
    fi
    


#    # A work-around to the errant "Verifying fonts" popup window.
#    if [ ! -f "$WABIDIR/windows/atm.ini" ]
#    then
#    	$TOUCH "$WABIDIR/windows/atm.ini"
#    fi


    # Copy Adobe pfm files to the windows directory.
    if [ ! -f "$WABIDIR/windows/cob_____.pfm" ]
    then
    	$CP $WABIHOME/wbin/windows/*.ebf "$WABIDIR/windows"
	$CP $WABIHOME/wbin/windows/*.ppb "$WABIDIR/windows"
	$CP $WABIHOME/wbin/windows/*.pfm "$WABIDIR/windows"
    fi


    # Create the windows/system directory if necessary.
    if [ ! -d "$WABIDIR/windows/system" ]
    then 
        $MKDIR "$WABIDIR/windows/system" 
    fi

    
    # Link regsync.dll library to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/regsync.dll" ]
    then
    	$LN "../../wabihome/wbin/regsync.dll" "$WABIDIR/windows/system/regsync.dll"
    fi

    # Link cplcfg.cpl file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/cplcfg.cpl" ]
    then
        $LN "../../wabihome/wbin/cplcfg.cpl" "$WABIDIR/windows/system/cplcfg.cpl"
    fi
  
    # Link Adobe printer driver files to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/adobeps.drv" ]
    then
    	$LN "../../wabihome/wbin/windows/system/adobeps.drv" "$WABIDIR/windows/system/adobeps.drv"
    fi


    # Link adobeps.hlp file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/adobeps.hlp" ]
    then 
	$LN "../../wabihome/wbin/windows/system/adobeps.hlp" "$WABIDIR/windows/system/adobeps.hlp"
    fi


    # Link Epson printer driver file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/epson.drv" ]
    then 
	$LN "../../wabihome/printers/epson.drv" "$WABIDIR/windows/system/epson.drv"
    fi


    # Link Epson printer help file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/epson.hlp" ]
    then 
	$LN "../../wabihome/printers/epson.hlp" "$WABIDIR/windows/system/epson.hlp"
    fi

    
    # Link PCL printer driver file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/hppcl5a.drv" ]
    then 
	$LN "../../wabihome/printers/hppcl5a.drv" "$WABIDIR/windows/system/hppcl5a.drv"
    fi


    # Link PCL printer help file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/hppcl5a.hlp" ]
    then 
	$LN "../../wabihome/printers/hppcl5a.hlp" "$WABIDIR/windows/system/hppcl5a.hlp"
    fi


    # Link PCL option DB help file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/hppcl5op.hlp" ]
    then 
	$LN "../../wabihome/printers/hppcl5op.hlp" "$WABIDIR/windows/system/hppcl5op.hlp"
    fi


    # Link oemsetup.ini file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/oemsetup.ini" ]
    then 
	$LN "../../wabihome/printers/oemsetup.ini" "$WABIDIR/windows/system/oemsetup.ini"
    fi


    # Copy commdlg.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/commdlg.dll" ]
    then 
	$CP "$WABIHOME/wbin/commdlg.dll" "$WABIDIR/windows/system/commdlg.dll"
    fi


    # Link commdlz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/commdlz.dll" ]
    then 
	$LN "../../wabihome/wbin/commdlz.dll" "$WABIDIR/windows/system/commdlz.dll"
    fi


    # Copy shell.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/shell.dll" ]
    then 
	$CP "$WABIHOME/wbin/shell.dll" "$WABIDIR/windows/system/shell.dll"
    fi


    # Link shelz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/shelz.dll" ]
    then 
	$LN "../../wabihome/wbin/shelz.dll" "$WABIDIR/windows/system/shelz.dll"
    fi


    # Link shellz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/shellz.dll" ]
    then 
	$LN "../../wabihome/wbin/shelz.dll" "$WABIDIR/windows/system/shellz.dll"
    fi


    # Link ver.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/ver.dll" ]
    then 
	$CP "$WABIHOME/wbin/ver.dll" "$WABIDIR/windows/system/ver.dll"
    fi


    # Link vez.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/vez.dll" ]
    then 
	$LN "../../wabihome/wbin/vez.dll" "$WABIDIR/windows/system/vez.dll"
    fi


    # Copy ddeml.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/ddeml.dll" ]
    then 
	$CP "$WABIHOME/wbin/ddeml.dll" "$WABIDIR/windows/system/ddeml.dll"
    fi


    # Link ddemz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/ddemz.dll" ]
    then 
	$LN "../../wabihome/wbin/ddemz.dll" "$WABIDIR/windows/system/ddemz.dll"
    fi


    # Copy mmsystem.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/mmsystem.dll" ]
    then 
	$CP "$WABIHOME/wbin/mmsystem.dll" "$WABIDIR/windows/system/mmsystem.dll"
    fi


    # Link mmsystez.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/mmsystez.dll" ]
    then 
	$LN "../../wabihome/wbin/mmsystez.dll" "$WABIDIR/windows/system/mmsystez.dll"
    fi


    # Copy olecli.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/olecli.dll" ]
    then
    	$CP "$WABIHOME/wbin/olecli.dll" "$WABIDIR/windows/system/olecli.dll"
    fi


    # Link oleclz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/oleclz.dll" ]
    then
    	$LN "../../wabihome/wbin/oleclz.dll" "$WABIDIR/windows/system/oleclz.dll"
    fi


    # Copy olesvr.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/olesvr.dll" ]
    then
    	$CP "$WABIHOME/wbin/olesvr.dll" "$WABIDIR/windows/system/olesvr.dll"
    fi


    # Link olesvz.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/olesvz.dll" ]
    then
    	$LN "../../wabihome/wbin/olesvz.dll" "$WABIDIR/windows/system/olesvz.dll"
    fi

   
    # Link colorset.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/colorset.dll" ]
    then 
	$LN "../../wabihome/wbin/colorset.dll" "$WABIDIR/windows/system/colorset.dll"
    fi


    # Link internat.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/internat.dll" ]
    then 
	$LN "../../wabihome/wbin/internat.dll" "$WABIDIR/windows/system/internat.dll"
    fi


#   # Link netbios.dll file to the windows/system directory.
#   if [ ! -f "$WABIDIR/windows/system/netbios.dll" ]
#   then 
#	$LN "../../wabihome/wbin/netbios.dll" "$WABIDIR/windows/system/netbios.dll"
#   fi


    # Link down.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/down.dll" ]
    then 
	$LN "../../wabihome/wbin/windows/system/down.dll" "$WABIDIR/windows/system/down.dll"
    fi


    # Link dwn.hlp file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/dwn.hlp" ]
    then 
	$LN "../../wabihome/wbin/windows/system/dwn.hlp" "$WABIDIR/windows/system/dwn.hlp"
    fi

    
    # Link ps_enum.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/ps_enum.dll" ]
    then 
	$LN "../../wabihome/wbin/windows/system/ps_enum.dll" "$WABIDIR/windows/system/ps_enum.dll"
    fi


    # Link psinstdv.exe file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/psinstdv.exe" ] 
    then  
        $LN "../../wabihome/wbin/windows/system/psinstdv.exe" "$WABIDIR/windows/system/psinstdv.exe" 
    fi


    # Link run_enum.exe file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/run_enum.exe" ] 
    then     
	$LN "../../wabihome/wbin/windows/system/run_enum.exe" "$WABIDIR/windows/system/run_enum.exe"  
    fi


    # Link windown.exe file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/windown.exe" ]  
    then     
        $LN "../../wabihome/wbin/windows/system/windown.exe" "$WABIDIR/windows/system/windown.exe"   
    fi


    # Link toolhelp.dll file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/toolhelp.dll" ]
    then
    	$CP "$WABIHOME/wbin/toolhelp.dll" "$WABIDIR/windows/system/toolhelp.dll"
    fi


    # Link chlmss.fon file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/chlmss.fon" ]
    then
        $LN "../../wabihome/wbin/chlmss.fon" "$WABIDIR/windows/system/chlmss.fon"
    fi


    # Copy user.exe file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/user.exe" ]
    then
        $CP "$WABIHOME/wbin/user.exe" "$WABIDIR/windows/system/user.exe"
    fi


    # Copy Adobe printer driver .ppd and .mfm files and to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/defprtr.ppd" ]  
    then      
	$CP $WABIHOME/wbin/windows/system/*.ppd "$WABIDIR/windows/system"    
	$CP $WABIHOME/wbin/windows/system/*.mfm "$WABIDIR/windows/system"
    fi


    # Link 8514oem.fon file to the windows/system directory.
    if [ ! -f "$WABIDIR/windows/system/8514oem.fon" ]
    then
        $LN "../../wabihome/wbin/windows/system/8514oem.fon" "$WABIDIR/windows/system/8514oem.fon"
    fi
   
    # Link copybits.94 file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/copybits.94 ]
    then
        $LN "../../wabihome/wbin/copybits.94" "$WABIDIR/windows/system/copybits.94"
    fi


    # Link arial.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arial.fot ]
    then
        $LN "../../wabihome/wbin/arial.fot" "$WABIDIR/windows/system/arial.fot"
    fi


    # Link arial.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arial.ttf ]
    then
        $LN "../../wabihome/wbin/arial.ttf" "$WABIDIR/windows/system/arial.ttf"
    fi


    # Link arialbd.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arialbd.fot ]
    then
        $LN "../../wabihome/wbin/arialbd.fot" "$WABIDIR/windows/system/arialbd.fot"
    fi


    # Link arialbd.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arialbd.ttf ]
    then
        $LN "../../wabihome/wbin/arialbd.ttf" "$WABIDIR/windows/system/arialbd.ttf"
    fi


    # Link arialbi.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arialbi.fot ]
    then
        $LN "../../wabihome/wbin/arialbi.fot" "$WABIDIR/windows/system/arialbi.fot"
    fi


    # Link arialbi.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/arialbi.ttf ]
    then
        $LN "../../wabihome/wbin/arialbi.ttf" "$WABIDIR/windows/system/arialbi.ttf"
    fi


    # Link ariali.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/ariali.fot ]
    then
        $LN "../../wabihome/wbin/ariali.fot" "$WABIDIR/windows/system/ariali.fot"
    fi


    # Link ariali.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/ariali.ttf ]
    then
        $LN "../../wabihome/wbin/ariali.ttf" "$WABIDIR/windows/system/ariali.ttf"
    fi


    # Link cour.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/cour.fot ]
    then
        $LN "../../wabihome/wbin/cour.fot" "$WABIDIR/windows/system/cour.fot"
    fi


    # Link cour.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/cour.ttf ]
    then
        $LN "../../wabihome/wbin/cour.ttf" "$WABIDIR/windows/system/cour.ttf"
    fi


    # Link courbd.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/courbd.fot ]
    then
        $LN "../../wabihome/wbin/courbd.fot" "$WABIDIR/windows/system/courbd.fot"
    fi


    # Link courbd.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/courbd.ttf ]
    then
        $LN "../../wabihome/wbin/courbd.ttf" "$WABIDIR/windows/system/courbd.ttf"
    fi


    # Link courbi.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/courbi.fot ]
    then
        $LN "../../wabihome/wbin/courbi.fot" "$WABIDIR/windows/system/courbi.fot"
    fi


    # Link courbi.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/courbi.ttf ]
    then
        $LN "../../wabihome/wbin/courbi.ttf" "$WABIDIR/windows/system/courbi.ttf"
    fi


    # Link couri.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/couri.fot ]
    then
        $LN "../../wabihome/wbin/couri.fot" "$WABIDIR/windows/system/couri.fot"
    fi


    # Link couri.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/couri.ttf ]
    then
        $LN "../../wabihome/wbin/couri.ttf" "$WABIDIR/windows/system/couri.ttf"
    fi


    # Link symbol.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/symbol.fot ]
    then
        $LN "../../wabihome/wbin/symbol.fot" "$WABIDIR/windows/system/symbol.fot"
    fi


    # Link symbol.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/symbol.ttf ]
    then
        $LN "../../wabihome/wbin/symbol.ttf" "$WABIDIR/windows/system/symbol.ttf"
    fi


    # Link times.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/times.fot ]
    then
        $LN "../../wabihome/wbin/times.fot" "$WABIDIR/windows/system/times.fot"
    fi


    # Link times.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/times.ttf ]
    then
        $LN "../../wabihome/wbin/times.ttf" "$WABIDIR/windows/system/times.ttf"
    fi


    # Link timesbd.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesbd.fot ]
    then
        $LN "../../wabihome/wbin/timesbd.fot" "$WABIDIR/windows/system/timesbd.fot"
    fi


    # Link timesbd.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesbd.ttf ]
    then
        $LN "../../wabihome/wbin/timesbd.ttf" "$WABIDIR/windows/system/timesbd.ttf"
    fi


    # Link timesbi.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesbi.fot ]
    then
        $LN "../../wabihome/wbin/timesbi.fot" "$WABIDIR/windows/system/timesbi.fot"
    fi


    # Link timesbi.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesbi.ttf ]
    then
        $LN "../../wabihome/wbin/timesbi.ttf" "$WABIDIR/windows/system/timesbi.ttf"
    fi


    # Link timesi.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesi.fot ]
    then
        $LN "../../wabihome/wbin/timesi.fot" "$WABIDIR/windows/system/timesi.fot"
    fi


    # Link timesi.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/timesi.ttf ]
    then
        $LN "../../wabihome/wbin/timesi.ttf" "$WABIDIR/windows/system/timesi.ttf"
    fi


    # Link tt3219z_.fot file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/tt3219z_.fot ]
    then
        $LN "../../wabihome/wbin/tt3219z_.fot" "$WABIDIR/windows/system/tt3219z_.fot"
    fi


    # Link tt3219z_.ttf file to the windows/system directory.
    if [ ! -f $WABIDIR/windows/system/tt3219z_.ttf ]
    then
        $LN "../../wabihome/wbin/tt3219z_.ttf" "$WABIDIR/windows/system/tt3219z_.ttf"
    fi

fi


# Create the wabi tmp directory if necessary.
if [ ! -d "$WABIDIR/tmp" ]
then
    $MKDIR "$WABIDIR/tmp"
fi


# Create the wabi font cache directory if necessary.
if [ ! -d "$WABIDIR/fc" ]
then
   $MKDIR "$WABIDIR/fc"
fi


PLAFORM="`$UNAME`"
if [ $PLAFORM = SunOS ]
then
    if [ `${UNAME} -r | $AWK -F. '{ print $1 }'` = "4" ]
    then
	WABIDRV_INSTALLED=`/usr/etc/modstat | ${GREP} wabi`
    else
	WABIDRV_INSTALLED=`${GREP} wabi /etc/driver_aliases`
    fi
	
    if [ -z "$WABIDRV_INSTALLED" ]
    then
	 # Test if wabi is installed in the local machine.
	 WHICHWABI="S`echo ${WABIHOME} | $AWK -FS '{ print $2 }'`"
    	 LOCALWABI="`$PKGINFO | $GREP $WHICHWABI`"

	if [ -z "$LOCALWABI" ]
    	then
	    # Wabi is not installed in local machine
	    echo "Warning: Package $WHICHWABI is not installed in this machine."
	    echo "Run $WABIHOME/bin/clientinstall as root to update" 
	    echo "the desktop environment."
	    exit 1
  	else
	    # Wabi is installed in local mechine but driver is not installed.
	    echo "Warning: The Wabi kernel driver is not installed."
            echo "Run $WABIHOME/drvr/wabiload as root to install the driver"
	fi
    fi
fi


# Until libvolmgt.so.1 becomes permanent in Solaris 2.3 we have to issue
# a warning to install the Volume Manager patch on Solaris 2.2 - if it's
# not already installed.
if [ `${UNAME} -r` = "5.2" ]
then
    if [ ! -f /usr/lib/libvolmgt.so.1 ]
    then
	echo " "
	echo "The Volume Manager patch should be installed on Solaris 2.2, otherwise"
	echo "Wabi may not be able to use the diskette drive."
	echo " "
    fi
fi

# Go to start point
cd "$INITIAL_DIR"

# HP specific code
if [ -f $WABIHOME/vue/custom.vue ]
then
	$WABIHOME/vue/custom.vue
 	if [ $? = 1 ]
	then
		exit
	fi
fi

# Ignoring eject diskette signal
trap "" 16

if [ $IFLAG = yes ]
then
    shift 1
    # Start wabiprog.i
    $WABIHOME/bin/wabiprog.i $*
else 
    # Start wabiprog
    $WABIHOME/bin/wabiprog $*
fi


# Restart Wabi automatically
while [ $? = 111 ]
do
    # If user choose restart wabi after MS Windows is installed, do merging when wabi restart.
    if [ -f "$WABIDIR/windows/control.src" ]
    then
    	if [ -f "$WABIDIR/windows/control.ini" ]
    	then
            $MV "$WABIDIR/windows/control.ini" "$WABIDIR/windows/control.ini.bak"
    	    $MERGEFILE "$WABIDIR/windows/control.src" "$WABIDIR/windows/control.ini.bak" "$WABIDIR/windows/control.ini"
            $RM "$WABIDIR/windows/control.src"
            $RM "$WABIDIR/windows/control.ini.bak"
        fi
    fi


    if [ $IFLAG = yes ]
    then
    	# Start wabiprog.i
    	$WABIHOME/bin/wabiprog.i $*
    else 
    	# Start wabiprog
     	$WABIHOME/bin/wabiprog $*
    fi
done

# If user do not choose restart wabi after MS Windows is installed, do merging when wabi exit.
if [ -f "$WABIDIR/windows/control.src" ]
then
    if [ -f "$WABIDIR/windows/control.ini" ]
    then
	$MV "$WABIDIR/windows/control.ini" "$WABIDIR/windows/control.ini.bak"
  	$MERGEFILE "$WABIDIR/windows/control.src" "$WABIDIR/windows/control.ini.bak" "$WABIDIR/windows/control.ini"
      	$RM "$WABIDIR/windows/control.src"
        $RM "$WABIDIR/windows/control.ini.bak"
    fi
fi

exit $?
