#!/bin/sh

# bbconfig
# BIG BROTHER - AUTOMATIC CONFIG SCRIPT
# Sean MacGuire - BB4 Technologies Inc.
# Version 1.5a
# Aug 30th, 2000
#
# Copyright (c) 1997-2000 BB4 Technologies Inc. - All Rights Reserved

#--------------------------------------------------------
# FIGURE OUT WHERE WE ARE AND SET BBHOME
#--------------------------------------------------------

PROG="$0"; export PROG
OSARG="$1"
# put all OS type to lower case
# thanks for the tip to "Thomas E. Alex" <talex@commgensys.com>
OSARG=`echo "$OSARG" | tr '[A-Z]' '[a-z]' `
ARGNUM="$#"
NAME=`basename $0`; export NAME
DIR=`echo $PROG | sed "s/${NAME}$//"`

cd $DIR				# GET TO THE INSTALL DIRECTORY
cd ..				# GO UP TO BBHOME
BBHOME=`pwd`			# SET IT THE EASY WAY
cd $DIR				# GO BACK WHERE WE WERE...

#--------------------------------------------------------
# WHAT VERSION OF echo?
#--------------------------------------------------------
# Find out which version of echo we have
# So we use the proper directive to not print out the newline character
# There are differences in echo on a SYSV system and a *BSD based system

testline=`echo -n bobo`
# echo "TESTLINE=$testline"

if [ "$testline" = "bobo" ]
then
	ECHOOPTION=" -n "
	ECHOTAIL=""
else
	ECHOOPTION=""
	ECHOTAIL='\c'
fi


tput clear

#--------------------------------------------------------
# WE REALLY SHOULD TRY TO FIGURE WHAT MACHINE WE'RE ON.
#--------------------------------------------------------

set `uname -a`
VERSION="$3"
if [ "$OSARG" = "" ]
then
	MACHINE="$1"		# THIS IS WHAT THE MACHINE THINKS IT IS
	MACHINE=`echo "$MACHINE" | tr '[A-Z]' '[a-z]' `
	# echo MACHINE IS $MACHINE
else
	MACHINE=$OSARG
fi

case $MACHINE
in
	linux )
		# ARE WE A REDHAT MACHINE?
		grep "Red" /etc/issue >/dev/null
		if test "$?" = "0"
		then
			MACHINE="redhat"
		fi
		grep "Caldera" /etc/issue > /dev/null
		if test "$?" = "0"
		then
			MACHINE="caldera"
		fi
		echo "$3" | grep "mdk" 2>&1 >/dev/null
		if [ "$?" -eq 0 ]
		then
			MACHINE="mandrake"
		fi
		;;

	sunos )
		echo "VERSION=$VERSION"
		VERSION=`echo $VERSION | sed "s/\.//g"`
		echo "VERSION=$VERSION"
		if test "$VERSION" -ge "24"
		then
			MACHINE="solaris"
		fi
		;;

	hp-ux )
		MACHINE="hpux"
		;;

	bsdi )
		OLDIFS=$IFS
		IFS='.'
		set $3 >/dev/null 2>&1
		IFS=$OLDIFS
		if [ "$#" -gt 1 -a "$1" -ge 4 ]
		then
			if [ "$1" -gt 4 -o "$2" -ge 1 ]
			then
				MACHINE="bsdi4"
			fi
		fi
		;;

	irix* )
		MACHINE=irix
		;;

	unixware* )
		VERSION=`echo $4 | sed "s/\./ /g"`
		set $VERSION
		if test "$VERSION" -ge "7"
		then
			MACHINE="unixware7"
		fi
		;;
esac

OS="bsdi bsdi4 sco3 sco freebsd solaris hpux9 hpux linux sunos netbsd osf ultrix irix unixware unixware7 redhat aix dynix debian dgux openbsd caldera mandrake sinix"

#--------------------------------------------------------
# SET UP BBHOME
#--------------------------------------------------------

