#!/bin/sh

# Very simple script to copy the global hosts file over the local one
# while preserving the localhost entry.  Run on DETER master clients

grep 127\\.0\\.0\\.1 /etc/hosts > /tmp/hosts
cat $1 >> /tmp/hosts
cp /tmp/hosts /etc/hosts && rm /tmp/hosts


# XXX Danger, hack ahead.  Apparently our FC6-SMB image and emulab disagree
# about where gated lives.  This will alias it.
if [ ! -x /usr/sbin/gated ] ; then 
	if [ -x /sbin/gated ] ; then
		ln /sbin/gated /usr/sbin/gated
	fi
fi
/usr/local/etc/emulab/rc/rc.route 

# SEER feels pain and confusion if times are wrong.  This lays a big lick on
# ntp sets the time directly and then restarts it.  XXX FreeBSD incantation is
# untested.

case `uname` in 
	"FreeBSD")
		/etc/rc.d/ntpd stop
		/usr/sbin/ntpdate boss
		/etc/rc.d/ntpd start
		;;
	"Linux")
		/etc/rc.d/init.d/ntpd stop
		/usr/sbin/ntpdate boss
		/etc/rc.d/init.d/ntpd start
		;;
esac

# Execute any command passed in as a startcmd.  This basically daisy chains the
# startcmd.  This needs to become a perl script to have uniform behavior here.
echo "*$2* *$3*"
if [ ! -z "$2" ]; then 
	echo "calling *$2* *$3*"
	case `uname` in
		"FreeBSD")
			su -l "$2" -c "$3"
			;;
		"Linux")
			su "$2" --command="$3"
			;;
	esac
fi
