#! /bin/sed {/^#>/!d;s/^#>//;}
#
# Getsystemoptions - set variables properly for the current system.
#
# Version: 1995/05/17.
#
# NOTE: this file must be "sourced", not run as a command.
# This script attempts to preserve and restore the command line
# arguments. The user should consider doing argument processing
# before sourcing this file.
#
# The following names are set:
#
# basecommand	- simple name of the invoked command.
# admin		- mail address of the system administrator.
# host		- host name.
# ostype	- O/S type (one of "HP-UX", "IRIX", "IRIX64",
#		  "SunOS", "AIX", "Domain/OS")
# dflocal	- get a list of local file systems.
# dfnfs		- get a list of NFS file systems.
# findopts	- 'find' options to scan only the current file system.
# lsopts	- 'ls' options for a full listing (owner+group).
# mail		- a "real" mail program (e.g. understands '-s subject').
# echoopt	- option to use for 'echo' with no new-line.
# echochar	- final special character for 'echo' with no new-line.
# unixprint	- command to print a file.
# fortranprint	- command to print a FORTRAN output file.
# testlink	- 'test' option to check for a symbolic link.
# rsh		- command to run a regular remote shell.
#
# If 'dflocal' and/or 'dfnfs' is returned simply as "df", there is
# no nice command to get what is needed, and the calling script
# will have to determine the list of file systems for itself.
# Using a plain 'df' is very bad news for 'dflocal', as the command
# will almost certainly hang if any NFS-mounted file system is
# not available.
#
# The 'echoopt' and 'echochar' are used as:
#    echo $echoopt "This line will not have newline$echochar"
#
# The 'unixprint' command includes the first part of the option
# to specify the printer name, so it is used as:
#    $unixprint $PRINTER filename
#
#
# The following section (marked with '#>') will be displayed if
# this script is executed instead of being "sourced" (this idea
# follows a suggestion by Jack Applin of HP <neutron@fc.hp.com>
# in the Fall 1993 issue of "The Works").
#
#>ERROR: Getsystemoptions must be "sourced", not executed.
#>Proper usage: '. /usr/local/bin/Getsystemoptions'
#
# Save any arguments as best we can - it would be nice to use an
# array but some /bin/sh don't support it, so use a temporary file.
#
nargs=$#
if [ "$nargs" -gt 0 ]; then
#  if [ "$?" = "0" ]; then
#     argtmp=
#     set -A saveargs "$@"
#  else
      argtmp=/tmp/.Getsystemoptions.$$
      /bin/rm -f $argtmp
      echo "set --\\" >$argtmp
      while [ "$#" -gt 0 ]; do
         echo " '$1'\\" | sed "s/\(..\)'\(..\)/\1'\"'\"'\2/g" >>$argtmp
         shift
      done
      echo "" >>$argtmp
#  fi
fi
#
# Get the simple name of the invoked command.
#
basecommand=`basename $0`
#
# Set the name of the system administrator - use '$localadmin@$mailserver'
# if the account exists locally, else 'root'.
#
localadmin=system
mailserver=alchemy
egrep -s "^$localadmin:|^\+$localadmin:" /etc/passwd >/dev/null 2>&1
if [ "$?" = "0" ]; then
   admin=$localadmin@$mailserver
else
   admin=root
fi
#
# Get the host name.
#
host=`hostname`
#
# Set default 'dflocal', 'dfnfs', 'find', 'ls', 'testlink'
# and 'rsh' options, and a real 'mail' program.
#
dflocal="df"
dfnfs="df"
findopts="-xdev"
lsopts="-l"
testlink="-h"
rsh="rsh"
#
set `which Mail`
if [ "$#" = "1" ]; then
   mail="$1"
else
   mail="mail"
fi
#
# Try to determine the current system type and set options accordingly.
#
set `which uname`
if [ "$#" = "1" ]; then
   ostype="`uname -s`"