if test "$ARGNUM" != "1"
then
echo "

	Welcome to the Big Brother installation procedure...
	The first thing we need to know is that OS you're
	running...

	Choose one of the following: $OS

"
	echo $ECHOOPTION "Please enter your OS: [$MACHINE]: $ECHOTAIL"
	read ANS

	if test "$ANS" != ""
	then
		MACHINE="$ANS"
	fi
fi

echo $OS | grep "$MACHINE" > /dev/null 2>&1
if test "$?" = "1"
then
	echo "---> $MACHINE unsupported... configure manually"
	echo "---> ./bbconfig [OS]"
	echo "--->	where OS is one of: $OS"
	exit 2
else
	echo "---> OK, we'll try $MACHINE..."
fi

case ${MACHINE}
in
	solaris )
		# Force the use of /usr/xpg4/bin if it's available
		if [ ! -d  /usr/xpg4/bin ]
		then
			echo "** It is stronly suggested that you get the xpg4 package **
** and install it on this server and rerun this script **
** before continuing any further **"
		fi
		;;
esac

#--------------------------------------------------------
# WARN ABOUT RUNNING BB AS root
#--------------------------------------------------------

STOPROOT=""
while [ "$STOPROOT" = "" ]
do
	STOPROOT="y"

		echo "

*** WARNING: Don't run BB as root ! ***
             Executing BB as root is not recommended

"

	echo $ECHOOPTION "Prevent the execution of BB as user 'root' (y/n) [$STOPROOT]: $ECHOTAIL"
	read ANS

	ANS=`echo "$ANS" | tr '[A-Z]' '[a-z]'`

	if [ "$ANS" != "" ]
	then
		STOPROOT="$ANS"
	fi

	if [ "$STOPROOT" = "y" ]
	then
		echo "---> OK... BB is NOT ALLOWED to run as root"
		STOPROOT=TRUE
	elif [ "$STOPROOT" = "n" ]
	then
		echo "---> OK... BB is ALLOWED to run as root"
		STOPROOT=FALSE
	else
		ANS=""
		STOPROOT=""
	fi
done

BBUSER=""
while [ "$BBUSER" = "" ]
do

	echo "

	BB will only start under a designated user id. The
	startup script will verify that the current user ID
	and the designated user ID are identical.
	Note: This check is only performed during the startup script.
              It does not prevent the execution of other BB binaries/scripts
              while working using another user ID. It only prevents
              you from starting BB while working another user ID.
        " 

	BBUSER="bb"

	echo $ECHOOPTION "What will be the user ID of BB [$BBUSER]: $ECHOTAIL"
	read ANS

	ANS=`echo "$ANS" | tr '[A-Z]' '[a-z]'`

	if [ "$ANS" != "" ]
	then
		BBUSER="$ANS"
	fi

	if [ "$BBUSER" = "root" -a "$STOPROOT" = "TRUE" ]
	then
		echo "---> User root has been previously disallowed"
		BBUSER=""
		continue
	fi

	if [ -r "/etc/passwd" ]
	then
		grep "^$BBUSER:" /etc/passwd >/dev/null 2>&1
		if [ "$?" -eq 0 ]
		then
			echo "---> BB will only run from user '$BBUSER'"
		else
			echo "---> User '$BBUSER' has not yet been created"
			echo "---> Don't forget to create the user '$BBUSER'"
		fi
	else
		echo "---> bbconfig could not read /etc/passwd ..."
		echo "---> User '$BBUSER' should be a valid user ID"
	fi
done

#--------------------------------------------------------
# SET UP BBHOME
#--------------------------------------------------------

echo "
	Making sure BBHOME <$BBHOME> is writable...
"

if [ ! -w "$BBHOME" ]
then
	echo "<$BBHOME> is not a writable directory"
	echo "Please become root or change permissions".
	echo "Exiting."
	exit 1
	ANS=""
fi
echo "---> OK, $BBHOME is fine..."

#-----------------------------------------------------
# SET UP OLD-STYLE DIRECTORY STRUCTURE
#-----------------------------------------------------

