#!/bin/sh
# @(#)wabi	2.171	08 Feb 1996
#
#	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-96, 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.

#
# Define internationalized "echo" replacement routine
#

msgprint(){
	eval echo "\"`TEXTDOMAINDIR=$WABIHOME/lib/locale TEXTDOMAIN=wabi gettext \"$1\"`\""
}

__WABI_ORIG_PATH=$PATH
PATH=/usr/bin:/bin:$PATH
export PATH

# Definitions
FILE_CHECK=/etc/.vold.wabi
WABIVERSION=2.2Beta2

#
# WABIFCS is used to determine if the current Wabi package is an FCS release.
# It is set to 0 if ${WABIVERSION} contains "alpha", "beta", or "wip".
# Otherwise, it is set to 1, indicating an FCS release.  We only invoke the
# survey tool for non-FCS releases, while the registration card is for Wabi FCS.
#
# The Makefile in $SRC/unixsrc/solaris/pkg also does a similar check on
# the value of $WABIVERSION, to determine whether to include filebug.exe and
# surveys.exe in the prototype file for packaging, which is only for non-FCS.
#

echo ${WABIVERSION} | egrep -i "alpha|beta|wip" > /dev/null 2>&1
WABIFCS=$?


#
# Invoke wabiprog with the "-c" option for non-FCS releases
#

if [ $WABIFCS -ne 1 ]
then
    WABIFLAGS="-c"
fi


chase_symlink()
{

#   To check for a symlink, use the test "-h" switch for all platforms 
#   except AIX, which only supports the "-L" switch. 
 
    if [ "`$UNAME`" = "AIX" ] 
    then 
	TEST_SYMLINK="-L" 
    else
	TEST_SYMLINK="-h" 
    fi

#   is the command a symlink?

    if [ $TEST_SYMLINK "$COMMAND" ]
    then

        FILE="/bin/file -h"

#	strip off the uninteresting stuff, leaving the path to the real file
	NEW_PATH=`$FILE $COMMAND|/bin/sed -e 's/.*://'|/bin/sed -e 's/symbolic link to//'`

	echo $NEW_PATH
    else
	echo $COMMAND
    fi
}

# Commands
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/ln ]; then
	LN="/usr/bin/ln -s"
else
	LN="/bin/ln -s"
fi

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

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

# start getting system information...
SYSTEM_OS_NAME="`uname`"
SYSTEM_OS_REL="`uname -r`"
SYSTEM_HW_NAME="`uname -m`"
SYSTEM_NODE_NAME="`uname -n`"


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

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

# Determine WABIDIR
WABIDIR=${WABIDIR:-"$HOME/wabi"}
export WABIDIR

# Record the starting point so we can return after determining WABIHOME.
INITIAL_DIR=`pwd`

# Determine PWD for those shells that don't have it
PWD=${PWD:-"$INITIAL_DIR"}
export PWD

# Find out where this script lives to determine WABIHOME.

if [ "$SYSTEM_OS_NAME" = "SCO_SV" ]
then
	COMMAND=$0

	# see if the command is a symbolic link and chase it if necessary
	COMMAND="`chase_symlink`"

	FROM_PATH=`echo "$COMMAND" | grep "/"`

	if [ -n "$FROM_PATH" ]
	then
		#in this case $COMMAND is a directory component.
		FIRSTARG=`echo ${FROM_PATH} | awk -F/ '{ print $1 }'`
 
		if [ -z "$FIRSTARG" ]
		then
			SOURCE3=`echo ${COMMAND} | awk -F/ '{ for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
		else
			SOURCE3=`echo ${COMMAND} | awk -F/ '{ if ($1 == "") printf "/"; for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
		fi
	else
		#in this case $COMMAND is not a directory component.
		SOURCE3="./"
	fi
 
	cd "$SOURCE3"
	cd ..
else
cd "`dirname $0`/.."
fi

WABIHOME=`pwd`
export WABIHOME

#
# setup platform dependent wabiprog file extension
#

ARCH_EXT=""
if [ -f $WABIHOME/bin/wabiplatform -a ! -z "`echo $SYSTEM_HW_NAME | grep sun`" ]
then	
	echo "install_utrap=X" | adb /lib/libc.so.1 > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
        	ARCH_EXT=`$WABIHOME/bin/wabiplatform -e`
	fi
fi

