#! /bin/sh

# Shell script to determine the operating system type by various heuristics.

# If OSTYPE is set, use it. This allows a manual override.

case "$OSTYPE" in ?*) os="$OSTYPE";; esac

# If os is still unset, try to get a value from the uname command.

case "$os" in '') os=`uname -s`;; esac

# ... what else can be tried? Insert here any other bright ideas that might
# come to mind ...

# Failed to find OS by automatic means. 

case "$os" in
'') echo "" 1>&2
    echo "*** Failed to determine the operating system type." 1>&2
    echo "" 1>&2 
    echo UnKnown
    exit 1;;
esac

# A value has been obtained for the os. Some massaging may be needed in
# some cases to get a uniform set of values.

case "$os" in
# Convert what bash gives to what uname gives
Irix5)	 os=IRIX;;
hpux_9)  os=HP-UX;;
Ultrix)  os=ULTRIX;;
BSD/OS)  os=BSDI;;
# Convert what tcsh sets OSTYPE to
solaris) os=SunOS5;;
sunos4)  os=SunOS4;;
# Convert what some Linuxes set in OSTYPE
linux)   os=Linux;;
esac

# In the case of SunOS we need to distinguish between SunOS4 and SunOS5.

case "$os" in
SunOS)	case `uname -r` in
	5*)	os="${os}5";;
	4*)	os="${os}4";;
	esac
esac

# Need to tell SunOS5 from the version on the HAL (64bit sparc, CC=hcc -DV7).

case "$os" in
SunOS5) case `uname -m` in
        sun4H)  os="${os}-hal";;
        esac
esac

# OK, the script seems to have worked. Pass the value back.

echo "$os"

# End of os-type
