#
#  Build script for etc/default/explorer
#  $Id: //depot/stable/explorer/build/explorer#3 $
#

# Define EXP_ETC variable
EXP_ETC="/etc/opt/SUNWexplo"

COMMENT_EXP_DEFAULTS="Location of the explorer defaults file"
COMMENT_EXP_DEF_VERSION="Version of defaults file"
COMMENT_EXP_LICENSE="Software License Agreement"
COMMENT_EXP_SUBJECT="Subject line for explorer email"
COMMENT_EXP_PATH="Default PATH for explorer"
COMMENT_EXP_CUSTOMER_NAME="Customer Name"
COMMENT_EXP_CONTRACT_ID="Contract ID"
COMMENT_EXP_EMAIL="Where explorer output should be mailed"
COMMENT_EXP_EMAIL_SPLIT="Maximum size (in bytes) of an explorer email"
COMMENT_EXP_USER_NAME="Customer Contact Name"
COMMENT_EXP_USER_EMAIL="Customer Contact Email"
COMMENT_EXP_PHONE="Customer Contact Phone Number"
COMMENT_EXP_ADDRESS_1="Customer Contact Address"
COMMENT_EXP_ADDRESS_2="Customer Contact Address (line 2)"
COMMENT_EXP_ADDRESS_CITY="Customer Contact City"
COMMENT_EXP_ADDRESS_STATE="Customer Contact State"
COMMENT_EXP_ADDRESS_ZIP="Customer Contact Zip"
COMMENT_EXP_ADDRESS_COUNTRY="Customer Contact Country"
COMMENT_EXP_ADDRESS_COUNTRY_CODE="Customer Contact Country Code"
COMMENT_EXP_CRON_WHICH="crontab entries to collect"
COMMENT_EXP_LIB="Explorer library directory"
COMMENT_EXP_GEO="Customer Geography one of:\n    APAC (Asia Pacific),\n    EMEA (Europe, Middle East, Africa),\n    AMERICAS (North, Central and South America)"
COMMENT_EXP_REPLY="Email address where replies should be sent"
COMMENT_EXP_WHICH="Default list of modules to run"
COMMENT_EXP_NOTIFY="Email address to notify when explorer data loaded"

record () {
    VAR=$"$1"
    VAL=`eval echo "${VAR}"`
    COM=`eval echo $"COMMENT_$1" | sed -e 's/^/# /'`

    # Serial number?
    if echo $1 | egrep -s -e "EXP_SERIAL_"
    then
        HID=`echo $1 | sed -e 's/EXP_SERIAL_//'`
	COM="# Serial number for hostid $HID"
    fi

    # Install date?
    if echo $1 | egrep -s -e "EXP_INSTALL_"
    then
        HID=`echo $1 | sed -e 's/EXP_INSTALL_//'`
	COM="# Installation date (MM/DD/YYYY) for hostid $HID"
    fi

    # Print comment
    printf "%s\n" "${COM}"
    # Print assignment
    printf "%s=\"%s\"\n\n" "$1" "${VAL}"
}

# /etc/opt/SUNWexplo/default/explorer builder
if [ "$1" = install ]; then
    # File header
    echo "#!/bin/ksh -p"
    echo "# Explorer defaults file"
    echo "# This file is Korn shell source and is read by the explorer program"
    echo "# Modified on `date` by pkgadd"
    echo ""

    # Variables
    for VAR in `env | grep EXP_ | awk -F= '{print $1}'`
    do
	# Skip crontab data
	expr "${VAR}" : "EXP_CRONTAB_" >/dev/null && continue
	# Skip run data
	expr "${VAR}" : "EXP_RUN" >/dev/null && continue
	# Skip EXP_HOME
	expr "${VAR}" : "EXP_HOME" >/dev/null && continue
	# Skip EXP_DEFAULTS
	expr "${VAR}" : "EXP_DEFAULTS" >/dev/null && continue

	# Record
	record `eval echo ${VAR}`
    done
fi

# /etc/opt/SUNWexplo/default/explorer deconstructor
if [ "$1" = remove ]; then
    if [ -f "${EXP_ETC}/default/explorer" ]; then
	cat ${EXP_ETC}/default/explorer
    fi
fi