OLDSTYLE=""
while [ "$OLDSTYLE" = "" ]
do
	echo "

	Do you want to preserve the old style directory structure ?
	You may want to do so if you use BB extensions or
	externals that do not understand the new directory structure.
	This option is *NOT* recommend as keeping the old directory
	around represents a security risk.
	"
	ANS=""
	echo $ECHOOPTION "Old-style directory structure (y/n): [n] $ECHOTAIL"
	read ANS

	if [ "$ANS" = "" ]
	then
		OLDSTYLE="n"
	else
		if [ "$ANS" != 'y' -a "$ANS" != 'Y' -a "$ANS" != 'n' -a "$ANS" != 'N' ]
		then
			OLDSTYLE=""
		else
			OLDSTYLE="$ANS"
		fi
	fi
done

# Get the top directory in the BB structure
OLDIFS=$IFS
IFS="/"
set $BBHOME
IFS=$OLDIFS
BBTOP=""
while [ "$#" -gt 1 ]
do
        # Don't accept empty args
        if [ "$1" != "" ]
        then
                BBTOP="$BBTOP/$1"
        fi
        shift
done
BBVAR=$BBTOP/bbvar

if [ "$OLDSTYLE" = "y" -o "$OLDSTYLE" = "Y" ]
then
	ln -s $BBVAR/acks $BBHOME/www/acks
	ln -s $BBVAR/data $BBHOME/www/data
	ln -s $BBVAR/disabled $BBHOME/disabled
	ln -s $BBVAR/hist $BBHOME/www/hist
	ln -s $BBVAR/histlogs $BBHOME/www/histlogs
	ln -s $BBVAR/logs $BBHOME/www/logs
fi

#--------------------------------------------------------
# SET UP FQDN
#--------------------------------------------------------

FQDN="y"
BBFQDN="FALSE"
while [ "$BBFQDN" != "TRUE" -a "$BBFQDN" != "" ]
do
	echo "

	When you set up your machines, you should use Fully Qualified
	Domain names, this means you use the whole name, like www.bb4.com,
	instead of just 'www'.  This is recommended.
	"
	echo $ECHOOPTION "Use FQDN (y/n): [$FQDN] $ECHOTAIL"
	read ANS

	if [ "$ANS" = "" ]
	then
		BBFQDN="TRUE"
		echo "---> Good, we'll use FQDN"
	else
		if [ "$ANS" = 'y' -o "$ANS" = 'Y' ]
		then
			BBFQDN="TRUE"
			echo "---> Good, we'll use FQDN"
		else
			BBFQDN=""
			echo "---> OK... if you must..."
		fi
	fi
done

#--------------------------------------------------------
# SET UP BBDISPLAY
#--------------------------------------------------------

THISHOST=`hostname 2>/dev/null`

BBDISPLAY=""
while [ "$BBDISPLAY" = "" ]
do
	BBDISPLAY="$THISHOST"

	echo "

	Big Brother creates HTML pages with the status of your network.
	You'll need a web server to publish this information.
	"
	echo $ECHOOPTION "What machine will be the BBDISPLAY [$BBDISPLAY]: $ECHOTAIL"
	read ANS

	if [ "$ANS" = "" ]
	then
		echo "---> OK... $BBDISPLAY will be a BBDISPLAY"
	else
		BBDISPLAY=$ANS
		echo "---> OK... $BBDISPLAY will be a BBDISPLAY"
	fi
	
	BBDISPLAY=`echo "$BBDISPLAY" | tr '[A-Z]' '[a-z]'`
done

if [ "$BBFQDN" = "TRUE" ]
then
	OLDIFS=$IFS
	IFS="."
	set $BBDISPLAY
	IFS=$OLDIFS

	if [ "$#" -eq 1 ]
	then
		echo "
---> !!! FQDN=y while the BBDISPLAY ($BBDISPLAY) is not!
"
	fi
fi

