#
#  request script for explorer3
#  $Id: //depot/stable/explorer/pkg/request#3 $
#
AMER=explorer-database-americas@sun.com
APAC=explorer-database-apac@sun.com
EMEA=explorer-database-emea@sun.com


#
#  Functions
#
prompt () {
    VAR=$"$1"
    VAL=`eval echo ${VAR}`

    # Display prompt
    echo "$2"
    echo "[${VAL}]: \c"

    # Read response
    read ANSWER

    # Accept crlf as default
    if [ -z "${ANSWER}" ]; then
	ANSWER=${VAL}
    fi

    # Set (or unset) variable
    eval "$1=\"${ANSWER}\""
    if [ "${ANSWER}" = '-' ]; then
	eval "unset $1"
    fi
}

yorn () {
    VAR=$"$1"

    while :
    do
	# Display prompt
	echo "$2"
	echo "[y,n] \c"

	# Read response
	read ANSWER

	# Acceptable responses are y|yes|n|no
	case `echo "${ANSWER}" | tr '[A-Z]' '[a-z]'` in
	    yes | y)
		ANSWER=yes
		break
		;;
	    no | n)
		ANSWER=no
		break
		;;
	    *)
		echo "Please answer y, yes, n or no"
		continue
		;;
	esac

    done

    # Set variable
    eval "$1=\"${ANSWER}\""
}

validate () {
    VAR=$"$1"
    VAL=`eval echo ${VAR}`
    CNT="-1"

    while [ "${CNT}" -lt "$2" -o "${CNT}" -gt "$3" ]
    do
	# Display prompt
	echo "$4"
	if [ -n "${VAL}" ]; then
	    echo "[${VAL}]: \c"
	fi

	# Read response
	read ANSWER

	# Accept clrf if default value exists
	if [ -z "${ANSWER}" ] && [ -n "${VAL}" ]; then
	    ANSWER=${VAL}
	fi

	if echo "${ANSWER}" | egrep -s -e "^[0-9]+$"
	then
	    # numeric answer
	    CNT="${ANSWER}"
	elif [ "${ANSWER}" = "*" ]
	then
	    # "*" answer
	    CNT="${ANSWER}"
	else
	    echo "${ANSWER} is not a valid number"
	    CNT="-1"
	fi

	# Accept * as response, do not return to loop
	if [ "${ANSWER}" = "*" ]
	then
	    break
	fi
    done

    # Set variable
    eval "$1=\"$CNT\""
}
##############################################################
get_geo () {
#  Set default to AMERICAS
  # display the list of geos
  cat <<!

Please select your geo from this list -

1) AMERICAS 
2) EMEA
3) APAC

[AMERICAS]
!

  # get the geo from the user ( set the default for the return key )
  read geo 
  if [ -z "$geo" ]
  then
    geo="1"
  fi

  # validate the user input and put up the corresponding country list
  # to get the country.
  ok="no"
  while [ "${ok}" = "no" ]
  do 
    case "$geo" in 
      "1" | "AMERICAS" ) ok="yes" ; GEO=AMERICAS ; MAIL=${AMER};;
      "2" | "EMEA"     ) ok="yes" ; GEO=EMEA ; MAIL=${EMEA};;
      "3" | "APAC"     ) ok="yes" ; GEO=APAC ; MAIL=${APAC};;
                      *) get_geo ;;
    esac
  done
echo ${GEO}
# Set variable
eval "$1=\"$GEO\""
eval "$2=\"$MAIL\""
}

