#!/bin/sh
get_arch()
{
#!/bin/sh
#
# find_arch.sh - determines the machine architechture for Wind/U purposes
#
# Copyright (c) 1994-1997 Bristol Technology Inc.
# All rights reserved.
#
# History
# 08/11/94	JDS	Initial version
# 08/23/94	CCC	Return error exit status on failure
# 11/04/94	JDS	Look in $WUARCH followed by $ARCH for preset arch
# 10/07/96	Aditi	Added support for sgimt
# 05/23/97	ArunE	hp700 and sgi are no longer valid ARCH's

# be sure "uname" can be found
PATH=$PATH:/bin:/usr/bin

me=`basename $0`

# check WUARCH then ARCH for valid Wind/U architecutre
for environment_var in "WUARCH" "ARCH"
do
  eval "expn=\$$environment_var"
  if [ "$expn" != "" ]; then
    env_var=$environment_var
    env_arch=$expn
    case "$expn" in
      sun4|sol2|sol2_x86|hp700|hp700mt|rs6000|sgi|sgimt|decaosf|ncr) env_arch=$expn
	  				  break 2 ;;
      sun4-g|sol2-g|hp700mt-g|rs6000-g|sgimt-g|decaosf-g) env_arch=`echo $expn | sed s/\-g//`
					  break 2 ;;
      *) env_arch="ERROR"
	 error_expn=$expn ;;
    esac
  fi
done
if [ "$env_arch" = "ERROR" ]; then
  echo "($me) WARNING: Unrecognized architecture of" \
       "\"$error_expn\" in $env_var."  >&2
  env_arch=""
fi

# figure it out ourselves
# Try to use "uname" - it's POSIX-compliant
found_arch="ERROR"
( exec uname ) > /dev/null 2>&1
if [ $? -eq 0 ]; then
  case "`uname`" in
     OSF1) found_arch=decaosf ;;
    HP-UX) case "`uname -r`" in
	    *.10.*) found_arch=hp700mt;;
	         *) found_arch=hp700;;
	   esac
	   ;;
     IRIX*) case "`uname -r`" in 
	   5.*) found_arch=sgi ;;
	   6.*) found_arch=sgimt ;;
	   esac
	   ;;
      AIX) found_arch=rs6000 ;;
  UNIX_SV) found_arch=ncr ;;
    SunOS) case "`uname -r`" in
             4.1.*) found_arch=sun4 ;;
               5.*) case "`uname -p`" in
			sparc) found_arch=sol2 ;;
			 i386) found_arch=sol2_x86 ;;
		    esac
           esac
  esac
fi
if [ "$found_arch" = "ERROR" ]; then
  if [ -f /usr/kvm/stand/kadb ] ; then
    if [ `/bin/arch` = "sun4" ] ; then
      found_arch=sun4
    fi
  elif [ -f /hp-ux ] ; then
    found_arch=hp700mt
  elif [ -f /usr/lib/boot/unix ] ; then
    found_arch=rs6000
  elif [ -f /ufsboot ] ; then
	if [ "`uname -m`" = "i86pc" ]
	then
	  found_arch=sol2_x86
	else
      found_arch=sol2
	fi
  else
    found_arch="ERROR"
  fi
fi

# check to be sure env var setting matches platform
# echo "found_arch = $found_arch   env_arch = $env_arch"
if [ "$env_arch" != "ERROR" -a "$env_arch" != "" -a \
     "$found_arch" != "ERROR" -a "$found_arch" != "$env_arch" ]; then
  # sgi and hp700 are no longer valid
  if [ "$env_arch" = "hp700" -o "$env_arch" = "sgi" ]; then
    echo "-------\n" \
     "($me) WARNING: Architecture of \"$env_arch\" set in $env_var" \
     "is no longer valid. \"$env_var\" will be set to \"$found_arch\"" \
     "as found by the script. Valid values are: decaosf, hp700mt, ncr," \
     "rs6000, sgimt, sol2, sol2_x86 and sun4." \
     "\n-------"  >&2
    wuarch=$found_arch
  else
    echo "($me) WARNING: Architecture of \"$env_arch\" set in $env_var" \
     "overrides the architecture of \"$found_arch\" found by the script." >&2
    wuarch=$env_arch # use env value anyway; heuristic could be wrong
  fi
elif [ "$env_arch" = "ERROR" -o "$env_arch" = "" ]; then
   wuarch=$found_arch # no env value, use ours
else
  wuarch=$env_arch # env value checks out; use it
fi

# print a message if the arch can not be determined
if [ "$wuarch" = "ERROR" ] ; then
  echo "($me) ERROR: Can't figure out your architecture."  >&2
  echo $wuarch 
  exit 1
else
  echo $wuarch
  exit 0
fi
}
#!/bin/sh
#
# windu_client -- convenient script to start/stop windu_clientd
#
# Copyright (c) 1994-1997 Bristol Technology Inc.
# All rights reserved.
#
# History
# 05/01/96	LU	Initial version
#

# sanity checking
# must set WUHOME
if [ -z "$WUHOME" ]; then
echo "Error: Please set WUHOME enviroment before you run this command"
exit 1
fi

# syntax
if [ $# -lt 1 -o "$1" != "stop" -a "$1" != "start" ]; then
echo "Usage: windu_client stop|start [-display HOSTNAME:0]"
exit 1
fi

# get arch
ARCH=`get_arch`

#
# Figure out the name of the daemon.  It's always the latest version of the
# daemon in the location specified by the user.
#
daemonLocation=$WUHOME/lib.$ARCH
currDir=`pwd`
cd $daemonLocation

latestVers=0
for x in `ls windu_clientd*`
do
   currentVers=`echo $x | cut -c 14-`
   if [ `expr $latestVers` -lt `expr $currentVers` ]
   then
      latestVers="$currentVers"
   fi
done
WINDU_CLIENTD="windu_clientd$latestVers"
cd $currDir

# check whether windu_clientd is there and is executable
if [ ! -x $WUHOME/lib.$ARCH/$WINDU_CLIENTD ]; then
echo "Error: $WUHOME/lib.$ARCH/$WINDU_CLIENTD is not there or does not have the right permission."
exit 1
fi
 
# determine whether to stop or start
if [ "$1" = "stop" ]; then
shift
$WUHOME/lib.$ARCH/$WINDU_CLIENTD -forceexit $@
exit 0
fi

if [ "$1" = "start" ]; then
shift
$WUHOME/lib.$ARCH/$WINDU_CLIENTD $@
exit 0
fi


