#!/bin/sh
#
# Copyright (c) 2000-2011, 2018 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
. /etc/emulab/paths.sh

# We can ditch this script, I think.
if [ -r $BOOTDIR/nodeid -a -r $BOOTDIR/nodetype ]; then
    nt=`cat $BOOTDIR/nodetype`
    echo $nt
    exit 0
fi

# Why am I trying to fix this script!?
if [ -r $BOOTDIR/nodeid -a -r $BOOTDIR/ltpmap ]; then
    nid=`cat $BOOTDIR/nodeid`
    nt=`grep $nid $BOOTDIR/ltpmap 2>/dev/null | awk "/^H/ { if (\\$3 == \"$nid\") print \\$5 }" 2>/dev/null`
    if [ -n "$nt" ]; then
	echo $nt
	exit 0
    fi
fi

if [ -x $BINDIR/cpuspeed.awk ]; then
	cpuspeed=`$BINDIR/cpuspeed.awk /proc/cpuinfo`;
else
	cpuspeed='';
fi

if [ x$cpuspeed = x ] || [ $cpuspeed = 0 ]; then
	echo "unknown";

# XXX hack for minibed and buff pc600s
elif [ $cpuspeed = "850" -a -x $BINDIR/chipset.awk -a -e /proc/pci ]; then
    case `$BINDIR/chipset.awk /proc/pci` in
    BX)
	echo pc850	# normal pc850
	;;
    GX)
	echo pcL440GX	# minibed node
	;;
    BX-AGP)
	echo pc850a    # buff pc600 node
	;;
    *)
	echo unknown
   	;;
esac
# For Aerospace Corp and Rutgers nodes
elif [ $cpuspeed = "2400" -a -x $BINDIR/chipset.awk -a -e /proc/pci ]; then
    case `$BINDIR/chipset.awk /proc/pci` in
    HI_C)
	echo pc${cpuspeed}-aero;
	;;
    HI_B)
	echo pc${cpuspeed}-orbit;
	;;
    *)
	echo unknown
   	;;
    esac
# For Wiconsin nodes - they have a different node typing scheme
elif [ $cpuspeed = "2500" ]; then
	echo i2;

else
	echo pc$cpuspeed;
fi
