#!/bin/sh

func_usage ()
{
    echo "Usage:"
    echo "	$0 [build|install|clean]"
    echo
    echo "Check suitability for Xen build or install."
    echo "Exit with 0 if OK, 1 if not."
    echo
    echo "Calling with 'clean' removes generated files."
    exit 1
}

PATH=$PATH:/sbin:/usr/sbin
OS=`uname -s`
export PATH OS

if [ "$OS" = "SunOS" ]; then
	exit 0
fi

case $1 in
    build)
        check="CHECK-BUILD"
        ;;
    install)
        check="CHECK-INSTALL"
        ;;
    clean)
        exit 0
        ;;
    *)
        func_usage
        ;;
esac

failed=0

echo "Xen ${check} " `date`
for f in check_* ; do
    case $f in
        *~)
            continue
            ;;
        *)
            ;;
    esac
    if ! [ -x $f ] ; then
        continue
    fi
    if ! grep -Fq "$check" $f ; then
        continue
    fi
    echo -n "Checking $f: "
    if ./$f 2>&1 ; then
        echo OK
    else
        failed=1
    fi
done

exit ${failed}