else
   ostype=""
fi
#
if [ "$ostype" = "HP-UX" ]; then
   dflocal="bdf -l"
   dfnfs="bdf -t nfs"
   rsh=remsh
   mail="mailx"
elif [ "$ostype" = "IRIX" -o "$ostype" = "IRIX64" ]; then
   dflocal="df -l"
   dfnfs="df"
   findopts="-mount"
   testlink="-l"
elif [ "$ostype" = "SunOS" ]; then
   dflocal="df -t 4.2"
   dfnfs="df -t nfs"
   lsopts="-lg"
elif [ "$ostype" = "AIX" ]; then
   dflocal="df"	# Yuck - this will hang if NFS-mounted systems are down.
   dfnfs="df"	# Yuck - this will hang if NFS-mounted systems are down.
   testlink="-L"
elif [ "$ostype" = "" -a -d /sys/node_data ]; then
   ostype="Domain/OS"
   dflocal="df"	# Yuck - this will hang if NFS-mounted systems are down.
   dfnfs="df"	# Yuck - this will hang if NFS-mounted systems are down.
   lsopts="-lg"
   testlink="-L"
else
   $mail -s "Can't set file system parameters in Getsystemoptions on $host" $admin <<EOF0
Getsystemoptions can't determine the file system parameters for host $host.
Please correct the script with the proper options.

Using plain 'df', which will hang if any NFS-mounted systems are down.
Using 'find $findopts', which may scan all NFS-mounted file systems,
or just fail.
EOF0
fi
#
# Handle the proper mechanism for echoing a character with no
# trailing newline.
#
if [ "`echo -n`" = "" ]; then
   echoopt=-n
   echochar=
else
   echoopt=
   echochar="\c"
fi
#
# Find out the proper command for standard UNIX printing:
# possibilites are 'lpr' (most systems, but don't use it on HP-UX)
# and 'lp' (HP-UX).
#
set `which lpr`
if [ "$#" = "1" -a "$ostype" != "HP-UX" ]; then
   unixprint="lpr -P"
else
   set `which lp`
   if [ "$#" = "1" ]; then
      unixprint="lp -d"
   else
      $mail -s "Can't set default print command in Getsystemoptions on $host" $admin <<EOF1
Getsystemoptions can't find 'lpr' or 'lp' on $host.
Please correct the script with the proper options.
EOF1
      exit 1
   fi
fi
#
# Find out the proper command for printing FORTRAN output files:
# possibilites are 'fpr' (most systems) and 'asa' (HP-UX).
# Note that you may to delete the first line of the file after 'asa'
# has processed it.
# If all else fails, use 'cat'.
# Don't complain about failures on our SunOS systems, which do not
# have FORTRAN or a complete development environment loaded.
#
set `which fpr`
if [ "$#" = "1" ]; then
   fortranprint=fpr
else
   set `which asa`
   if [ "$#" = "1" ]; then
      fortranprint=asa
   else
      if [ "$ostype" != "SunOS" ]; then
         $mail -s "Can't set default FORTRAN output filter in Getsystemoptions on $host" $admin <<EOF2
Getsystemoptions can't find 'fpr' or 'asa' on $host.
Using 'cat' for now.
Please correct the script with the proper options.
EOF2
      fi
      fortranprint=cat
   fi
fi
#
# Restore any command line arguments.
#
if [ "$nargs" -gt 0 ]; then
#  if [ "$argtmp" = "" ]; then
#     set -- "${saveargs[@]}"
#  else
      . $argtmp
      /bin/rm -f $argtmp
#  fi
else
   set --
fi
# Don't do the following check on SunOS (where Korn Shell is a link to /bin/sh).
if [ "$#" -ne "$nargs" -a "$ostype" != "SunOS" ]; then
   echo "*** WARNING: $nargs arguments found originally, but $# have been restored ***"
fi
#
# End of Getsystemoptions.
#