#--------------------------------------------------------
# SET UP BBPAGER
#--------------------------------------------------------

BBPAGER=""
while [ "$BBPAGER" = "" ]
do
	BBPAGER=$BBDISPLAY

	echo "
	Big Brother sends important messages to a pager server.  This
	machine will at a minimum to be able to send mail. 
	"

	echo $ECHOOPTION "What machine will be the BBPAGER [$BBPAGER]: $ECHOTAIL"
	read ANS

	if [ "$ANS" = "" ]
	then
		echo "---> OK... $BBPAGER will be a BBPAGER"
	else
		BBPAGER=$ANS
		echo "---> OK... $BBPAGER will be a BBPAGER"
	fi
	
	BBPAGER=`echo "$BBPAGER" | tr '[A-Z]' '[a-z]'`
	
done

if [ "$BBFQDN" = "TRUE" ]
then
	OLDIFS=$IFS
	IFS="."
	set $BBPAGER
	IFS=$OLDIFS

	if [ "$#" -eq 1 ]
	then
		echo "
---> !!! FQDN=y while the BBPAGER ($BBPAGER) is not!
"
	fi
fi

echo "
	Some questions regarding the current host
	($THISHOST) will be asked. 
"

DOWEB="y"
while [ "$DOWEB" != "TRUE" -a "$DOWEB" != "FALSE" ]
do
        echo $ECHOOPTION "
Is this host a BBDISPLAY host (y/n): [$DOWEB] $ECHOTAIL"
	read ANS
	if [ "$ANS" = "" ]
	then
		ANS=$DOWEB
	fi
	if [ "$ANS" = 'y' -o "$ANS" = 'Y' ]
	then
		DOWEB=TRUE
	else
		DOWEB=FALSE
	fi
done

DOPAGE="y"
while [ "$DOPAGE" != "TRUE" -a "$DOPAGE" != "FALSE" ]
do
        echo $ECHOOPTION "
Is this host a BBPAGER host (y/n): [$DOPAGE] $ECHOTAIL"
	read ANS
	if [ "$ANS" = "" ]
	then
		ANS=$DOPAGE
	fi
	if [ "$DOPAGE" = 'y' -o "$ANS" = 'y' -o "$ANS" = 'Y' ]
	then
		DOPAGE=TRUE
	else
		DOPAGE=FALSE
	fi
done

DEFAULTPAGE=""
if [ "$DOPAGE" = "TRUE" ]
then
	while [ "$DEFAULTPAGE" = "" ]
	do
		DEFAULTPAGE="root@localhost"
        	echo $ECHOOPTION "
Enter the default recipient: [$DEFAULTPAGE] $ECHOTAIL"
        read ANS
	if [ "$ANS" != "" ]
	then
		DEFAULTPAGE=$ANS
	fi
done                            

fi

#--------------------------------------------------------
# SET URL OF BB
#--------------------------------------------------------

BBWEB=""
if [ "$DOWEB" = "TRUE" ]
then
while [ "$BBWEB" = "" ]
do
	echo "
	Since Big Brother produces results to be displayed on web
	pages, we need to know where to view these results.
	"
	echo $ECHOOPTION "Enter the base URL for BB [/bb]: $ECHOTAIL"
	read ANS
	if test "$ANS" != ""
	then
		BBWEB="$ANS"
	else	
		BBWEB="/bb"
	fi
	echo "$BBWEB" | grep ".*/$" >/dev/null 2>&1
	if [ "$?" -eq 0 ]
	then
		echo "
The base URL <$BBWEB> is invalid, it should not terminate with a '/'
"
		BBWEB=""
	else
		BBWEB=`echo $BBWEB | sed 's/[ 	]//g'`
		case "$BBWEB" in
			/* )
				BBWEBHOST="http://$BBDISPLAY"
				;;	# It's clean

			http* )
				BBWEBURL="$BBWEB"
				case $BBWEB in
					http://* )
						BBWEB=`echo "$BBWEBURL" | sed 's!^http://[^/]*/!/!g'`
						BBWEBHOST=`echo "$BBWEBURL" | sed "s!$BBWEB!!g"`
						;;
					https://* )
						BBWEB=`echo "$BBWEBURL" | sed 's!^https://[^/]*/!/!g'`
						BBWEBHOST=`echo "$BBWEBURL" | sed "s!$BBWEB!!g"`
						;;
					* )
						echo "