###########################################################################
get_country () {
  DONE=FALSE
  COUNTRY_CODE=
  while [ ${DONE} != TRUE ]
  do
    echo "Please Enter the two character Country code or enter ? for a list of countries."
    echo "[${COUNTRY_CODE}]:\c"
    read COUNTRY_CODE
    if [ -z "${COUNTRY_CODE}" ]
      then 
      echo "No country entered."
      else
        if [ "${COUNTRY_CODE}" = "?" ]
         then
         if [ "${GEO}" = "AMERICAS" ]
           then
           for X in 1 2 3 
           do
             cat $INST_DATADIR/SUNWexplo/install/${GEO}_countries.$X
             echo "Press Enter for more countries or q to quit list and enter a country code."
             read RESPONSE 
             if [ "${RESPONSE}" = "q" -o "${RESPONSE}" = "Q" ]
               then
               break
	     fi
            done
         fi
         if [ ${GEO} = "APAC" ]
           then
           for X in 1 2 3 4
           do
             cat $INST_DATADIR/SUNWexplo/install/${GEO}_countries.$X
             echo "Press Enter for more countries or q to quit list and enter a country code."
             read RESPONSE 
             if [ "${RESPONSE}" = "q" -o "${RESPONSE}" = "Q" ]
               then
               break
             fi
           done
         fi
         if [ ${GEO} = "EMEA" ]
           then
           for X in 1 2 3 4 5 6 7 8
           do
             cat $INST_DATADIR/SUNWexplo/install/${GEO}_countries.$X
             echo "Press Enter for more countries or q to quit list and enter a country code."
             read RESPONSE 
             if [ "${RESPONSE}" = "q" -o "${RESPONSE}" = "Q" ]
               then
               break
             fi
           done
         fi
       else
       COUNTRY_CODE="${COUNTRY_CODE} "
       grep -s -i "^$COUNTRY_CODE" $INST_DATADIR/SUNWexplo/install/${GEO}_countries_codes
       if [ ${?} = "0" ]
         then
         DONE=TRUE
         COUNTRY_CODE=`grep -s -i "^$COUNTRY_CODE" $INST_DATADIR/SUNWexplo/install/${GEO}_countries_codes|cut -c1-2`
         COUNTRY=`grep -s -i "^$COUNTRY_CODE" $INST_DATADIR/SUNWexplo/install/${GEO}_countries_codes | cut -c5-50`
         else
         echo "${COUNTRY_CODE} is not a valid country in this geo."
       fi
     fi
   fi
done
# Set Variable
eval "$1=\"$COUNTRY\""
eval "$2=\"$COUNTRY_CODE\""
}
##############################################################

# Start Main Script
# Get version of package
pkginfo -l -q SUNWexplo.\*
if [ ${?} = "0" ]
then
  UPGR_SCRIPT=/var/tmp/upgr_${PKGINST}
  OldPkgVers=`pkginfo -l SUNWexplo.\*|grep VERSION: |nawk -F: '{ print $2 }'`
  if [ -n ${OldPkgVers} ]
  then
    OldPkg=`pkginfo -v "${OldPkgVers}" -x SUNWexplo.\* |nawk '/SUNW/{print $1}'`
    /usr/bin/echo "A version of SUNWexplo is installed."
    /usr/bin/echo "It will be replaced with this version."
    /usr/bin/echo "PATH=/usr/sadm/bin:${PATH}" > ${UPGR_SCRIPT}
    /usr/bin/echo "sleep 3" >> ${UPGR_SCRIPT}
    /usr/bin/echo "#Old Pkg Version is OldPkgVers: ${OldPkgVers}" >> ${UPGR_SCRIPT}
    /usr/bin/echo "echo Now removing old instance of SUNWexplo" >> ${UPGR_SCRIPT}
    /usr/bin/echo "pkgrm -a exp_admin -n ${OldPkg}" >> ${UPGR_SCRIPT}
    /usr/bin/echo "/usr/bin/rm ${UPGR_SCRIPT}" >> ${UPGR_SCRIPT}
    /usr/bin/cp ${UPGR_SCRIPT} /var/tmp/upgr.SUNWexplo.view
  else
    echo "request: Value of OldPkgVers is null."
  fi
else
  echo "Package ${PKGINST} not yet installed."
fi

# Software Agreement
# Software Agreement
yorn EXP_LICENSE "
SUN MICROSYSTEMS, INC.

SOFTWARE LICENSE AGREEMENT

