#!/bin/ksh -p
#  exp_main: explorer main: variables and command line parsing
#  $Id: //depot/stable/explorer/lib/exp_main#3 $
EXP_MAIN_VERSION='$Revision: #3 $'

if [ -n "${DO_VERSION}" ]
then
    LIB=${0##*/}
    echo "${LIB} version: ${EXP_MAIN_VERSION}"
    exit
fi

# Save HOSTID
HOSTID=`hostid`
export HOSTID EXP_MAIN_VERSION

#
# Set default values for certain variables
#
DIR=${0%/*}
if [ "${DIR}" = "/usr/sbin" ]
then
    EXP_HOME="/"
    EXP_LIB="/usr/lib/explorer"
    EXP_DEFAULTS="/etc/default/explorer"
else
    # Make DIR absolute path
    if [ `echo ${DIR} | cut -c1` != "/" ]
    then
        DIR=`pwd`
    fi
    EXP_ETC="/etc/opt/SUNWexplo"
    EXP_HOME=${DIR%/*}
    EXP_LIB="${EXP_HOME}/lib"
    EXP_DEFAULTS="${EXP_ETC}/default/explorer"
fi
EXP_QUIET=
EXP_LOGFILE=/dev/null
BIN=${0##*/}
USAGE="\n\
${BIN} -version\n\
${BIN} -help\n\n\
${BIN}\n\
\t[ -h <explorer-home> ]\n
\t[ -d <defaults-file> ]\n
\t[ -l <log-file> ]\n
\t[ -e | -mail ]\n
\t[ -E <email-address> | -myemail <email-address> ]\n
\t[ -t <output-directory> | -target <output-directory> ]\n
\t[ -r ]\n
\t[ -R <email-address> ]\n
\t[ -i | -instinfo ]\n
\t[ -k | -keep ]\n
\t[ -f <file> ]\n
\t[ -c <command> ]\n
\t[ -w <module-list> ]\n
\t[ -V | -version ]\n
\t[ -v | -verbose ]\n
\t[ -q | -quiet ]\n
\t[ -C | -case <case-number> ]\n
\t[ -L | -esc <escalation-number> ]\n
\t[ -S | -sn <serial-number> ]\n
\t[ -T | -transport <transport> ]\n
\t[ -D ]\n
\t[ -N ]\n
\t[ -M ]\n
\t[ -iplanet ]\n
\t[ -s <subject> ]\n
"

#
# returns non-zero if all of the components of the ${EXP_WHICH} variable
# are negative (start with a ! character).
#
which_negative_check () {
    for i in `echo ${EXP_WHICH} | sed -e 's/,/ /g'`
    do
	expr "$i" : "^!" >/dev/null || return 0
    done

    # All negative options, assume default
    EXP_WHICH="default,${EXP_WHICH}"
}

#
# generate parse data (README / defaults)
#
gen_parse_data () {
    EXP_SERIAL=`eval echo $"EXP_SERIAL_${HOSTID}"`
    LC_SAVE=${LC_ALL}
    LC_ALL=C

    # Expand EXP_SUBJECT if necessary
    if [ -z "${EXP_SUBJECT}" ]
    then
        EXP_SUBJECT=${EXP_FNAME}
    else
	# Translate %F to EXP_FNAME
	EXP_SUBJECT=`echo ${EXP_SUBJECT} | sed -e "s~%F~${EXP_FNAME}~g"`

	# Translate %C to EXP_CUSTOMER_NAME
	EXP_SUBJECT=`echo ${EXP_SUBJECT} | sed -e "s~%C~${EXP_CUSTOMER_NAME}~g"`

	# Translate %I to EXP_CONTRACT_ID
	EXP_SUBJECT=`echo ${EXP_SUBJECT} | sed -e "s~%I~${EXP_CONTRACT_ID}~g"`

	# Translate %E to EXP_ID
	EXP_SUBJECT=`echo ${EXP_SUBJECT} | sed -e "s~%E~${EXP_ID}~g"`

	# Translate %H to hostid
	EXP_SUBJECT=`echo ${EXP_SUBJECT} | sed -e "s~%H~${HOSTID}~g"`
    fi

    echo "=========== SUN ENTERPRISE(TM) EXPLORER (Version ${EXP_VERSION}) ===========" >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    echo "This directory contains system configuration information. " >> ${EXP_TARGET}/README
    echo "Information was gathered on `date`." >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    echo "Synopsis" >> ${EXP_TARGET}/README
    echo "========" >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    # Regenerate old /etc/default/explorer format
    echo "       Customer Name: ${EXP_CUSTOMER_NAME}" >> ${EXP_TARGET}/README
    echo "         Contract ID: ${EXP_CONTRACT_ID}" >> ${EXP_TARGET}/README
    echo "    Email results to: ${EXP_REPLY}" >> ${EXP_TARGET}/README
    [ -n "${EXP_RECEIPT}" ] && echo "Explorer receipts to: ${EXP_RECEIPT}" >> ${EXP_TARGET}/README
    [ -n "${EXP_SUBJECT}" ] && echo "             Subject: ${EXP_SUBJECT}" >> ${EXP_TARGET}/README
    [ -n "${EXP_NOTIFY}" ] && echo "  Email on data load: ${EXP_NOTIFY}" >> ${EXP_TARGET}/README
    echo "    Modules selected: ${EXP_WHICH}" >> ${EXP_TARGET}/README
    [ -n "${EXP_CASE}" ] && echo "         Case number: ${EXP_CASE}" >> ${EXP_TARGET}/README
    [ -n "${EXP_ESC}" ] && echo "    Escalation number: ${EXP_ESC}" >> ${EXP_TARGET}/README
    echo "   License Agreement: ${EXP_LICENSE}" >> ${EXP_TARGET}/README

    FOUND=""
    if [ -d "${EXP_TARGET}/sc" ]
    then
	for SC in ${EXP_TARGET}/sc/*
	do
	    if [ -d "${SC}" ]
	    then
		if [ -z "${FOUND}" ]
		then
		    echo "SC extended data for:\c" >> ${EXP_TARGET}/README
		    FOUND=notempty
		fi
		HOST=${SC##*/}
		echo " ${HOST}\c" >> ${EXP_TARGET}/README
	    fi
	done
	echo "" >> ${EXP_TARGET}/README
    fi

    FOUND=""
    if [ -d "${EXP_TARGET}/disks/t3" ]
    then
	for T3 in ${EXP_TARGET}/disks/t3/*
	do
	    if [ -d "${T3}" ]
	    then
		if [ -z "${FOUND}" ]
		then
		    echo "T3 extended data for:\c" >> ${EXP_TARGET}/README
		    FOUND=notempty
		fi
		HOST=${T3##*/}
		echo " ${HOST}\c" >> ${EXP_TARGET}/README
	    fi
	done
	echo "" >> ${EXP_TARGET}/README
    fi

    FOUND=""
    if [ -d "${EXP_TARGET}/san" ]
    then
	for SAN in ${EXP_TARGET}/san/*
	do
	    if [ -d "${SAN}" ]
	    then
		if [ -z "${FOUND}" ]
		then
		    echo "SAN switch extended data for:\c" >> ${EXP_TARGET}/README
		    FOUND=notempty
		fi
		HOST=${SAN##*/}
		echo " ${HOST}\c" >> ${EXP_TARGET}/README
	    fi
	done
	echo "" >> ${EXP_TARGET}/README
    fi

    echo "" >> ${EXP_TARGET}/README
    echo "           User Name: ${EXP_USER_NAME}" >> ${EXP_TARGET}/README
    echo "         User e-mail: ${EXP_USER_EMAIL}" >> ${EXP_TARGET}/README
    echo "        User Phone #: ${EXP_PHONE}" >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    echo "System Serial number: ${EXP_SERIAL}" >> ${EXP_TARGET}/README
    echo "      Address line 1: ${EXP_ADDRESS_1}" >> ${EXP_TARGET}/README
    echo "      Address line 2: ${EXP_ADDRESS_2}" >> ${EXP_TARGET}/README
    echo "                City: ${EXP_ADDRESS_CITY}" >> ${EXP_TARGET}/README
    echo "               State: ${EXP_ADDRESS_STATE}" >> ${EXP_TARGET}/README
    echo "             Country: ${EXP_ADDRESS_COUNTRY}" >> ${EXP_TARGET}/README
    echo "            Zip Code: ${EXP_ADDRESS_ZIP}" >> ${EXP_TARGET}/README
    echo "        Country Code: ${EXP_ADDRESS_COUNTRY_CODE}" >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    echo "The following info was collected using UNIX tools (hostname, arch, etc)" >> ${EXP_TARGET}/README
    echo "----------------------------------------------------------------------" >> ${EXP_TARGET}/README
    echo "" >> ${EXP_TARGET}/README
    echo "Date: ${EXP_START}" >> ${EXP_TARGET}/README
    echo "Finished: ${EXP_STOP}" >> ${EXP_TARGET}/README
    echo "Hostname: \c" >>${EXP_TARGET}/README
    hostname >>${EXP_TARGET}/README
    echo "Hostid: \c" >>${EXP_TARGET}/README
    hostid >>${EXP_TARGET}/README
    echo "Release: \c" >>${EXP_TARGET}/README
    uname -r >>${EXP_TARGET}/README
    echo "Kernel architecture: \c" >>${EXP_TARGET}/README
    uname -m >>${EXP_TARGET}/README
    echo "Application architecture: \c" >>${EXP_TARGET}/README
    uname -p >>${EXP_TARGET}/README
    echo "Domain: \c" >>${EXP_TARGET}/README
    domainname >>${EXP_TARGET}/README

    SYSNAME=`prtconf | egrep '^SUNW,'`
    if [ -z "$SYSNAME" ]
    then
	SYSNAME=`prtconf | egrep '^CYRS,'`
    fi
    echo "System Type: $SYSNAME" >> ${EXP_TARGET}/README

    echo "Uptime: `uptime`" >> ${EXP_TARGET}/README

    echo "Swap-s:" >> ${EXP_TARGET}/README
    swap -s >> ${EXP_TARGET}/README

    echo "Swap-l:" >> ${EXP_TARGET}/README
    swap -l 2>&1 >> ${EXP_TARGET}/README

    echo "Vmstat:" >> ${EXP_TARGET}/README
    vmstat >> ${EXP_TARGET}/README

    # Get the input file
    cp ${EXP_DEFAULTS} ${EXP_TARGET}/defaults

    # Get log file if specified
    if [ "${EXP_LOGFILE}" != "/dev/null" ]
    then
        cp ${EXP_LOGFILE} ${EXP_TARGET}/log
    fi

    # Create rev file
    echo "${EXP_VERSION}" > ${EXP_TARGET}/rev
    export LC_ALL=${LC_SAVE}
}

