#!/bin/sh

#
# BIG BROTHER
#
# SCRIPT TO MAKE BIG BROTHER CLIENTS
#
# THIS SCRIPT MUST BE RUN FROM HERE!
#
# Format: bbclient <CLIENT-MACHINE-NAME>
#

if test "$#" != "1"
then
	echo "bbclient: Wrong number of arguments!
	Format: ./bbclient [client-machine-name]"
	exit 1
else
	CLIENT=$1
fi

#
# FIRST, SEE IF THIS MACHINE IS EITHER THE DISPLAY SERVER
# THE PAGER SERVER, OR BOTH...
#
grep "$CLIENT" ../etc/bb-hosts > /tmp/BB.$$
if test "$?" != "0"
then
	echo "bbclient: $CLIENT not defined in ../etc/bb-hosts!"
	exit 2
fi

# START MAKING THE CLIENT LIST...
# EVERY ONE GETS THESE...

echo "*** Adding standard things..."
echo "bb/README
	bb/runbb.sh
	bb/etc
	bb/bin
	bb/bin/bb-local.sh
	bb/bin/bb" > /tmp/BBLIST


grep BBDISPLAY /tmp/BB.$$ > /dev/null 2>&1
if test "$?" = "0"		# WE'RE A DISPLAY SERVER
then
	echo "*** Adding Big Brother Display things..."
	BBSERVER="TRUE"
	echo " bb/bin/touchtime
		bb/www/
		bb/web/" >> /tmp/BBLIST
fi

grep BBPAGER /tmp/BB.$$ > /dev/null 2>&1
if test "$?" = "0"
then
	echo "*** Adding Big Brother Pager Server things..."
	BBSERVER="TRUE"
	echo "bb/bin/bb-page.sh" >> /tmp/BBLIST
fi

grep BBNET /tmp/BB.$$ > /dev/null 2>&1
if test "$?" = "0"
then
	echo "*** Adding Big Brother Network Monitor things..."
	echo "bb/bin/bbnet" >> /tmp/BBLIST
	echo "bb/bin/bb-network.sh" >> /tmp/BBLIST
fi

#
# IF WE NEED THE BIG BROTHER DAEMON ON THIS MACHINE THEN ADD IT
#
if test "$BBSERVER" = "TRUE"
then
	echo "*** Adding Big Brother Daemon..."
	echo "bb/bin/bbd" >> /tmp/BBLIST
fi
rm -f /tmp/BB.$$		# DON'T NEED THIS ANY MORE...

cd ../..
echo "*** Creating tar file for Big Brother on $CLIENT"
tar cvf bb-${CLIENT}.tar `cat /tmp/BBLIST`
rm -f /tmp/BBLIST

echo "*** Done.

The Big Brother Client archive has been created.  It's called:
	bb-${CLIENT}.tar
and lives in the directory above the bb directory.

You can now install Big Brother on ${CLIENT}"
