From: friedman@gnu.ai.mit.edu (Noah Friedman)
Subject: Re: Maintaining .cshrc files across several machines
Organization: Free Software Foundation, 675 Mass Ave. Cambridge, MA 02139
Date: Thu, 9 Apr 1992 12:40:32 GMT

rantapaa@s6.math.umn.edu (Erik E. Rantapaa) writes:
>Has any one solved the problem of maintaining .cshrc files across
>several machines?  In particular, it would be nice to have a
>'cshrc-config' program which would sniff out a system for binary
>paths, libraries, etc.

   I use the following bourne-shell script on the machines where I work.
You can just add extra switches and tests if you need to.  I've tried to
make it give output consistent with what some system programs (like `arch'
on the suns) will give.  Basically, I do something like

        MACHTYPE="`machtype`"
        PATH="${HOME}/bin/${MACHTYPE}:${PATH}"

in my .profile.  You can certainly use this with csh as well by doing

        set machtype=`${HOME}/bin/machtype`
        set path=(${HOME}/bin/${machtype} ...)

in your .cshrc.  Enjoy. 

#!/bin/sh
# machtype -- 18-Mar-92 Noah Friedman (friedman@prep.ai.mit.edu)
#
#    This script attempts to determine the machine type by going through a
# list of programs which might give some indication of the machine
# architecture and/or type and runs the first one it can find.  Add any
# other program names which might be useful.  If you're using bash, also
# check functions.init.  That version is faster because it is "inline", and
# is also more correct because bash's test has a -x operator.
#
# Public domain.
#

SHELL=/bin/sh
export SHELL

# First try `uname -m'
machtype="`(uname -m) 2> /dev/null | tr '[A-Z]' '[a-z]'`"
if [ "${machtype}" ]; then
   case ${machtype} in
      # HP 9000 series
      9000/*)	  
         # HP 9000 series
         hptype="`echo ${machtype} | sed 's=9000/\(.\).*=\1='`"
         result="hp${hptype}00"
        ;;
      sun4*)		result="sun4" 		;;
      sun3 | sun3x)	result="sun3"		;;
      sun2*)		result="sun2"		;;
      *)		result="${machtype}"	;;
   esac

   echo "${result}"
   exit 0
fi

#----------------------------------------------------------------------#

# Try some other programs.  These should echo the name of the machine type
# on stdout. 
progs="
   /bin/arch 
   /bin/mach 
   /bin/machine 
   /usr/local/bin/machine 
"
machtype=""

for prog in ${progs} ; do
   # Should really be -x, but some old versions of test are broken
   if [ -r ${prog} ]; then 
      machtype="`${prog}`"
      break
   fi
done

if [ "${machtype}" ]; then
   case ${machtype} in
      hp??? )
         # HP 9000 series
         result="`echo ${machtype} | sed 's=..$=00='`"
        ;;
      sparc | sun4*)	result="sun4" 		;;
      sun3 | sun3x)	result="sun3"		;;
      sun2*)		result="sun2"		;;
      *)		result="${machtype}"	;;
   esac

   echo "${result}"
   exit 0
fi

#----------------------------------------------------------------------#

# A last-ditch effort to determine machine type.  These programs just exit
# with a zero exit status if they are for the correct machine type.  They
# return false otherwise.  Add programs as necessary.
#
#  Be sure to list most specific types first.  For example, on a Sun,
# /bin/sun will return 0 even though that's not very specific.  Try `sun3',
# `sun4', etc. first before trying `sun'.  
#
# Not all these are guaranteed to exist, even on systems they describe.
# For example, as the sysadmin for a couple of IBM RT machines, I added
# /bin/ibmrt myself.  Ordinarily there's no way to tell if you're on an RT
# or not (except by messing with the C preprocessor)

commands='
   /bin/hp9000s*
   /bin/vax
   /bin/u370
   /bin/u3b2
   /bin/u3b5
   /bin/u3b10
   /bin/u3b15
   /bin/u3b
   /bin/sun4c
   /bin/sun4
   /bin/sun3x
   /bin/sun3
   /bin/sun2
   /bin/sun386
   /bin/sun
   /bin/i386
   /bin/iAPX286
   /bin/rs6000
   /bin/ibmrt
'

system=""

for cmd in ${commands} ; do
   if [ -x ${cmd} ] && ${cmd} ; then
      system="`basename ${cmd}`"
      break
   fi
done

case ${system} in
   hp9000s*)	 echo ${system} | sed 's=hp9000s\(.\).*=hp\100='	;;
   sun4*)  	 echo sun4 						;;
   sun3 | sun3x) echo sun3						;;
   sun2*)	 echo sun2						;;
   "")		 echo unknown						;;
   *)		 echo ${system}  					;;
esac

exit 0

#
# eof
#