#!/bin/ksh -p
#
# ident "@(#)gl_defs.ksh	1.21 04/09/09 SMI"
#
# Copyright 2001-2002,2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# global variables definition
#
# NOTE: 
# These variables must be set by the master task:
#
# G_MEDIA_DIR which contains the pathname of modules, support_lib directories
#             (otherwise master task cannot source this library)
# G_PRODUCT_DIR which contains the pathname of the Sun Ray bundle area (SWS,
#             SunDs, ...)

# find local temporary directory location
if [[ -d /var/tmp ]]; then
   export G_TMP=/var/tmp
elif [[ -d /tmp ]]; then
   export G_TMP=/tmp
elif [[ -d /usr/tmp ]]; then
   export G_TMP=/usr/tmp
else
   echo "$0: Error, cannot find a temporary directory"
   exit 1
fi

export G_PROGRAM_ID="$(basename $0)"
export G_MODE="install"
export G_ADMIN_FILE="${G_MEDIA_DIR}/admin_default"
export G_JRE=""
export G_DEBUG="no"
export G_QUICK_INSTALL="no"

#
# pre-defined variables
#
case "$G_OS" in
  SunOS) export G_ADM_LOG_DIR="/var/adm/log";;
  Linux) # on Linux, the journal for utinstall goes into /var/log,
	 # but the journal for other utilities goes into /var/log/SUNWut
	 # which is installed and removed by the SUNWutr package.
	if [[ ${G_PROGRAM_ID} = "utinstall" ]]; then
		export G_ADM_LOG_DIR="/var/log"
	else
		LINUX_LOG_DIR="/var/log/SUNWut"
		if [[ -d ${LINUX_LOG_DIR} ]]; then
			export G_ADM_LOG_DIR=${LINUX_LOG_DIR}
		else
			export G_ADM_LOG_DIR="/var/log"
		fi
	fi;;
esac

export G_TIME_STAMP="$(date '+%Y_%m_%d_%H:%M:%S')"
export G_PID="$$"
#
# attach pid and timestamp to G_TMP and create the temporary working
# directory with umask of 077.
export G_TMP_DIR="${G_TMP}/${G_PROGRAM_ID}.${G_PID}.${G_TIME_STAMP}"
if ! (umask 077; mkdir ${G_TMP_DIR}); then
    print -u2 "${G_PROGRAM_ID}: unable to create temporary working directory."
    exit 1
fi

export G_UT_PROD_NAME="Sun Ray Core Services"
export G_UT_VERSION="3.1"
export G_LOGFILE="${G_ADM_LOG_DIR}/${G_PROGRAM_ID}.${G_TIME_STAMP}.log"
export G_UPGRADE_DIR="${G_TMP}/SUNWut.upgrade"

# when restoring the server, use the data from an old preserved tarfile
# instead of the current configuration if this file exists.
export G_OLD_PRESERVED_FILE="${G_UPGRADE_DIR}/USE_OLD_PRESERVED"

export G_DAEMON_LOC="/etc/init.d"

export G_ACTIVITYM_PID=""
export G_MESSAGE_FILE="${G_TMP_DIR}/${G_PROGRAM_ID}.${G_PID}.message"

# Sun Ray Server Software directory
export G_SUNRAY_SERVER_DIR="Sun_Ray_Core_Services_3.1"

# architecture type to be installed.
export G_INSTALL_ARCH=$(uname -p)
if [[ $G_INSTALL_ARCH = "unknown" ]]; then
	G_INSTALL_ARCH=$(uname -m)
fi

# OS type to be installed.
export G_INSTALL_OS=$(uname -s)

# Current installed Sun Ray version.  It will be empty if not installed.
export G_SR_CURRENT_VERSION=$($G_MEDIA_DIR/utprodinfo -p SUNWutr VERSION 2>&- \
	| cut -d_ -f1)
