#!/bin/bash

source /etc/DTBrand.sh

lib=/usr/lib/$DTBRAND_PATH_SUBDIR

# This is a simplified version of what we use in DTInit.sh.
determine_os() {
    local base="$1"

    if [ -r $base/etc/redhat-release ]; then
        if uname -r | egrep -q "^2.6.9"; then
            os=rhel4
        elif egrep -q "release 5" $base/etc/redhat-release; then
            os=rhel5
        elif egrep -q "release 6" $base/etc/redhat-release; then
            os=rhel6
        else
            os=unknown
            squawk "Cannot figure out what release of RHEL or CentOS this machine is running."
        fi
    elif [ -r $base/etc/SuSE-release ]; then
        if grep -q "VERSION = 9" $base/etc/SuSE-release; then
            os=suse93
        elif grep -q "VERSION = 10" $base/etc/SuSE-release; then
            os=sles10
        elif grep -q "VERSION = 11" $base/etc/SuSE-release; then
            os=sles11
        else
            os=unknown
            squawk "Unable to determine the version of Sles."
        fi
    else
        os=unknown
        squawk "Cannot figure out what OS this machine is."
    fi
    echo $os
}

determine_arch() {
    if [ $(uname -m) = "x86_64" ]; then
        echo 64;
    else
        echo 32;
    fi
}

if [ -x $lib/DTSubAgent ]; then
    subagent=$lib/DTSubAgent
else
    subagent=$lib/DTSubAgent-$(determine_os)-$(determine_arch)
fi

if [ ! -x $subagent ]; then
    echo >&2 "No usabable subagent at $subagent"
    exit 1
fi

exec $subagent "$@"