# Clean up function
clean () {
    # Remove tmp files
    rm -rf ${EXP_STDERR} ${EXP_TMPDIR}/*.${EXP_PID}

    # Restore .netrc
    [ -f "/.netrc.${EXP_PID}" ] && mv /.netrc.${EXP_PID} /.netrc

    # Remove explorer_pid file
    if [ -f /tmp/explorer_pid ]
    then
       rm /tmp/explorer_pid
    fi

    if [ "$#" -eq 0 ]
    then
	# Remove output dir
	rm -rf ${EXP_TARGET}

	TEXT=`gettext "Explorer interrupted"`
	logger -p daemon.notice -t explorer "${TEXT}"
	logfile NOTNOISE "${TEXT}"
	exit
    fi
}

#
#  override certain defaults
#
override () {
    # Override certain defaults with appropriate versions
    EXP_VERSION="4.0, FCS"
    EXP_ID="explorer.${HOSTID}.`uname -n`-`date -u +\%Y.\%m.\%d.\%H.\%M`"
    EXP_STARTDIR=`pwd`
}

# Source common functions
. ${EXP_LIB}/exp_common

# Explorer must be run as root 
# Attempt to use /usr/xpg4/bin/id, otherwise use /bin/id
TEXT=`gettext "Must be run as root"`
if [ -x "/usr/xpg4/bin/id" ]
then
    require "test `/usr/xpg4/bin/id -u` -eq 0" "${TEXT}"
else
    require '/bin/id | egrep -s -e "uid=0\("' "${TEXT}"
fi


# read defaults
. ${EXP_ETC}/default/explorer

# Override certain defaults
override

#
# Support for localization
#
TEXTDOMAIN=explorer
if [ "${EXP_HOME}" != "/" ]
then
    TEXTDOMAINDIR="${EXP_LIB}/locale"
fi

# Save original email destination
DEFAULT_EMAIL="${EXP_EMAIL}"
EXP_EMAIL=""

# Set the output target
test -z "${EXP_TARGET}" && {
    if [ "${EXP_HOME}" = "/" ]
    then
        EXP_TARGET="/var/explorer/output/${EXP_ID}"
    else
        EXP_TARGET="${EXP_HOME}/output/${EXP_ID}"
    fi
}   

# Read in Positional Parameters and sort into an array


while [ "$#" -ne 0 ]
do
    case "$1" in
	-version) exp_parms[0]="$1"		# Version
		  ;;
	-V)       exp_parms[1]="$1"		# Version
		  ;;
	-help)    exp_parms[2]="$1"		# Help 
		  ;;
	-i|-instinfo)
	          exp_parms[3]="$1"		# Instinfo
		  ;;
	-d)       exp_parms[4]="$1"		# Defaults file override
		  shift
		  exp_parms[5]="$1"		# Defauts file full pathname
		  ;;
	-h)       exp_parms[6]="$1"		# Home directory override
		  shift
		  exp_parms[7]="$1"		# Home directory full pathname
		  ;;
	-l)       exp_parms[8]="$1"		# Log file signal
		  shift
		  exp_parms[9]="$1"		# Log file full pathname
		  ;;
	-e)       exp_parms[10]="$1"		# Email Flag use default
		  ;;
	-mail)    exp_parms[11]="$1"		# Email Flag use default
		  ;;
	-E)       exp_parms[12]="$1"		# Email flag use specified
		  if [ -z "${exp_parms[13]}" ]
		  then
		    exp_parms[13]="$2"
		  else
		    exp_parms[13]=${exp_parms[13]},"$2"
		  fi
		  shift
		  ;;
	-myemail) exp_parms[14]="$1"		# Email flag use specified
		  if [ -z "${exp_parms[15]}" ]
		  then
		    exp_parms[15]="$2"
		  else
		    exp_parms[15]=${exp_parms[15]},"$2"
		  fi
		  shift
		  ;;
	-t)       exp_parms[16]="$1"		# Output Flag directory override
		  shift
		  exp_parms[17]="$1"		# Output directory full pathname
		  ;;
	-target)  exp_parms[18]="$1"		# Output Flag directory override
		  shift
		  exp_parms[19]="$1"		# Output directory full pathname
		  ;;
	-R)       exp_parms[20]="$1"		# Email receipt flag use specified
		  if [ -z ${exp_parms[21]} ]
		  then 
		    exp_parms[21]="$2"		# Email receipts addresses
		  else
		    exp_parms[21]=${exp_parms[21]},"$2"
		  fi
		  shift
		  ;;
	-r)       exp_parms[22]="$1"		# Email receipt flag use default
		  ;;
	-k)       exp_parms[23]="$1"		# Keep old Explorer outputs
		  ;;
	-keep)    exp_parms[24]="$1"		# Keep old Explorer outputs
		  ;;
	-f)       exp_parms[25]="$1"		# Add specified file for collection
		  if [ -z "${exp_parms[26]}" ]
		  then
		    exp_parms[26]=$2
	          else
	            exp_parms[26]="${exp_parms[26]},$2"
	    	  fi
		  shift
		  ;;
	-c)       exp_parms[27]="$1"		# Add specified command to gather
	          CMD=`echo $2 | sed -e 's/ /%20/g'`
		  if [ -z "${exp_parms[28]}" ]
		  then
		    exp_parms[28]="$CMD"
	          else
	            exp_parms[28]="${exp_parms[28]},$CMD"
	    	  fi
		  shift
		  ;;
	-w)       exp_parms[29]="$1"		# Modules to run Flag
		  shift
		  exp_parms[30]="$1"		# List of modules to include/exclude
		  ;;
	-v)       exp_parms[31]="$1"		# Verbose mode Flag
		  ;;
	-verbose) exp_parms[32]="$1"		# Verbose mode Flag
		  ;;
	-q)       exp_parms[33]="$1"		# Quiet mode Flag
		  ;;
	-quiet)   exp_parms[34]="$1"		# Quiet mode Flag
		  ;;
	-s)       exp_parms[35]="$1"		# Mail Subject Flag use specified
		  shift
		  exp_parms[36]="$1"		# Mail Subject literal
		  ;;
	-case|-C)    exp_parms[37]="$1"		# Case number Flag
		  if [ -z "${exp_parms[38]}" ]
		  then
		    exp_parms[38]="$2"
	          else
	            exp_parms[38]="${exp_parms[38]},$2"
	    	  fi
		  shift
		  ;;
	-esc|-L)     exp_parms[39]="$1"		# Escalation number flag
		  shift
		  exp_parms[40]="$1"		# Escalation number
		  ;;
	-sn|-S)      exp_parms[41]="$1"		# Serial Number Flag use specified
		  shift
		  exp_parms[42]="$1"		# Serial number
		  ;;
	-transport|-T)  exp_parms[43]="$1"		# Transport override flag

		    if [ -z "${exp_parms[44]}" ]
		    then
		      exp_parms[44]=$2
	    	     else
	              exp_parms[44]="${exp_parms[44]},$2"
	    	    fi
	    	    shift
	          ;;
	-D)  exp_parms[45]="$1"
	          ;;

	-N)  exp_parms[46]="$1"
	          ;;

	-M)  exp_parms[47]="$1"
	          ;;

	-iplanet)  exp_parms[48]="$1"
	          ;;

	*)
		 echo $USAGE 
		 exit 1
		 ;;
    esac
    shift
done


# command line options override
typeset -i j
(( j = 0 ))

while (( j <= 49 ))
do
  
#  Following line will echo the paramter number and value to the screen
#  This is useful in debugging issues with exp_main.
#  Uncomment if it is desired.
#  echo  "$j and exp_parm is ${exp_parms[$j]}"
#read

  case ${exp_parms[$j]} in
	-i|-instinfo) 
	
	    $EXP_HOME/bin/instinfo
	    if [ "${?}" -ne 0 ]
	    then exit 1
	    fi
	    ;;

	-d)
	    require "test ${exp_parms[(( $j + 1))]} != -*" "argument ${exp_parms[$j]} requires a file."
	    require "test -f ${exp_parms[(( $j + 1))]}" "argument ${exp_parms[$j]} requires a file."

	    (( j = $j + 1))
	    if [[ ${exp_parms[$j]} != -* ]]
            then
	      EXP_DEFAULTS=${exp_parms[$j]}
	      ORIG_EMAIL=${EXP_EMAIL}

	      if [ -f "${EXP_DEFAULTS}" ]
	      then
		# Read defaults
		. ${EXP_DEFAULTS}

		# Override certain defaults
		override

		# Save original email destination
		if [ -z "${ORIG_EMAIL}" ]
		then
		    DEFAULT_EMAIL=${EXP_EMAIL}
		    EXP_EMAIL=""
		else
		    DEFAULT_EMAIL=${EXP_EMAIL}
		    EXP_EMAIL=${ORIG_EMAIL}
		fi
	      fi
	    fi
	    ;;

	-help)
		 echo $USAGE 1>$2
		 exit 1
		 ;;
	-f)
	    (( j = $j + 1 ))
	    EXP_EXTRA_FILES=${exp_parms[26]}
	    ;;

	-c) 
	    (( j = $j + 1 ))
	    EXP_EXTRA_CMDS=${exp_parms[28]}
	    ;;

	-R)
	    (( j = $j + 1 ))
	    EXP_RECEIPT=${exp_parms[21]}
	    ;;

	-r)
	    if [ -z "${EXP_RECEIPT}" ]
	    then
		EXP_RECEIPT="${EXP_USER_EMAIL}"
            else
                if [ -n "${EXP_USER_EMAIL}" ]
		then
                    EXP_RECEIPT="${EXP_RECEIPT},${EXP_USER_EMAIL}"
		fi
            fi
            ;;

	-E|-myemail)
	    (( j = $j + 1 ))
            if [ -z "${EXP_EMAIL}" ]
            then
                EXP_EMAIL=${exp_parms[$j]}
            else
                EXP_EMAIL="${EXP_EMAIL},${exp_parms[$j]}"
	    fi
	    ;;

	-e|-mail)
       	    if [ -z "${EXP_EMAIL}" ]
	    then
		EXP_EMAIL="${DEFAULT_EMAIL}"
	    else
		EXP_EMAIL="${EXP_EMAIL},${DEFAULT_EMAIL}"
	    fi

	    ;;

	-sn|-S)
	   eval "EXP_SERIAL_${HOSTID}"=${exp_parms[42]}
	    (( j = $j + 1 ))
	   ;;

	-h)

	    EXP_HOME=${exp_parms[7]}
	    EXP_LIB="${EXP_HOME}/lib"
	    EXP_DEFAULTS="${EXP_ETC}/default/explorer"
	    ORIG_EMAIL=${EXP_EMAIL}

	    # Source common functions
	    . ${EXP_LIB}/exp_common

	    # Read defaults
	    . ${EXP_DEFAULTS}

	    # Override certain defaults
	    override

	    # Save original email destination
	    if [ -z "${ORIG_EMAIL}" ]
	    then
		DEFAULT_EMAIL=${EXP_EMAIL}
		EXP_EMAIL=""
	    else
		DEFAULT_EMAIL=${EXP_EMAIL}
		EXP_EMAIL=${ORIG_EMAIL}
	    fi
	    (( j = $j + 1 ))
	    ;;

	-k|-keep)
	    EXP_KEEP=notempty
	    ;;

	-l)
	
	    EXP_LOGFILE=${exp_parms[9]}
	    expr "X${EXP_LOGFILE}" : "X/.*" > /dev/null || \
	    EXP_LOGFILE=${EXP_STARTDIR}/${EXP_LOGFILE}
	    (( j = $j + 1 ))

	    ;;

	-t|-target)

	    if (( ${#exp_parms[17]} > 0 ))
	    then
		EXP_TARGET="${exp_parms[17]}/${EXP_ID}"
	    fi
	
	    if (( ${#exp_parms[19]} > 0 ))
	    then
		EXP_TARGET="${exp_parms[19]}/${EXP_ID}"
	    fi
	    (( j = $j + 1 ))

	    ;;

	-t|-transport)
	#   require "test $# -gt 1" "argument $1 requires option"

	    (( j = $j + 1 ))
            EXP_TRANSPORT=${exp_parms[44]}
	    ;;

	-D)
	    EXP_DELETE=notempty
	    ;;

	-N)
	    EXP_RESEND=notempty
	    ;;
	-M)
	    EXP_NOMIME=notempty
	    ;;
	-w)
	    EXP_WHICH=${EXP_WHICH},${exp_parms[30]}
	    (( j = $j + 1 ))
	    ;;
	-iplanet)
	    EXP_WHICH=${EXP_WHICH},iplanet
	    ;;
	-q|-quiet)
	    EXP_QUIET=notempty
	    ;;

	-v|-verbose)
	    EXP_VERBOSE=notempty
	    ;;

	-C|-case)
	    EXP_CASE=${exp_parms[38]}
	    (( j = $j + 1 ))
	    ;;

	-L|-esc)
	    EXP_ESC=${exp_parms[40]}
	    (( j = $j + 1 ))
	    ;;

	-s)
	    EXP_SUBJECT=${exp_parms[36]}
	    (( j = $j + 1 ))
	    ;;

	-V|-version)
		echo "Explorer version: ${EXP_VERSION}" 1>&2
		DO_VERSION=notempty
		export DO_VERSION
		for lib in ${EXP_LIB}/exp_*
            do
			 ${lib}
            done
            exit 1
            ;;
	
	"") ;;
	    
	*) echo "Nothing recoginized ${exp_parms[$j]}"
	   echo "press return to continue"
	   read
	    ;;
	
    esac
    (( j = $j + 1 ))
done

# Update TRANSPORT with EXP_EMAIL addresses
for i in `echo ${EXP_EMAIL} | sed -e 's/,/ /g'`
do
    if [ -z "${EXP_TRANSPORT}" ]
    then
        EXP_TRANSPORT="mailto:$i"
    else
        EXP_TRANSPORT="${EXP_TRANSPORT},mailto:$i"
    fi
done

# Set EXP_TMPDIR based on TARGET
EXP_TMPDIR=${EXP_TARGET%/*}/

which_negative_check

# Translate spaces to %20
EXP_EXTRA_CMDS=`echo ${EXP_EXTRA_CMDS} | sed -e 's/ /%20/g'`

# Make variables available
export EXP_STARTDIR EXP_HOME EXP_TARGET EXP_ID EXP_WHICH
export EXP_OPTIONS_DONE EXP_FILE_MAX_SIZE EXP_EXTRA_CMDS
export EXP_EXTRA_FILES EXP_EMAIL_SPLIT EXP_MAIN_VERSION
export EXP_VERSION EXP_STDERR EXP_EMAIL EXP_KEEP EXP_GEO
export EXP_FILE_HEAD_LINES EXP_FILE_TAIL_LINES EXP_FILE_PATTERNS
export EXP_QUIET EXP_VERBOSE EXP_LOGFILE EXP_TRANSPORT EXP_CASE
export EXP_CUSTOMER_NAME EXP_CONTRACT_ID EXP_SERIAL EXP_RECEIPT
export EXP_USER_NAME EXP_USER_EMAIL EXP_PHONE
export EXP_ADDRESS_1 EXP_ADDRESS_2 EXP_ADDRESS_CITY
export EXP_ADDRESS_STATE EXP_ADDRESS_ZIP EXP_ADDRESS_COUNTRY
export EXP_TMPDIR EXP_SUBJECT EXP_DELETE EXP_RESEND EXP_NOMIME
export EXP_ADDRESS_COUNTRY_CODE EXP_J2SE EXP_IPLANET