The base URL <$BBWEB> is invalid, it should begin with a '/',http:// or https://
"
						BBWEB=""
						continue
						;;
				esac
	
				;;

			* )
				echo "
The base URL <$BBWEB> is invalid, it should begin with a '/',http:// or https://
"
				BBWEB=""
				continue
				;;
		esac
		echo "---> OK... Big Brother will live under ${BBWEBHOST}${BBWEB}"
	fi
done

#--------------------------------------------------------
# SET LOCATION OF CGI DIRECTORIES
#--------------------------------------------------------

CGIBIN=""
while [ "$CGIBIN" = "" ]
do
	echo "
	Big Brother also uses CGI scripts to create dynamic output.
	What directory do these scripts live in?
	"
	echo $ECHOOPTION "Enter CGI directory [/home/www/httpd/cgi-bin]: $ECHOTAIL"
	read ANS
	if test "$ANS" != ""
	then
		CGIBIN="$ANS"
	else	
		CGIBIN="/home/www/httpd/cgi-bin"
	fi

	if [ ! -d "$CGIBIN" ]
	then
		echo "***---> $CGIBIN doesn't exist..."
		CGIBIN=""
	elif [ ! -w "$CGIBIN" ]
	then
		echo "***---> $CGIBIN isn't writable..."
		CGIBIN=""
	else
		WEB="OK"
		echo "---> OK... CGI scripts will live at $CGIBIN"
	fi
done

#--------------------------------------------------------
# SET CGI SCRIPTS URL LOCATION
#--------------------------------------------------------

CGIBINURL=""
while [ "$CGIBINURL" = "" ]
do
	CGIBINURL="/cgi-bin"
	echo $ECHOOPTION "Enter the base URL of the CGI scripts [$CGIBINURL]: $ECHOTAIL"
	read ANS
	if test "$ANS" != ""
	then
		CGIBINURL="$ANS"
	fi

	echo "---> OK... The base URL location of CGI scripts is in $CGIBINURL"
done

fi	# "$DOWEB" = TRUE

cd $BBHOME

#--------------------------------------------------------
# NOW COPY STUFF ACROSS
#--------------------------------------------------------

echo "
--------------------------------------------------------
"
echo "--> UPDATING Makefile"

cp install/Makefile.${MACHINE} src/Makefile

# Insert OS specific -D option
# Not yet implemented
BBOSTYPE=`echo $MACHINE | tr '[a-z]' '[A-Z]'`
cat src/Makefile | sed "s/&BBOSTYPE/$BBOSTYPE/g" > tmp/Makefile.$$
mv tmp/Makefile.$$ src/Makefile

echo "--> UPDATING runbb.sh"
cat runbb.sh.DIST | sed "s:&BBHOME:$BBHOME:g" > runbb.sh
chmod 755 runbb.sh

echo "--> UPDATING bbsys.local"

cp install/bbsys.${MACHINE} etc/bbsys.local

echo "--> CHECKING COMMAND PATHNAMES"

$BBHOME/etc/bbchkcmds.sh

echo "--> UPDATING bbdef.sh"


# Insert OS specific in an env variable
cat etc/bbdef.sh.DIST | sed "s/&BBOSTYPE/$MACHINE/g" > tmp/bbdef.sh
# Insert FQDN specific into bbdef.sh
cat tmp/bbdef.sh | sed "s/&BBFQDN/$BBFQDN/g" > tmp/bbdef.sh.$$
# Insert if BB is prevented to run a root
cat tmp/bbdef.sh.$$ | sed "s/&STOPROOT/$STOPROOT/g" > tmp/bbdef.sh
# Insert BB's user ID into bbdef.sh
cat tmp/bbdef.sh | sed "s/&BBUSER/$BBUSER/g" > tmp/bbdef.sh.$$
mv tmp/bbdef.sh.$$ etc/bbdef.sh
rm -f tmp/bbdef.sh tmp/bbdef.sh.$$

