#!/bin/sh
#
# setPath - create platform override path
#


OS=`uname -s`

if [ "$OS" != "UnixWare" ]
then
    OS_VERSION=`uname -r`
else
    OS_VERSION=`uname -v`
    OS_RELEASE=`uname -r`
fi

ARCH=`uname -m`
MACHINE_NAME=`uname -n`
 
BASE=`pwd`
SCRIPTS=$BASE/scripts

PATH=$SCRIPTS/generic:$PATH           # Prepend generic scripts to path
PATH=$SCRIPTS/$OS:$PATH               # Prepend platform dependent scripts

# If we find a newer version than we support then we use the Latest set
# of scripts as the best chance of getting a working compile. Better
# than the old default OS scripts, but not guaranteed to work.

if [ -d $SCRIPTS/$OS/Latest ]
then
    OS_DIR_PATH=`$SCRIPTS/generic/deReference $SCRIPTS/$OS/Latest`
    LATEST_SUPPORTED_OS_VERSION=`basename $OS_DIR_PATH`

    # note newerOS is flawed - it assumes #.#.#  format with only numerics ...
    # it ignores the trailing -# if any exists... 
    
    USE_LATEST=`$SCRIPTS/generic/newerOS $OS_VERSION $LATEST_SUPPORTED_OS_VERSION`

    if [ "$USE_LATEST" != "0" ]
    then
    	if [ ! -f .useLatestScripts ]
	then
            echo
            echo "Note: The current OS is newer than the latest one the program was tested on!"
            echo "Note: The latest set of scripts might work, give them a try."
	fi

        PATH=$SCRIPTS/$OS/Latest:$PATH   # Prepend Latest version specific scripts

    	if [ ! -f .useLatestScripts ]
	then
            echo
            echo -n "Continue config/make with most recent scripts? (y/n) "
	    read resp
	    if [ "$resp" = "y" -o "$reps" = "Y" ]
	    then
	 	touch .useLatestScripts
	    else
	    	exit
	    fi
	fi
    else
        PATH=$SCRIPTS/$OS/$OS_VERSION:$PATH   # Prepend any version specific scripts
    fi
fi


if [ -d $SCRIPTS/$ARCH ]
then
    PATH=$SCRIPTS/$ARCH:$PATH # Prepend any gneric architecture scripts
fi

if [ -d $SCRIPTS/$OS/$OS_VERSION/$ARCH ]
then
    PATH=$SCRIPTS/$OS/$OS_VERSION/$ARCH:$PATH # Prepend any OS architecture scripts
fi

if [ -d $SCRIPTS/Local ]
then
    PATH=$SCRIPTS/Local:$PATH # Local policy scripts
fi

if [ -L $SCRIPTS/Local/$MACHINE_NAME ]
then
    PATH=$SCRIPTS/Local/$MACHINE_NAME:$PATH # machine specific scripts
fi

if [ -L $SCRIPTS/Local/Install ]
then
    PATH=$SCRIPTS/Local/Install:$PATH # Install overrides.
fi
# Add the compiled probes to the path

PATH=$SCRIPTS/localize/probes:$PATH

export OS OS_VERSION PATH