if [ "$SYSTEM_OS_NAME" = "SunOS" ]
then
	# -
	# check to see if /etc/vold.conf should change.
	# -
	#
	# if this is not already fixed...
	#
	if [ ! -f $FILE_CHECK ]
	then
  	  #
	  # only change 5.4  and 5.5 systems (should we do this?)
	  #
	  if [ "$SYSTEM_OS_REL" = "5.4" -o "$SYSTEM_OS_REL" = "5.5"  -o "$SYSTEM_OS_REL" = "5.5.1" ]
	  then
	    #
	    # only do this is they have a floppy
	    #
	    if [ -c /dev/rdiskette ]
	    then
	      # 
	      # are they even running vold?
	      #

	      PID=`ps -ef | grep /usr/sbin/vold | grep -v grep | nawk '{ print $2 }'`

	      if [ ! -z "$PID" ]
	      then
	        #
	        # 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)
	            } 
	        '

	        if [ "$?" = "1" ]	# if we have found the line to change
	        then
		  msgprint '
To use your diskette drive under Wabi, we recommend that you
disable control of the diskette drive by Volume Manager. To do
this, enter the following command as superuser:
	$WABIHOME/lib/vold.switch -disable

See the Wabi 2.2 Release Notes for more detailed information.
' 1>&2
		fi
	      fi
	    fi
          fi
	fi
fi

# Check for adequate swap space to start Wabi.
case "$SYSTEM_OS_NAME" in
	
	SunOS )
   	        SWAPS=`$SWAP`
    		SWAPAVAIL=`echo ${SWAPS} | sed -e 's/.*, //' -e 's/k.*//'`
    		if [ -z "$SWAPAVAIL" ]
    		then
		    SWAPAVAIL=0
		fi