if [ "$DOWEB" = "TRUE" ]
then
	# Insert WEB specific into bbdef.sh
	echo "--> UPDATING URL location"

	# OOps must do BBWEBHOST before BBWEB
	# Thanks to helge.jacobsen@mch.sbs.de
	# FULL URL of BBDISPLAY
	cat etc/bbdef.sh | sed "s!&BBWEBHOST!$BBWEBHOST!g" > tmp/bbdef.sh.$$
	# Base URL location
	cat tmp/bbdef.sh.$$ | sed "s!&BBWEB!$BBWEB!g" > tmp/bbdef.sh
	# Base URL location of CGI scripts
	cat tmp/bbdef.sh | sed "s!&CGIBINURL!$CGIBINURL!g" > tmp/bbdef.sh.$$
	mv tmp/bbdef.sh.$$ etc/bbdef.sh

	cat www/help/bb-ack.html.DIST | sed "s!&CGIBINURL!$CGIBINURL!g" > tmp/bb-ack.html.$$
	mv  tmp/bb-ack.html.$$ www/help/bb-ack.html

	cat www/help/bb-rep.html.DIST | sed "s!&CGIBINURL!$CGIBINURL!g" > tmp/bb-rep.html.$$
	mv  tmp/bb-rep.html.$$ www/help/bb-rep.html
fi

if test "$DOWEB" = "TRUE"
then
	echo "--> INSTALLING CGI scripts"
	# setup BB's CGI scripts
	for script in bb-hist.sh bb-histlog.sh bb-ack.sh bb-hostsvc.sh bb-rep.sh bb-replog.sh
	do
		# Does the script already exists ?
		RC="Y"
		if [ -f "$CGIBIN/${script}" ]
		then
			RC=""
			while [ "$RC" != "Y" -a "$RC" != "N" ]
			do
				echo $ECHOOPTION "Overwrite the current version of $CGIBIN/${script} (y/n)?: $ECHOTAIL"
				read RC
				RC=`echo "$RC" | tr '[a-z]' '[A-Z]'`
			done
		fi
		if [ "$RC" = "Y" ]
		then
			if [ ! -f "$CGIBIN/${script}" -o -w "$CGIBIN/${script}" ]
			then
				cat web/${script}.DIST | sed "s!&&BBHOME!$BBHOME!1" > tmp/${script}.$$
				mv  tmp/${script}.$$ $CGIBIN/${script}
				chmod 755 $CGIBIN/${script}
			else
				echo "Can't create <$CGIBIN/${script}>: permission denied"
				echo "  Either fix the permissions and rerun this script"
				echo "  or create it manually (update BBHOME/BBWEB in the script)"
			fi
		fi
	done

	WEBUSER=""
	while [ "$WEBUSER" = "" ]
	do
		echo "
	BB needs to set the group name of the www/rep directory
	to the group name of the web server by using its user name
"
		echo $ECHOOPTION "Enter web server user id [nobody]: $ECHOTAIL"
		read ANS
		if test "$ANS" != ""
		then
			WEBUSER="$ANS"
		else	
			WEBUSER=nobody
		fi

		userline=`grep "^$WEBUSER:" /etc/passwd`
		if [ "$?" -ne 0 ]
		then
			echo "Invalid user id: $WEBUSER"
			WEBUSER=""
		else
			OLDIFS=$IFS
			IFS=':'
			set -f
			set $userline
			set +f
			IFS=$OLDIFS
			groupid=$4
			groupline=`grep ":$4:" /etc/group`
			if [ "$?" -ne 0 ]
			then
				echo "Group name for $WEBUSER could not be determined, using nobody"
				echo "    You will manually have to change the group name of the www/rep directory
