#!/bin/csh -f
#
#      $Id: rarch,v 1.15 2003-05-16 14:53:13 haley Exp $
#
#########################################################################
#									#
#			   Copyright (C)  1992				#
#	     University Corporation for Atmospheric Research		#
#			   All Rights Reserved				#
#									#
#########################################################################
#
#	File:		rarch
#
#	Author:		John Clyne
#			National Center for Atmospheric Research
#			PO 3000, Boulder, Colorado
#
#	Date:		Fri Dec 11 14:09:51 MST 1992
#
#	Description:	Determine the architecture of a remote host using
#			rsh and the uname command. On success, rarch writes
#			the remote architecture type to stdout and exits
#			with a zero exit status.
#
#	Usage:		rarch [-l <remote_user>] <rhost>
#
#	Environment:
#
#	Files:
#
#
#	Options:	remote_user	: login to the remote machine as
#					$remote_user

set ruser = ""

while ($#argv)
	switch ("$argv[1]")
	case -l:
		shift
		set ruser = "-l $argv[1]"
		breaksw
	case -*:
		echo "Usage: rarch  [-l <remote_user>] <rhost>" > /dev/tty
		exit 1
		breaksw
	default:
		set rhost = "$argv[1]"
		breaksw
	endsw

	shift
end

if (! $?rhost) then 
	echo "Usage: rarch  [-l <remote_user>] <rhost>" > /dev/tty
	exit 1
endif
		
if (-e /bin/uname) then
  set Uname = "/bin/uname"
else if (-e /usr/bin/uname) then
  set Uname = "/usr/bin/uname"
endif
  
#set a = `$RSH $host $ruser /bin/uname -a`
set a = `$LOCALDIR/rshe $RSH $ruser $rhost $Uname -a`
if ($status != 0) then
	exit 1
endif

switch ("$a[1]")
case AIX:
	echo AIX_RS6000
	exit 0

case IRIX:
case IRIX64:
	echo IRIX_IP
	exit 0

case OSF1:
 	echo OSF1_alpha
 	exit 0

case ULTRIX:
	echo ULTRIX_RISC
	exit 0

case HP-UX:
	switch ("$a[5]")
	case	9000/7*:
		echo HPUX_HP9000_7xx
		breaksw
	case	9000/8*:
		echo HPUX_HP9000_8xx
		breaksw
	endsw
	exit 0

case Linux:
case LINUX:
	switch ("$a[12]")
	case	*86:
		echo LINUX_PC
		breaksw
	case	ia64:
		echo LINUX_IA64
		breaksw
	endsw
	exit 0

case Darwin:
case DARWIN:
	echo DARWIN_MAC
	exit 0

case Cygwin:
case CYGWIN:
	echo CYGWIN_PC
	exit 0

case SunOS:
	switch ("$a[3]")
	case	5*:
        if ("$a[5]" == "i86pc") then
			echo Solaris_PC
		else
			echo Solaris_sun4
		endif
		exit 0
	default:
		switch("$a[5]")
		case	sun4*:
			echo SunOS_sun4
			exit 0
		endsw
	endsw
	
endsw

switch ("$a[5]")
case CRAY:
	switch("$a[6]")
	case	Y*:
		echo UNICOS_YMP
		exit 0
	case	J9*:
		echo UNICOS_J90
		exit 0
	case	C9*:
		echo UNICOS_C90
		exit 0
	case	T*:
		echo UNICOS_T90
		exit 0
	endsw

case UNIX_System_V:
	echo UNIXSV_Fujitsu300
	exit 0

endsw

echo unknown
exit 1