# Physical memory space recommended to run wabi, Sparc: 32M bytes; i86: 24M bytes
		if [ "$SYSTEM_HW_NAME" -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
				msgprint 'Warning: The memory size is less than $MEMREQD Mbytes recommended for Wabi.
Warning: Wabi performance may be affected.' 1>&2
		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
			msgprint 'There may not be enough swap space on your system to run the wabi software.
$SWAPAVAIL 512 byte blocks are available, $SWAPREQD Kbytes are required.
To increase the amount of swap space, see your system administrator.
Swap space can be increased through the use of the swap and marry commands.' 1>&2
			SWAPAVAIL=$SWAPREQD
    	fi
		;;

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

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

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

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

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


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

    if [ "$SYSTEM_OS_NAME" = "SCO_SV" ]
    then
    	WABIDIRAVAIL=`echo ${DISKFREE} | awk -F" " '{ print $4 }'`
	WABIDIRAVAIL=`expr ${WABIDIRAVAIL} / 2`
    else
    	WABIDIRAVAIL=`echo ${DISKFREE} | cut -f11 -d" "`
    fi

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

#
#	write some system information into ~/wabi 
#

if [ -w $WABIDIR ] 
then
	/bin/rm -f $WABIDIR/sysinfo.txt
	(
		echo "USER: `id | cut -f2 -d'(' | /bin/sed -e 's/).*//`"
		echo "HOST: $SYSTEM_NODE_NAME"
		echo "DISPLAY: $DISPLAY"
		echo "OS: $SYSTEM_OS_REL"
		echo "ARCH: $SYSTEM_HW_NAME"
		case "$SYSTEM_OS_NAME" in
		    SunOS )
			echo "FB: `/bin/file -h /dev/fb|/bin/sed -e 's/.*://'`"
			echo "MEMORY: ${MEMAVAIL}MB"
			echo "SWAP: `expr ${SWAPAVAIL} / 1024`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"
WABIMERGEFILE="$WABIHOME/lib/mergefile"
export WABIMERGEFILE


# 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"
    touch "$WABIDIR/new.tmp"
    __WABIDIR_UPDATE="yes"
else
    CURVERSION="`grep Config= $WABIDIR/windows/wabi.ini`"
    CURVERSION=`expr "$CURVERSION" : '.*=\([1-9][0-9\.]*.*\)[
]$'`
  
    if [ "$CURVERSION" = "$WABIVERSION" ]
    then
	# Put this condition only for testing.
    	MERGEFLG=`echo ${WABIMERGE}`
    	if [ -n "$MERGEFLG" -a  "$MERGEFLG" = "1" ]
	then
	    MERGE="yes"
	    __WABIDIR_UPDATE="yes"
        else
	    MERGE="no"
    	fi
    else
	MERGE="yes"
        __WABIDIR_UPDATE="yes"
    fi

    # Check if windows is installed.
    if [ -f "$WABIDIR/windows/system/setup.inf" ]
    then
        __WABI_MSWIN_VER="`grep MS_Win= $WABIDIR/windows/wabi.ini`"
        __WABI_MSWIN_VER=`expr "$__WABI_MSWIN_VER" : '.*=\([A-Z][a-z\.]*.*\)[
]$'`
    fi

# If we're PowerPC-Solaris, make certain our wabi.ini has the new section added
if [ "$SYSTEM_HW_NAME" = "prep" -a "$SYSTEM_OS_NAME" = "SunOS" ]
then
    PPCSECTION="`grep PowerPC $WABIDIR/windows/wabi.ini`"
    if [ -z "$PPCSECTION" ]
    then
            MERGE="yes"
            __WABIDIR_UPDATE="yes"
    fi
 fi

    if [ "$MERGE" = "yes" ]
    then
        echo "$CURVERSION" >"$WABIDIR/upgrade.tmp"
	mv "$WABIDIR/windows/wabi.ini" "$WABIDIR/windows/wabi.ini.$WABIVERSION"
	$WABIMERGEFILE -P "$WABIDIR/windows/wabi.ini.$WABIVERSION" "$WABIHOME/wbin/wabi.ini" "$WABIDIR/windows/wabi.ini"
	msgprint 'Saving existing wabi.ini to wabi.ini.$WABIVERSION and updating wabi.ini.' 1>&2
    fi
fi


if [ -z "$__WABI_MSWIN_VER" ]
then
    __WABI_NEW_SHELL="win_inst"
fi

#
# Define subroutines
#

Add_DoRegSync_Yes()
{
# add the entry "WabiDoRegSync=Yes" to the "ShellData" section of wabi.ini.
# This will turn on the RegSync mechanism in the Windows Installer.

    sed '/[Ww][Aa][Bb][Ii][Dd][Oo][Rr][Ee][Gg][Ss][Yy][Nn][Cc]/d' "$WABIDIR/windows/wabi.ini" > "$WABIDIR/windows/wabi.ini.tmp" 
    $RM "$WABIDIR/windows/wabi.ini"
    sed '/^\[[Ss][Hh][Ee][Ll][Ll][Dd][Aa][Tt][Aa]\]/a\
WabiDoRegSync=Yes
' "$WABIDIR/windows/wabi.ini.tmp" > "$WABIDIR/windows/wabi.ini" 
    $RM "$WABIDIR/windows/wabi.ini.tmp"
}



#
# Define subroutines end
#

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

    if [ "$SYSTEM_OS_NAME" = "SunOS" -a ${WABIFCS} -eq 1 ]
    then
        __WABI_NEW_SHELL="regiwabi"
    fi
else
    if [ "$MERGE" = "yes" ]
    then
	mv "$WABIDIR/windows/system.ini" "$WABIDIR/windows/system.ini.$WABIVERSION"
	$WABIMERGEFILE -P "$WABIDIR/windows/system.ini.$WABIVERSION" "$WABIHOME/wbin/system.ini" "$WABIDIR/windows/system.ini"
	msgprint 'Saving existing system.ini to system.ini.$WABIVERSION and updating system.ini.' 1>&2
        if [ "$SYSTEM_OS_NAME" = "SunOS" -a ${WABIFCS} -eq 1 ]
	then

	    # make the windows install program sync up registration databases
	    # from the previous wabi version.
	    Add_DoRegSync_Yes

            __WABI_NEW_SHELL="regiwabi"
	fi
    fi
fi

if [ -n "$__WABI_NEW_SHELL" ]
then
  # the following SED command deletes any line starting with (case-insensitive)
  # "shell=" within the set of lines that start with the line starting with
  # (case-insensitive) "[boot]" and ending (inclusive) with the next line
  # starting with "[".

    sed '/^\[[Bb][Oo][Oo][Tt]\]/,/^\[/{
/^[Ss][Hh][Ee][Ll][Ll]\=/d
}' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp" 
    $RM "$WABIDIR/windows/system.ini"
    mv "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	

  # the following SED command appends the line "shell=regiwabi.exe" or
  # "shell=win_inst.exe" after a line starting with (case-insensitive)
  # "[boot]".

    if [ "$__WABI_NEW_SHELL" = "regiwabi" ]
    then
	sed '/^\[[Bb][Oo][Oo][Tt]\]/ a\
shell\=regiwabi\.exe
' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp"
    else
        sed '/^\[[Bb][Oo][Oo][Tt]\]/ a\
shell\=win\_inst\.exe
' "$WABIDIR/windows/system.ini" > "$WABIDIR/windows/system.tmp"
    fi

    $RM "$WABIDIR/windows/system.ini"
    mv "$WABIDIR/windows/system.tmp" "$WABIDIR/windows/system.ini"	    
fi


if [ -n "$__WABIDIR_UPDATE" -a "$__WABIDIR_UPDATE" = "yes" ]
then
    . "$WABIHOME/lib/wabidirupdate"
    echo ""
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


