#!/bin/sh

# bbclient
# SCRIPT TO CREATE BIG BROTHER CLIENT TARBALLS
# Sean MacGuire - The MacLawran Group Inc.
# Version 1.4
# Mar 05th, 2000

#
# This program is Copyright (c) 1997-2000
# The MacLawran Group Inc.
# All Rights Reserved
#
# THIS SCRIPT MUST BE RUN FROM HERE!
# USE ONLY IF THE CLIENTS ARE RUNNING THE SAME OS!!!
#
# 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

# Save the BB base directory
currpwd=`pwd`
cd ..
OLDIFS=$IFS
IFS='/'
set `pwd`
IFS=$OLDIFS
shift `expr $# - 1`
BBASE=$1

cd $currpwd

# START MAKING THE CLIENT LIST...
# EVERY ONE GETS THESE...
echo "*** Adding standard things..."
echo "$BBASE/README
	$BBASE/README.INSTALL
	$BBASE/LICENSE
	$BBASE/runbb.sh
	$BBASE/tmp/.helloworld
	$BBASE/etc
	$BBASE/bin
	$BBASE/ext
	$BBASE/bin/bb-local.sh
	$BBASE/bin/bb
	$BBASE/bin/bbrun" > /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 "	$BBASE/www/
		$BBASE/web/" >> /tmp/BBLIST
fi

grep BBPAGER /tmp/BB.$$ > /dev/null 2>&1
if test "$?" = "0"
then
	echo "*** Adding Big Brother Pager Server things..."
	# Add only if host is not BBDISPLAY also
	if test "$BBSERVER" != "TRUE"
	then
		echo "	$BBASE/www/
			$BBASE/web/" >> /tmp/BBLIST
		BBSERVER="TRUE"
	fi
fi

grep BBNET /tmp/BB.$$ > /dev/null 2>&1
if test "$?" = "0"
then
	echo "*** Adding Big Brother Network Monitor things..."
	# Nothing to add for now
fi

#
# IF WE NEED THE BIG BROTHER DAEMON ON THIS MACHINE THEN ADD IT
#
if test "$BBSERVER" = "TRUE"
then
	echo "*** Adding Big Brother Daemon..."
	# Nothing to add for now
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}

Do not forget to edit PROCS/PAGEPROC in bbdef.sh on ${CLIENT}
Also modify BBHOME and BBEXT in runbb.sh if required"