"
				TMPWEBGROUP=nobody
			else
				IFS=':'
				set $groupline
				TMPWEBGROUP=$1
				IFS=$OLDIFS
			fi
		fi
	done

	WEBGROUP=""
	while [ "$WEBGROUP" = "" ]
	do
		echo "
	You may override the group name determined by the previous step.
"
		echo $ECHOOPTION "Enter group name [$TMPWEBGROUP]: $ECHOTAIL"
		read ANS
		if test "$ANS" != ""
		then
			WEBGROUP="$ANS"
		else	
			WEBGROUP="$TMPWEBGROUP"
		fi

		groupline=`grep "^$WEBGROUP:" /etc/group`
		if [ "$?" -ne 0 ]
		then
			echo "Invalid group name: $WEBGROUP"
			WEBGROUP=""
		fi
	done

	# Reset permissions of www/rep directory where availability reports are saved
	echo "
--> SETTING WRITE PERMISSION FOR OWNER AND GROUP FOR www/rep"
	chmod 775 www/rep
	echo "--> CHANGING THE GROUP ID OF www/rep"
	chgrp $WEBGROUP www/rep
	if [ "$?" -ne 0 ]
	then
		echo "
The group name of the www/rep directory could not be changed to the
group name ($WEBGROUP) of the web server.  Please set manually or
otherwise the availability reporting will fail.
"
	fi

fi

if [ "$DOPAGE" = "TRUE" ]
then
	echo "--> UPDATING bb-pager scripts"
	case ${MACHINE}
	in
		solaris )
			# Force the use of /usr/xpg4/bin if it's available
			if [ -d  /usr/xpg4/bin ]
			then
				cat bin/bb-page.sh.DIST | sed 's/\/bin\/sh/\/usr\/xpg4\/bin\/sh/1' > tmp/bb-page.sh.$$
				mv  tmp/bb-page.sh.$$ bin/bb-page.sh
				cat bin/bb-page1.sh.DIST | sed 's/\/bin\/sh/\/usr\/xpg4\/bin\/sh/1' > tmp/bb-page1.sh.$$
				mv  tmp/bb-page1.sh.$$ bin/bb-page1.sh
				cat etc/bbchkwarnrules.sh.DIST | sed 's/\/bin\/sh/\/usr\/xpg4\/bin\/sh/1' > tmp/bbchkwarnrules.sh.$$
				mv  tmp/bbchkwarnrules.sh.$$ etc/bbchkwarnrules.sh
			else
				echo "
	*** It is stronly suggested that you get the xpg4 package
	*** and install it on this server and rerun this script
	*** before continuing any further
			"
				fi
				;;
		*)
			cp bin/bb-page.sh.DIST bin/bb-page.sh
			cp bin/bb-page1.sh.DIST bin/bb-page1.sh
			cp etc/bbchkwarnrules.sh.DIST etc/bbchkwarnrules.sh
			;;
	esac
	chmod 755 bin/bb-page.sh
	chmod 755 bin/bb-page1.sh
	chmod 755 etc/bbchkwarnrules.sh

	# Insert the default recipient
	cat etc/bbwarnrules.cfg.DIST | sed "s/&DEFAULTPAGE/$DEFAULTPAGE/g" > etc/bbwarnrules.cfg
fi

echo "
--------------------------------------------------------
"
echo "--> Done.  Now do"
echo "               cd ../src"
echo "               make"
echo "               make install"
echo "               cd ../.."
echo "               chown -R $BBUSER bbvar bb<ver>"
echo "                    where bb<ver> is the new version's directory name"

if [ "$MACHINE" = "redhat" ]
then
	echo ""
	echo "Note to RedHat 6.1 users, ping is broken, please use ping from"
	echo "http://www.rpmfind.net/linux/RPM/redhat/6.0/i386/netkit-base-0.10-29.i386.html"
fi

exit 0
