#!/bin/sh

syscompat=
sysname=
basecompat=i386_rh9:i386_linux24:i386_linux22:i386_linux3:i386_linux2:i386_linux1


if [ ! -f /etc/redhat-release ] || [ "`awk '{ print tolower($3); }' /etc/redhat-release`" != "enterprise" ]; then
    sysname=@sys
fi
if [ -z "$sysname" ]; then
    case "`awk '{ print $7; }' /etc/redhat-release`" in
	5)
	    if [ "`/bin/uname -i`" = "i386" ]; then
		sysname=i386_rhel5
		syscompat=i386_rhel4:i386_rhel3:$basecompat
	    else
		sysname=@sys
	    fi
	    ;;
	4)
	    if [ "`/bin/uname -i`" = "i386" ]; then
		sysname=i386_rhel4
		syscompat=i386_rhel3:$basecompat
	    else
		sysname=@sys
	    fi
	    ;;
	3)
	    sysname=i386_rhel3
	    syscompat=$basecompat
	    ;;
	*)
	    sysname=@sys
	    ;;
    esac
fi

    

while getopts CS i; do
    case "$i" in
	C)
	    echo $syscompat
	    ;;
	S)
	    echo $sysname
	    ;;
	\?)
	    echo "Usage: machtype [-CS]" 1>&2
	    exit 1
	    ;;
    esac
done

exit 0