if [ "$SYSTEM_OS_NAME" = SunOS ]
then
    WABIDRV_INSTALLED=`grep wabi /etc/driver_aliases`
	
    if [ -z "$WABIDRV_INSTALLED" ]
    then
	 # Test if wabi is installed in the local machine.
	 WHICHWABI="S`echo ${WABIHOME} | cut -f2 -dS`"
    	 LOCALWABI="`pkginfo | grep $WHICHWABI`"

	if [ -z "$LOCALWABI" ]
    	then
	    # Wabi is not installed in local machine
	    msgprint 'Warning: Package $WHICHWABI is not installed in this machine.
Run $WABIHOME/bin/wabiclientinstall as root to update
the desktop environment.' 1>&2
	    exit 1
  	else
	    # Wabi is installed in local mechine but driver is not installed.
	    msgprint 'Warning: The Wabi kernel driver is not installed.
Run $WABIHOME/drvr/wabiload as root to install the driver.' 1>&2
	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 [ "$SYSTEM_OS_REL" = "5.2" ]
then
    if [ ! -f /usr/lib/libvolmgt.so.1 ]
    then
	msgprint '
The Volume Manager patch should be installed on Solaris 2.2, otherwise
Wabi may not be able to use the diskette drive.
' 1>&2
    fi
fi

# Go to start point
cd "$INITIAL_DIR"

#setup arguments
IFLAG="no"
if [ $# != 0 ]
then
	FIRSTFLAG=`echo $* | cut -f1 -d' '`
	# echo $FIRSTFLAG
	if [ $FIRSTFLAG = -i ]
	then
		IFLAG="yes"
	fi

	# make sure this and all children show up on the right display
	num=0
	for arg in $*
	do
	    if [ "$arg" = "-display" ]
	    then
	      eval DISPLAY=$`expr "$num" + 2`
	      break
	    fi
	    num=`expr "$num" + 1` 2>&-
	done
fi

export DISPLAY
	

# 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 this is a non-FCS Solaris release, invoke the survey tool if more 
# than a week has passed since its last invocation.
#

if [ ${WABIFCS} -ne 1 -a ${SYSTEM_OS_NAME} = "SunOS" ]
then

    if [ -f $WABIDIR/.surveystamp ]
    then

	#
	# If there is an existing .surveystamp and its more than a week
	# old, then run the survey tool and reset the survey time stamp.
	#

        if [ "`find $WABIDIR/.surveystamp -mtime +6 -print`" != "" ]
        then

	    $RM    $WABIDIR/.surveystamp
	    touch  $WABIDIR/.surveystamp

	    (	sleep 30                	# wait until wabiprog starts
		$WABIHOME/bin/wabiprog${ARCH_EXT} -s c:\\wabihome\\wbin\\surveys.exe
	    )   >/dev/null 2>&1 &

        fi

    else

	#
	# For a new $WABIDIR, create a time stamp file for the survey tool.
	# During a non-FCS release, we check this file and start the survey
	# tool if it more than a week old.
	#

        touch $WABIDIR/.surveystamp

    fi

fi
 


if [ "$IFLAG" = "yes" ]
then
    shift 1
    # Start wabiprog.i
    PATH=$__WABI_ORIG_PATH $WABIHOME/bin/wabiprog.i  $WABIFLAGS $*
else 
    # Start wabiprog
    PATH=$__WABI_ORIG_PATH $WABIHOME/bin/wabiprog${ARCH_EXT} $WABIFLAGS $*
fi
WABI_RETURN_VAL=$?


# Restart Wabi automatically
while [ $WABI_RETURN_VAL = 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.$WABIVERSION"
    	    $WABIMERGEFILE -P "$WABIDIR/windows/control.src" "$WABIDIR/windows/control.ini.$WABIVERSION" "$WABIDIR/windows/control.ini"
            $RM "$WABIDIR/windows/control.src"
            $RM "$WABIDIR/windows/control.ini.$WABIVERSION"
        fi
    fi

    if [ "$IFLAG" = "yes" ]
    then
    	# Start wabiprog.i
        PATH=$__WABI_ORIG_PATH $WABIHOME/bin/wabiprog.i $WABIFLAGS $*
    else 
    	# Start wabiprog
        PATH=$__WABI_ORIG_PATH $WABIHOME/bin/wabiprog${ARCH_EXT} $WABIFLAGS $*
    fi
    WABI_RETURN_VAL=$?
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.$WABIVERSION"
  	$WABIMERGEFILE -P "$WABIDIR/windows/control.src" "$WABIDIR/windows/control.ini.$WABIVERSION" "$WABIDIR/windows/control.ini"
      	$RM "$WABIDIR/windows/control.src"
        $RM "$WABIDIR/windows/control.ini.$WABIVERSION"
    fi
fi

exit $WABI_RETURN_VAL


