#!/bin/sh
# $Id: configure,v 1.10 2002/09/14 17:45:38 sirott Exp $

PATH="$PATH:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/bin:/opt/local/bin";
export PATH
search_dirs="`echo $PATH | sed '1,$s/:/ /g'`"


#
# Function to return a real, live executable
#
getExecutable() {
    execloc=
    autoexecloc="$3"
    if [ -z "$autoexecloc" ]
    then
        for i in $search_dirs
  	do
  	    if [ -f $i/$1 -a -x $i/$1 ] 
  	    then
  		autoexecloc="$i/$1"
  		break
  	    fi
  	done
  	echo "Searching for $1..."
  	if [ -z "$autoexecloc" ] 
  	then
  	    echo "Can't find $1"
  	fi
    fi
    until [ -n "$execloc" ]
    do
  echo ""
	echo -n "Location of $2 executable [$autoexecloc] "
	read execloc
	if [ -z "$execloc" ] 
	then
	    execloc="$autoexecloc"
	fi
	if [ ! -f "$execloc" -o ! -x "$execloc" ]
	then
	    echo "$execloc is not an executable file"
	    execloc=""
	fi
    done
}

if [ ! -z "$1" -a "$1" != "-noui" ]
then
    echo "Usage: configure [-nocompare]"
    exit 1
fi

#
# Get perl
#
default_perl=""
if [ -f "config.results" ]
then
    default_perl=`grep 'LasConfig{perl}' config.results | awk '{print $3}' | sed "1,1s/[\'\;]//g"`
fi
getExecutable perl perl $default_perl
perlloc="$execloc"

until [ "$answer" = "yes" -o "$answer" = "no" ]
do
echo "This script will configure LAS and the new Version 7.0 UI."  
echo "If you want you can install the old version 6.x UI at the same time."
echo -n "Do you want to install the old LAS version 6.x user interface (yes or no)? "
read answer
done

if [ "$answer" = "yes" ]
then
   echo "Starting Perl configuration script with $perlloc..."
   exec $perlloc ./configure.pl $perlloc $*
fi
if [ "$answer" = "no" ]
then
   echo "Starting Perl configuration script with $perlloc..."
   exec $perlloc ./configure7.pl $perlloc $*
fi

    
