#!/bin/sh
# This script works in two different ways. It can be invoked without
# arguments, and the user will be prompted for answers, or the arguments
# provide all the answers and there is no interaction

#---------------------------------------------------------------- functions ---

echon() { 
  echo "$@" | tr -d '\012'; 
}

tocd() {
  echo `tocddir $1$iso`; 
}

tocddir() {
  a=$1
  if [ $upcase = 1 ]; then
    a=`echo $a | tr '[a-z]' '[A-Z]'`
  else 
    a=`echo $a | tr '[A-Z]' '[a-z]'`
  fi;
  echo $a; 
}
  
tolower() {
  a=`echo $1 | tr '[A-Z]' '[a-z]'`;
  echo $a; 
}

GetPlatInfo() {
      case `uname` in
      SunOS) case `uname -r` in
             4*) MWOS=sunos4
                 MWARCH=sparc
                 MWCONFIG_NAME=sunos4
		 ;;
             5*) MWOS=sunos5
                 MWCONFIG_NAME=sunos5
                 case `uname -m` in
                 sun4*) MWARCH=sparc;;
                 i86*)  MWARCH=i86;;
                 *)     echo "Machine under sunos must be sun4 or i86pc" 1>&2;;
                 esac
		 ;;
             esac
	     ;;

      HP-UX)   case `uname -r` in
               [AB].09*) MWOS=ux9
	  	         MWCONFIG_NAME=ux9
               	         case `uname -m` in 
                         9000/[78]*) MWARCH=hp700;;
                         9000/3*)    MWARCH=hp300;; 
                         *) echo "HP-UX machine must be 9000/700 or 300 series" 1>&2;;
                         esac
			 ;;
               [AB].10*) MWOS=ux10
	                 MWCONFIG_NAME=ux10
                         case `uname -m` in 
                         9000/[78]*) MWARCH=hp700;;
                         *) echo "HP-UX machine must be 9000/700 series" 1>&2;;
                         esac
			 ;;
                A.08*)   MWOS=ux8;;
                [AB].11*) MWOS=ux11
			  MWCONFIG_NAME=ux11
                          case `uname -m` in
                          9000/[78]*) MWARCH=hp700;;
                          ia64)       MWARCH=ia64
				      MWCONFIG_NAME=ia64_ux11;;
                          *) echo "HP-UX machine must be 9000/700 series" 1>&2;;
                          esac
			  ;;
                 *)       echo "Unknown HP-UX version" 1>&2 ;;
               esac
	       ;;
      UNIX_SV) case `uname -r` in 
               4.2) MWOS=sysvr4_2
                    case `uname -m` in
                    i*86) MWARCH=i86;;
                    #add other SysV machines here
                    *) echo "Unknown SYS_V machine" 1>&2
                    esac
		    ;;
               4.2MP) MWOS=sysvr4_2
                      case `uname -m` in
                      R3000) MWARCH=mips;;
                      *) echo "Unknown SYS_V machine" 1>&2
                      esac;;
               *)     echo "Versions of SYS_V other than 4.2 are not supported" 1>&2;;
               esac
	       ;;

      AIX)  case `uname -v` in
             3) MWOS=aix3
	        MWCONFIG_NAME=aix3
                MWARCH=rs6000;;
            4|5) MWOS=aix4
	         MWCONFIG_NAME=aix4
                 MWARCH=rs6000;;
            *)   echo "Unknow version of AIX" 1>&2;;
            esac
	    ;;

      UNIX_System_V) case `uname -r` in
                     4.2) MWOS=sysvr4_2
                          case `uname -m` in
                          R3000) MWARCH=mips;;
                          *) echo "Unknown UNIX_System_V machine" 1>&2;;
                          esac
			  ;;
                      *)  echo "Versions of Unix System V other than 4.2 are not supported" 1>&2;;
                      esac
		     ;;

      IRIX*)
         # Silicon Graphics
         case `uname -r` in
         5.2)
         MWOS=irix5
         MWARCH=mips;;
         5.3)
         MWOS=irix53
         MWARCH=mips;;
         6.*)
         MWOS=irix6
         MWARCH=mips;;
         *) echo "Versions of Irix other than 5.2, 5.3, or 6.x are not supported";;
         esac;;
      OSF1)
         case `uname -r` in
            V3.*)
         MWOS=osf1v2
         MWARCH=alpha;;
            V4.*)
         MWOS=osf1v4
         MWARCH=alpha;;
         *) echo "Versions of OSF/1 other than 3.x / 4.x are not supported";;
         esac;;
         
      NEWS-OS)
         case `uname -r` in
         6.1)
         MWARCH=mips
         MWOS=news6;;
         *) echo "Versions of NEWS-OS other than 6.1 not supported";;
         esac;;
         
    #
    #  Linux
    #
      Linux)
         MWOS=linux
	 MWCONFIG_NAME=linux
         MWARCH=i86;;
      *)   
         # The  Motorola 88000 returns the name of the machine for uname
         # without any options same for SCO and some sysV.3 (seems to be a
         # bug in V.3) !
         case `uname -m` in
         m88k)
            MWOS=sysv4
            MWARCH=m88k;;
         #
         # this is for SCO3.2 and SCO5
         #
         i386)
            MWARCH=i86
            case `uname -s` in
            SCO_SV)
               MWOS=sco5;;
            *)
                  MWOS=sco3;;
            esac;;
         *) echo "Unknown architecture and operating system." 1>&2
         esac;;
      esac
      export MWOS
      export MWARCH
      export MWCONFIG_NAME
}

#MAIN
type=$1
if [ "$type" = "-h" ];then
  echo "Usage: getplatinfo [os |arch|config]"
fi
GetPlatInfo
if [ "$type" = ""  -o "$type" = "os" ];then 
  echo ${MWOS}
else if [ "$type" = "arch" ];then  
  echo ${MWARCH}
else if [ "$type" = "config" ];then
  echo ${MWCONFIG_NAME}
else
  echo "Usage: getplatinfo [os |arch |config]"
fi
fi
fi
exit 0

