#!/bin/sh
# 
# @DEC_COPYRIGHT@
#
# HISTORY
# $Log: evmcommandset.sh,v $
# Revision 1.1.1.1  2003/12/11 15:40:47  ajay
# Importing Evm sources.
#
# Revision 1.1.1.1  2002/09/12 15:43:53  lsn
# EVM source - Linux initial version
#
# Revision 1.1.17.1  2001/09/26  18:57:43  Anthony_Hoffman
# 	redo of wildcatos submits
#
# Revision 1.1.15.2  2001/07/30  18:08:25  Anthony_Hoffman
# 	wc.evm.002.portability
#
# Revision 1.1.15.1  2001/06/27  19:17:06  Jem_Treadwell
# 	QAR 87148: Added secure tempfile function
#
# Revision 1.1.11.1  2000/05/18  19:33:57  Anthony_Hoffman
# 	QAR 78713 - add cluster commands to support rolling upgrades
#
# Revision 1.1.5.8  1999/03/29  20:47:55  Bruce_Gayliard
# 	Fixes for QAR 70082 - uninit/unused vars and portability.
# 	[1999/03/29  17:21:46  Bruce_Gayliard]
#
# Revision 1.1.2.8  1999/03/29  16:28:47  Bruce_Gayliard
# 	Fixes for QAR 70082 - various code cleanup issues.
# 	[1999/03/29  16:21:23  Bruce_Gayliard]
# 
# Revision 1.1.2.7  1998/11/10  14:04:37  Jem_Treadwell
# 	Added egrep & ls
# 	[1998/11/10  14:04:13  Jem_Treadwell]
# 
# Revision 1.1.2.6  1998/09/15  03:00:45  Bruce_Gayliard
# 	Added some more support macros.
# 	[1998/09/15  01:10:40  Bruce_Gayliard]
# 
# Revision 1.1.2.5  1998/03/25  22:09:42  Jem_Treadwell
# 	Added gzip
# 	[1998/03/25  22:09:05  Jem_Treadwell]
# 
# Revision 1.1.2.4  1998/02/23  21:04:50  Jem_Treadwell
# 	Added awk
# 	[1998/02/23  21:04:12  Jem_Treadwell]
# 
# Revision 1.1.2.3  1998/02/13  23:55:51  Jem_Treadwell
# 	Added fmt and msg catalog cmds
# 	[1998/02/13  23:55:18  Jem_Treadwell]
# 
# Revision 1.1.2.2  1997/09/08  19:04:35  Bruce_Gayliard
# 	Fixes for LINUX / portability.
# 	[1997/09/08  19:01:07  Bruce_Gayliard]
# 
# $EndLog$
# 
# @(#)$RCSfile: evmcommandset.sh,v $ $Revision: 1.1.1.1 $ (DEC) $Date: 2003/12/11 15:40:47 $
# 

# define the commands to be used by EVM scripts.

# Currently, the only supported systems are linux and DIGITAL UNIX.
# DIGITAL UNIX is the default.
# Also, this script currently assumes that either sh or ksh is sourcing it.

case "${OSTYPE}" in
Linux | linux-gnu | linux)
   AWK=/usr/bin/awk
   BASENAME=/bin/basename
   CAT=/bin/cat
   CHMOD=/bin/chmod
   DIRNAME=/usr/bin/dirname
   EXPR=/usr/bin/expr
   FIND=/usr/bin/find
   GZIP=/bin/gzip
   GUNZIP=/bin/gunzip
   KILL=/bin/kill	# ksh implements this as a builtin
   LS=/bin/ls
   MKDIR=/bin/mkdir
   RM=/bin/rm
   SHELL=/bin/sh
   TOUCH=/bin/touch
   SLEEP=/bin/sleep
   GREP=/bin/grep
   EGREP="/bin/grep -E"
   FMT=/usr/bin/fmt
   XARGS=/usr/bin/xargs
   # sh and ksh implement the following as builtin commands
   ECHO=echo
   TEST=test
   ;;
*)
# DIGITAL UNIX
   AWK=/usr/bin/awk
   BASENAME=/usr/bin/basename
   CAT=/sbin/cat
   CHMOD=/sbin/chmod
   DIRNAME=/usr/bin/dirname
   EXPR=/sbin/expr
   FIND=/sbin/find
   GZIP=/usr/bin/gzip
   GUNZIP=/usr/bin/gunzip
   KILL=/sbin/kill	# ksh implements this as a builtin
   LS=/usr/bin/ls
   MKDIR=/sbin/mkdir
   RM=/sbin/rm
   SHELL=/sbin/sh
   TOUCH=/usr/bin/touch
   SLEEP=/sbin/sleep
   GREP=/sbin/grep
   EGREP=/usr/bin/egrep
   DSPMSG=/usr/bin/dspmsg
   DSPCAT=/usr/bin/dspcat
   FMT=/usr/bin/fmt
   CLU_GET_INFO=/usr/sbin/clu_get_info
   CLU_UPGRADE=/usr/sbin/clu_upgrade
   SYSCONFIG=/sbin/sysconfig
   # sh and ksh implement the following as builtin commands
   ECHO=echo
   TEST=test
   XARGS=/usr/bin/xargs
   ;;
esac

#==========================================================================
# Function: EVM_MKSTEMP
#
# This function creates a temporary file based on the name of the first
# argument, and writes the path to stdout.  For security, if the caller
# has write access to /var/evm/sockets, the file is created in that
# directory; otherwise it is created in /tmp.  If the creation attempt
# fails, a message is written to stderr and nothing is written to
# stdout.
# 
# Inclusion of a pid & uid suffix in the name, along with use of mkstemp
# (where available), further improves security and avoids the risk of
# a name clash.  Note that mkstemp is available on Tru64 UNIX, but cannot
# be assumed to be available on other platforms.
#
# Arguments: $1 identifies the caller and is used as the basis for the
#            tempfile name.
#==========================================================================
EVM_MKSTEMP()
{
    TEMPDIR=/tmp
    if [ -w /var/evm/sockets ]
    then
	TEMPDIR=/var/evm/sockets
    fi
    TEMPFILENAME=`${BASENAME} $1`.$$`id -u`
    TEMPFILE=$TEMPDIR/$TEMPFILENAME

    if [ -x /usr/lbin/mkstemp ]
    then
	TEMPFILE=`/usr/lbin/mkstemp $TEMPFILE`
	if [ "$TEMPFILE" = "" ]
	then
	   echo `basename $1`: "Failed to generate a unique tempfile name" >&2
	   exit $EXIT_TEMPFILE
	fi
    else
	${RM} -f $TEMPFILE
	if [ -e $TEMPFILE ]
	then
	   echo `basename $1`: "Failed to create tempfile $TEMPFILE" >&2
	   exit $EXIT_TEMPFILE
	fi

	UMASK_SAVE=`umask`
	umask 077
	touch $TEMPFILE
	umask $UMASK_SAVE

	if [ ! -e $TEMPFILE ]
	then
	   echo `basename $1`: "Failed to create tempfile $TEMPFILE" >&2
	   exit $EXIT_TEMPFILE
	fi
    fi

    echo $TEMPFILE
}