SUN IS WILLING TO LICENSE THE ACCOMPANYING SOFTWARE TO YOU ONLY UPON THE 
CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS LICENSE AGREEMENT. 
READ THE TERMS AND CONDITIONS OF THIS LICENSE CAREFULLY BEFORE DOWNLOADING THE 
SOFTWARE. BY DOWNLOADING AND OR USING THE SOFTWARE, YOU AGREE TO THE TERMS AND 
CONDITIONS OF THIS AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS 
AGREEMENT, YOU ARE NOT AUTHORIZED TO DOWNLOAD OR USE THIS SOFTWARE.

1. License to Use. Customer is granted a royalty-free non-exclusive and 
non-transferable license (\"License\") for the use of the accompanying software, 
together with accompanying documentation, if any, (\"Software\"), only in 
combination with the specific software previously licensed by you from Sun with 
which this Software is intended to operate.  No other use or distribution of the
Software is authorized.

2. Restrictions. Software is copyrighted and title to all copies is retained by
Sun and/or its licensors. Customer shall not make copies of the Software, other
than as authorized above plus a single copy for archival purposes and, if
applicable, Customer may, for its internal use only, print the number of copies
of on-line documentation, if any, for which it has been authorized, in which
event all proprietary rights notices on the Software shall be reproduced and
applied. Unless enforcement of this provision is prohibited by applicable law,
Customer shall not modify, decompile, disassemble, decrypt, extract, or
otherwise reverse engineer the Software. The Software is not designed or
licensed for use in on-line control equipment in hazardous environments such
as operation of nuclear facilities, aircraft navigation or control, or direct
life support machines. 

3. Confidentiality. The Software is confidential and proprietary information of 
Sun and/or its licensors. Customer agrees to take adequate steps to protect the 
Software from unauthorized disclosure or use.

4. Disclaimer of Warranty. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT A WARRANTY 
OF ANY KIND. EXCEPT AS SPECIFIED IN THIS LICENSE, ALL EXPRESS OR IMPLIED 
CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE 
HEREBY EXCLUDED TO THE EXTENT ALLOWED BY APPLICABLE LAW.

5. Limitation of Liability. IN NO EVENT WILL SUN BE LIABLE FOR ANY LOST REVENUE,
PROFIT OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 
DAMAGES HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY ARISING OUT OF 
THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGES.  IN NO EVENT WILL SUN BE LIABLE FOR ANY DAMAGES, 
REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO
USE THE SOFTWARE, WHICH ARE GREATER THAN THE  ACTUAL PURCHASE PRICE CUSTOMER 
PAID TO SUN FOR SUCH SOFTWARE.

6. Termination. This License is effective until terminated. Customer may 
terminate this License at any time by destroying all copies of the Software 
including any documentation.  This License will terminate immediately without 
notice from Sun if Customer fails to comply with any provision of this License. 
Upon termination, Customer must destroy all copies of the Software.

7. Export Regulations. The Software, including technical data, is subject to 
U.S. export control laws, including the U.S. Export Administration Act and its 
associated regulations, and may be subject to export or import regulations in 
other countries. Customer agrees to comply strictly with all such regulations 
and acknowledges that it has the responsibility to obtain licenses to export, 
re-export, or import the Software.

8. U.S. Government Restricted Rights. If Customer is acquiring the Software 
including accompanying documentation, if any, on behalf of the U.S.  Government,
the following provisions apply. If the Software is supplied to the Department of
Defense (\"DOD\"\), the Software is subject to \"Restricted Rights\", as that term is
defined in the DOD Supplement to the Federal Acquisition Regulations (\"DFAR\") in
paragraph 252.227-7013(c) (1). If the Software is supplied to any unit or agency
of the United States Government other than DOD, the Government's rights in the 
Software will be as defined in paragraph 52.227-19(c) (2) of the Federal 
Acquisition Regulations (\"FAR\"). Use, duplication, reproduction or disclosure by
the Government is subject to such restrictions or successor provisions. 
Contractor/Manufacturer is: Sun Microsystems, Inc., 2550 Garcia Ave., Mountain 
View, CA 94043.

9. Governing Law. This Agreement is made under, shall be governed by and 
construed in accordance with the laws of the State of California, U.S.A., 
excluding its choice of law provisions.

10. Severability. If any of the above provisions are held to be in violation of 
applicable law, void, or unenforceable  in any jurisdiction, then such 
provisions are herewith waived to the extent necessary for the License to be 
otherwise enforceable in such jurisdiction,   However, if in Sun's opinion 
deletion of any provisions of the License by operation of this paragraph  
unreasonably compromises the rights or liabilities of Sun or its licensors, Sun 
reserves the right to terminate the License and require the destruction or 
return of the Software.

11. Integration. This Agreement is the entire agreement between Customer and Sun
relating to this Software and: (i) supersedes all prior or contemporaneous oral 
or written communications, proposals and representations with respect to its 
subject matter; and (ii) prevails over any conflicting or additional terms of 
any quote, order, acknowledgment, or similar communication between the parties 
during the term of this Agreement. No modification to the Agreement will be 
binding, unless in writing and signed by a duly authorized representative of 
each party.

Agree to these terms? \c"

if [ "${EXP_LICENSE}" = no ]; then
    exit 1
fi
EXP_LICENSE=`date -u`

#
# Disclaimer
#
echo "
-----

Sun Microsystems, Inc. respects your desire for privacy. Personal information
collected from this form will not be shared with organizations external to Sun
without your consent, except to process data on Sun's behalf in connection with
this transaction. We will use your personal information for communications
regarding Sun equipment and service related topics associated with the data
submitted.

Sun, as a global company, may transfer your personal information to countries
which may not provide an adequate level of protection. Sun, however, is
committed to providing a suitable & consistent level of protection for your
personal information regardless of the country in which it resides.

Completing the form below implies agreement with the above processing.

If you have any questions please refer to the Sun Privacy Policy or contact us
at privacy@sun.com.

If you have any questions about this form or in the future wish to update or
delete any of the information provided, please contact explorer-privacy@sun.com

-----
"

echo "For any prompt, defaults appear in square brackets, e.g. [default]."
echo "Pressing "return" without entering any data will take the default."
echo "You may specify an empty reply, as opposed to the default, by replying"
echo "with a single dash, '-'."

#
#  Request data
#

# Prompt for installation location
while true
do
    echo ""
    prompt BASEDIR "Where should this package be installed? \c"

    # Make sure BASEDIR isn't NULL
    if [ -z "${BASEDIR}" ]; then
	continue
    else
	break
    fi
done

# Set EXP_ETC variable for EXP_DEFAULTS use
EXP_ETC="/etc/opt/SUNWexplo"
# Make sure EXP_DEFAULTS is set
if [ -z "${EXP_DEFAULTS}" ]
then
    if [ -f "${BASEDIR}/etc/default/explorer" ]
    then
        EXP_DEFAULTS="${BASEDIR}/etc/default/explorer"
    else
        EXP_DEFAULTS="${EXP_ETC}/default/explorer"
    fi
fi
# Check for previous install defaults file (shell style)
CINFO=${PKG_INSTALL_ROOT}/etc/default/explorer
if [ -f "${EXP_DEFAULTS}" ]
then
    test -r "${EXP_DEFAULTS}" && . ${EXP_DEFAULTS}

# Check for old style defaults file only if new style not available
elif [ -f "${CINFO}" ]
then
    getFeld () {
        egrep "$1" ${CINFO} | cut -f2- -d":" | sed -e 's/^ //g'
    }

    # Company information
    EXP_CUSTOMER_NAME=`getField "Customer Name"`
    EXP_CONTRACT_ID=`getField "Contract ID"`
    EXP_EMAIL=`getField "Email results to"`

    # System information
    EXP_SERIAL=`getField "System Serial number"`

    # Contact information
    EXP_USER_NAME=`getField "User Name"`
    EXP_USER_EMAIL=`getField "User e-mail"`
    EXP_PHONE=`getField "User Phone #"`
    EXP_ADDRESS_1=`getField "Address line 1"`
    EXP_ADDRESS_2=`getField "Address line 2"`
    EXP_ADDRESS_CITY=`getField "City"`
    EXP_ADDRESS_STATE=`getField "State"`
    EXP_ADDRESS_ZIP=`getField "Zip Code"`
fi


# Override EXP_HOME, EXP_DEF_VERSION and EXP_DEFAULTS
EXP_HOME=${BASEDIR}
EXP_DEF_VERSION="${VERSION}"
if [ -f "${BASEDIR}/etc/default/explorer" ]
then 
  DEFAULTS="\${EXP_HOME}/etc/default/explorer"
  EXP_DEFAULTS="${EXP_HOME}/etc/default/explorer"
fi
if [ -f "${EXP_ETC}/default/explorer" ]
then
  DEFAULTS="\${EXP_ETC}/default/explorer" 
  EXP_DEFAULTS="${EXP_ETC}/default/explorer"
fi

if [ "${BASEDIR}" = "/" ]
then
    EXP_LIB=/usr/lib/explorer
else
    EXP_LIB="\${EXP_HOME}/lib"
fi

# Transform EXP_SERIAL_HOSTID to EXP_SERIAL if don't already have one
HOSTID=`hostid`
if [ -z "${EXP_SERIAL}" ]
then
    EXP_SERIAL=`eval echo $"EXP_SERIAL_$HOSTID"`
fi

# Set Install date if not already set
EXP_INSTALL=`eval echo $"EXP_INSTALL_$HOSTID"`
if [ -z "${EXP_INSTALL}" ]
then
    eval "EXP_INSTALL=`date -u '+%m/%d/%Y'`"
fi

# Use VARS variable to determine what is used in the request script
VARS="EXP_DEFAULTS \
EXP_DEF_VERSION \
EXP_SUBJECT \
EXP_PATH \
EXP_SERIAL_$HOSTID \
EXP_CUSTOMER_NAME \
EXP_CONTRACT_ID \
EXP_EMAIL \
EXP_EMAIL_SPLIT \
EXP_USER_NAME \
EXP_USER_EMAIL \
EXP_PHONE \
EXP_ADDRESS_1 \
EXP_ADDRESS_2 \
EXP_ADDRESS_CITY \
EXP_ADDRESS_STATE \
EXP_ADDRESS_COUNTRY \
EXP_ADDRESS_COUNTRY_CODE \
EXP_ADDRESS_ZIP \
EXP_GEO \
EXP_LIB \
EXP_REPLY \
EXP_NOTIFY \
EXP_WHICH \
EXP_CRONTAB_RUN \
EXP_CRONTAB_HOUR \
EXP_CRONTAB_MINUTE \
EXP_CRONTAB_DAY"

# Get customer information
DONE=no
while [ -n "$DONE" ] && expr "X$DONE" : "X[Nn]" >/dev/null
do
    echo ""
    # Company information
    prompt EXP_CUSTOMER_NAME   "Company name \c"
    prompt EXP_CONTRACT_ID     "Contract ID \c"

    # System information
    prompt EXP_SERIAL          "System serial number \c"

    # Contact information
    prompt EXP_USER_NAME       "Contact name \c"
    prompt EXP_USER_EMAIL      "Contact email address \c"
    prompt EXP_PHONE           "Phone number \c"
    prompt EXP_ADDRESS_1       "Address (line 1) \c"
    prompt EXP_ADDRESS_2       "Address (line 2) \c"
    prompt EXP_ADDRESS_CITY    "City \c"
    prompt EXP_ADDRESS_STATE   "State \c"
    prompt EXP_ADDRESS_ZIP     "Zip \c"


get_geo EXP_GEO MAIL

get_country EXP_ADDRESS_COUNTRY EXP_ADDRESS_COUNTRY_CODE


    # Send to Sun?
    yorn SUN "
Automatic Email Submission

Would you like all explorer output to be sent to:
    ${MAIL}
at the completion of explorer when -mail or -e is specified?"

    # Remove database address from EXP_EMAIL
    if [ -n "${EXP_EMAIL}" ]
    then
	EMAIL=`echo ${EXP_EMAIL} | sed -e "s/${MAIL}//" -e "s/^,//" -e "s/,$//"`
    fi

    # Alternate addresses for mail?
    prompt EMAIL "
Alternate Email Addresses

Would you like explorer output to be sent to alternate email
addresses at the completion of explorer?  If not, enter a single "-"
only for your reply.

To enter multiple addresses, seperate them with a comma (,).
\c"

    # If select to send to Sun, add MAIL to EXP_EMAIL
    if [ "${SUN}" = "yes" ]
    then
	if [ -z "${EMAIL}" ]
	then
	    EXP_EMAIL="${MAIL}"
	else
	    EXP_EMAIL="${MAIL},${EMAIL}"
	fi
    else
        EXP_EMAIL="${EMAIL}"
    fi

    # Set default reply address to user email address
    test -z "${EXP_REPLY}" && eval "EXP_REPLY=${EXP_USER_EMAIL}"

    # Explorer reply address
    echo ""
    prompt EXP_REPLY "Return address for explorer email output \c"

    # Notification of load into repository email address
    echo ""
    prompt EXP_NOTIFY "
To receive email notification that your explorer output has been loaded
into the repository, enter the email address to send the notification to.
If notification is not wanted, enter a single "-".  
\c"


    # Default environment values
    [ -z "${EXP_WHICH}" ] &&       EXP_WHICH=default
    [ -z "${EXP_EMAIL_SPLIT}" ] && EXP_EMAIL_SPLIT=4194304
    [ -z "${EXP_SUBJECT}" ] &&     EXP_SUBJECT="%C %I %E"
    [ -z "${EXP_PATH}" ] &&        EXP_PATH="/usr/bin:/usr/sbin"

    # Done, finish up
    # (Include in 3.5.5 release) Notification of receipt: ${EXP_NOTIFY}
    echo ""
    DONE=Yes
    yorn DONE "You have answered:
             Company name: ${EXP_CUSTOMER_NAME}
              Contract ID: ${EXP_CONTRACT_ID}

     System serial number: ${EXP_SERIAL}

             Contact name: ${EXP_USER_NAME}
    Contact email address: ${EXP_USER_EMAIL}
             Phone number: ${EXP_PHONE}
         Address (line 1): ${EXP_ADDRESS_1}
         Address (line 2): ${EXP_ADDRESS_2}
                     City: ${EXP_ADDRESS_CITY}
                    State: ${EXP_ADDRESS_STATE}
                      Zip: ${EXP_ADDRESS_ZIP}
                  Country: ${EXP_ADDRESS_COUNTRY}
             Country Code: ${EXP_ADDRESS_COUNTRY_CODE}

                Geography: ${EXP_GEO}
           Mail output to: ${EXP_EMAIL}
         Mail output from: ${EXP_REPLY}
        Mail on data load: ${EXP_NOTIFY}

    Are these values okay? \c"

    if [ "${DONE}" = no ]; then
	yorn ABORT "Abort install? \c"
	if [ "${ABORT}" = yes ]; then
	    exit 1
	fi
    fi
done

# If this is not a remote install, check cron and see if 
# explorer should be run
if [ -z "${PKG_INSTALL_ROOT}" ]
then
    yorn EXP_CRONTAB_RUN "
We recommend running explorer once a week and emailing the results
to the explorer database.  If you agree with this, the root crontab
will be modified.

Do you wish to run explorer once a week? \c"

    if [ "${EXP_CRONTAB_RUN}" = yes ]; then
	validate EXP_CRONTAB_HOUR   0 23 "At which hour would you like this to run (0 to 23): \c"
	validate EXP_CRONTAB_MINUTE 0 59 "At which minute would you like this to run (0 to 59): \c"
	validate EXP_CRONTAB_DAY    0 6  "On which day would you like this to run (0-6 with 0=Sunday): \c"
    fi

    echo ""
    echo "If this is a new install of explorer, please run explorer and"
    echo "mail the results to Sun."
    echo ""
    echo "The command to do this would be:"
    echo ""
    echo "${EXP_HOME}/bin/explorer -q -e"
    echo ""

    yorn EXP_RUN "Would you like to do this now? \c"
else
    EXP_CRONTAB_RUN=no
    EXP_RUN=no
fi

# Make environment variables available to installation service
cat >>$1 <<!
BASEDIR="${BASEDIR}"
EXP_HOME="${EXP_HOME}"
EXP_LICENSE="${EXP_LICENSE}"
EXP_DEFAULTS="${DEFAULTS}"
EXP_DEF_VERSION="${EXP_DEF_VERSION}"
EXP_CONTRACT_ID="${EXP_CONTRACT_ID}"
EXP_EMAIL="${EXP_EMAIL}"
EXP_EMAIL_SPLIT="${EXP_EMAIL_SPLIT}"
EXP_USER_EMAIL="${EXP_USER_EMAIL}"
EXP_PHONE="${EXP_PHONE}"
EXP_LIB="${EXP_LIB}"
EXP_GEO="${EXP_GEO}"
EXP_REPLY="${EXP_REPLY}"
EXP_WHICH="${EXP_WHICH}"
EXP_CRONTAB_RUN="${EXP_CRONTAB_RUN}"
EXP_CRONTAB_HOUR="${EXP_CRONTAB_HOUR}"
EXP_CRONTAB_MINUTE="${EXP_CRONTAB_MINUTE}"
EXP_CRONTAB_DAY="${EXP_CRONTAB_DAY}"
EXP_RUN="${EXP_RUN}"
EXP_SUBJECT="${EXP_SUBJECT}"
EXP_PATH="${EXP_PATH}"
EXP_ADDRESS_ZIP="${EXP_ADDRESS_ZIP}"
EXP_NOTIFY="${EXP_NOTIFY}"
!

# Esacpe quotes in certain variables
QUOTE=`echo ${EXP_USER_NAME} | sed -e "s/'/\\'/g"`
echo EXP_USER_NAME="${QUOTE}" >>$1
QUOTE=`echo ${EXP_CUSTOMER_NAME} | sed -e "s/'/\\'/g"`
echo EXP_CUSTOMER_NAME="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_1} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_1="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_2} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_2="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_CITY} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_CITY="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_STATE} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_STATE="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_COUNTRY} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_COUNTRY="${QUOTE}" >>$1
QUOTE=`echo ${EXP_ADDRESS_COUNTRY_CODE} | sed -e "s/'/\\'/g"`
echo EXP_ADDRESS_COUNTRY_CODE="${QUOTE}" >>$1

# Transform EXP_SERIAL to EXP_SERIAL_HOSTID
eval "EXP_SERIAL_$HOSTID=${EXP_SERIAL}"

# Store serial number for this HOSTID
echo "EXP_SERIAL_$HOSTID=\"${EXP_SERIAL}\"" >>$1
unset EXP_SERIAL

# Store install date for this HOSTID
echo "EXP_INSTALL_$HOSTID=\"${EXP_INSTALL}\"" >>$1

# See if other variables are in defaults file and make available
if [ -f "${PKG_INSTALL_ROOT}/${EXP_DEFAULTS}" ]
then
    cat ${EXP_DEFAULTS} | while read line
    do
	# Skip comments and blank lines
	echo $line | sed -e 's/^ *//' -e 's/ *$//' | egrep -s -e '^#' && continue
	echo $line | egrep -s -e '^$' && continue

	# Get the variable
	VAR=`echo $line | awk -F= '{ print $1 }'`

	# Only print lines that aren't in VARS
	# eval test -z \"\$\{$VAR\}\" && echo $line >>$1
	echo $VARS | egrep -s -e "$VAR" || echo $line >>$1
    done
fi

exit 0
