
#
#	Copyright (C) Enhanced Software Technologies, Inc. 1994
#
#	doinst.sh   BRU installation script for Linux
#
#  RCS CHANGE LOG 
#
#	doinst.sh,v
# Revision 1.0  1994/12/07  13:09:59  tjones
# Initial Linux installation.
#
#
#  DESCRIPTION
#
#	This script will install the bru executable and 
#	associated files and set the proper ownership
#	and permissions.
#
#	Normally, bru is installed in the /bin directory.
#	Since bru may be used to restore the system after
#	a crash, it is important that it reside in the
#	directory containing basic system utilities.
#
#	Copies of all the files will be stored in the /bru
#	directory.  This will contain a spare copy of
#	bru, in case /bin/bru is destroyed.
#
#	In case of a problem (after the /bru directory has been
#	set up), you can do a re-install with following commands:
#
#		cd /bru
#		./doinst.sh
#
#	This script assumes that all the distribution files
#	are in the current directory.
#
#

PATH=.:$PATH:/etc

###################################################################
#
# cleanup routine to remove or restore files 
#
###################################################################
cleanup ()
{
	ARG1=$1

	trap '' 1 2 3 15

	#
	#  remove any temporary commands
	#
	rm -f $SED_CMDS

	if [ "$ARG1" -ne 0 ]
	then
		echo "\nError # $ARG1 - BRU installation failed"
	fi
	
	#
	# check for old versions of bru that we may have saved
	#
	if [ -f "$OLD_BRU" ]
	then
		if [ "$ARG1" -ne 0 ]
		then
			if [ -f "$BRU" ]
			then
				rm $BRU		# delete bru just installed
			fi
			mv $OLD_BRU $BRU	# restore original bru
			if [ "$?" -eq 0 ]
			then
				echo "Restored old version of bru"
			else
				echo "Unable to restore old version of bru"
			fi
		fi
	fi

	if [ "$ARG1" -ne 0 ]
	then
		exit $ARG1		# exit if code was not zero
	fi
	return 0
}

#######################################################################
#
# errexit generic error display 
# pass the title and text as arguments in the call
# i.e.:
#   errexit "Installation Failed" "Unable to create directory"
#
#######################################################################

errexit ()
{
	TITLE=$1
	TEXT=$2

	dialog --title "$TITLE" --infobox "\n$TEXT" 5 74 
	exit 1
}

######################################################################
#
# serialize routine
#
######################################################################

serialize ()
{
	dialog --title "BRU Serialization" --inputbox \
	"Please enter the serial number from your
BRU installation diskette.  It is
SAFE to remove it from the drive
at this time." 13 62 2>/tmp/serial$$
SERERR=$?
if [ $SERERR = 0 ]
then
	sernum=`cat /tmp/serial$$`
	echo 1000-$sernum > /bru/.serial_number
else
	dialog --title "Install Error" --msgbox \
"You MUST enter your serial number for BRU support purposes" 5 62
serialize
fi
}


######################################################################
#
# buildBrutab routine
#
######################################################################

buildBrutab ()
{
TITLE="BRUTAB Parameters"
DEFFLOPPY="/dev/fd0H1440"
DEFFSIZE="1440k"
DEFTAPE="/dev/rmt0"
DEFTSIZE="150MT"
# BRUTAB="/etc/brutab"
DMAXWRITES="500"
DOVERWRITEPROTECT="YES"
DOVERWRITEDAYS="7"

dialog --title "$TITLE" --msgbox \
"BRU uses a configuration file called /etc/brutab to identify system \
resources and default operational parameters. You will now be asked \
questions regarding your system configuration and various BRU options." \
8 68

dialog --title "$TITLE" --yesno \
"\nThe default floppy device is $DEFFLOPPY\nIs this correct?" 8 60

yn=$?
if [ "$yn" = "255" ]
then
	errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
fi
if [ "$yn" = "1" ]
then
	FLOPPY=""
	FSIZE=""
	dialog --title "$TITLE" --inputbox \
"Enter the appropriate default floppy device name" 9 50 2>/tmp/floppy
	fchange=$?
	if [ "$fchange" = "1" -o "$fchange" = "255" ]
	then
		rm -f /tmp/floppy
		errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
	else
		FLOPPY="`cat /tmp/floppy`"
		rm -f /tmp/floppy
	fi
	dialog --title "$TITLE" --inputbox \
"What is the size of $FLOPPY\n(i.e.: 1440k, 720k  - must be in k)" \
9 48 2>/tmp/fsize
	schange=$?
	if [ "$schange" = "1" -o "$schange" = "255" ]
	then
		rm -f /tmp/fsize
		errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
	else
		FSIZE="`cat /tmp/fsize`"
		rm -f /tmp/fsize
	fi
fi
dialog --title "$TITLE" --yesno "Do you have a tape drive?" 5 40
tape=$?
if [ "$tape" = "0" ]
then
	dialog --title "$TITLE" --yesno "The default tape device is $DEFTAPE \
with a size of $DEFTSIZE. is this correct for your system?" 8 50
ctape=$?
	if [ "$ctape" = "255" ]
	then		
		errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
	fi
	if [ "$ctape" = "1" ]
	then
		dialog --title "$TITLE" --inputbox "Enter the default tape device" \
		8 40 2>/tmp/tape
		ctape=$?
		if [ ! "$ctape" = "0" ]
		then
			rm -f /tmp/tape
			errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
		else
			TAPE="`cat /tmp/tape`"
			rm -f /tmp/tape
		fi
		dialog --title "$TITLE" --inputbox "Enter the size of $TAPE.
\nThe size should be listed in either MEGABYTES
or GIGABYTES with NO decimal (i.e.: 2.2GB = 2200MB) 
use GT or MT and BRU will automatically calculate 
tape overhead." 13 56 2>/tmp/tsize
		ERROR=$?
		if [ "$ERROR" = "1" -o "$ERROR" = "255" ]
		then
			rm -f /tmp/tsize
			errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
		else
			TSIZE="`cat /tmp/tsize`"
			rm -f /tmp/tsize
		fi
	fi
	dialog --title "Special Options" --msgbox \
"BRU provides the ability to manage your tapes by monitoring \
how many times a particular tape has been written to as well \
as providing overwrite protection for current tapes.  These \
next questions will help us configure BRU's tape management system." 11 50
	dialog --title "Overwrite Protection" --yesno \
"Do you wish to protect the contents of current backup tapes \
from accidental overwrites?" 7 50
	ERROR=$?
	if [ "$ERROR" = "1" ]
	then
		OVERWRITEPROTECT="NO"
	fi
	if [ "$ERROR" = "0" ]
	then
		dialog --title "Overwrite Protection" --inputbox \
"How many days should pass before a tape is to be considered \"old\" \
enough to overwrite?" 10 46 2>/tmp/odays
		ERROR=$?
		if [ "$ERROR" = "1" -o "$ERROR" = "255" ]
		then
			rm -f /tmp/odays
			errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
		else
			OVERWRITEDAYS="`cat /tmp/odays`"
			OVERWRITEPROTECT="YES"
			rm -f /tmp/odays
		fi
		dialog --title "Maximum Writes" --inputbox \
"The following is a table of recommendations for the maximum 
number of times that a tape should be written to (MAXWRITES).
BRU uses this entry to warn you when a tape has reached the 
end of its projected useful life.

                 1/4\" DC6000 carts   100
                 4mm DAT             200
                 8mm Exabyte          50 for non-MP 
                                     150 for MP tapes
                 1/2\" Reel           500
                 1/2\" DLT            500

Enter a number from the above table or your own value." 20 70 2>/tmp/maxwrites
		ERROR=$?
		if [ "$ERROR" = "1" -o "$ERROR" = "255" ]
		then
			rm -f /tmp/maxwrites
			errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
		else
			MAXWRITES="`cat /tmp/maxwrites`"
			rm -f /tmp/maxwrites
		fi
	fi
	if [ "$ERROR" = "255" ]
	then
		errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
	fi
#
# Now we present the info and ask if it's correct!
#
	if [ "$FLOPPY" = "" ] 
	then 
		FLOPPY="$DEFFLOPPY"
		FSIZE="$DEFFSIZE"
	fi
	if [ "$TAPE" = "" ]
	then
		TAPE="$DEFTAPE"
		TSIZE="$DEFTSIZE"
	fi
	if [ "$OVERWRITEPROTECT" = "" ]
	then
		OVERWRITEPROTECT="$DOVERWRITEPROTECT"
	fi
	if [ "$OVERWRITEDAYS" = "" ]
	then
		OVERWRITEDAYS="$DOVERWRITEDAYS"
	fi
	if [ "$MAXWRITES" = "" ]
	then
		MAXWRITES="$DMAXWRITES"
	fi
	dialog --title "Default Device" --menu \
"Select which of these devices should be the default backup device" 12 48 2 \
"$FLOPPY" "Floppy Device" \
"$TAPE" "Tape Device" 2>/tmp/tag
	ERROR=$?
	if [ "$ERROR" = 1 -o "$ERROR" = 255 ]
	then
		rm -f /tmp/tag
		errexit "BRUTAB Changes Aborted" "$BRUTAB Must be edited for proper BRU operation"
	else
		DEFDEVICE="`cat /tmp/tag`"
		rm -f /tmp/tag
	fi
	dialog --title "$TITLE" --yesno \
"\nThe following entries will be made to your 
$BRUTAB file:

  Default Diskette = $FLOPPY size $FSIZE
Default Tape drive = $TAPE size $TSIZE
  OVERWRITEPROTECT = $OVERWRITEPROTECT
     OVERWRITEDAYS = $OVERWRITEDAYS
         MAXWRITES = $MAXWRITES

             Are these acceptable?" 16 52
	ERROR=$?
	if [ "$ERROR" = "1" ]
	then
		dialog --title "Changes Rejected" --yesno \
"Do you wish to go back through and re-enter these values?" 6 40
		ERROR=$?
		if [ "$ERROR" = "1" -o "$ERROR" = "255" ]
		then
			errexit "BRUTAB Edits Aborted" \
			"You should manually edit $BRUTAB for your system"
		else
			ACCEPT="0"
		fi
	else
		echo "# Global BRU settings" >> /tmp/brutab.temp
		echo "#" >> /tmp/brutab.temp
		echo "#+OVERWRITEPROTECT=$OVERWRITEPROTECT" >> /tmp/brutab.temp
		echo "#+RECYCLEDAYS=$OVERWRITEDAYS" >> /tmp/brutab.temp
		echo "#+MAXWRITES=$MAXWRITES" >> /tmp/brutab.temp
		echo "#+ZBUFSIZE=512k" >> /tmp/brutab.temp
		echo "#" >> /tmp/brutab.temp
		echo "# Default Archive Device" >> /tmp/brutab.temp
		if [ $DEFDEVICE="$TAPE" ]
		then
echo "#" >> /tmp/brutab.temp
echo "# $TAPE device entry" >> /tmp/brutab.temp
echo "$TAPE \\" >> /tmp/brutab.temp
echo "    size=$TSIZE seek=0 bufsize=20k shmseg=7 shmmax=200k \\" >> /tmp/brutab.temp
echo "    reopen rawtape tape rewind shmcopy" >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
echo "# Floppy Archive Device" >>/tmp/brutab.temp
echo "$FLOPPY \\" >> /tmp/brutab.temp
echo "    size=$FSIZE seek=2k format fmtcmd=\"fdformat $FLOPPY\" reopen shmcopy" >> /tmp/brutab.temp
		else
echo "#" >> /tmp/brutab.temp
echo "# Floppy Archive Device" >>/tmp/brutab.temp
echo "$FLOPPY \\" >> /tmp/brutab.temp
echo "    size=$FSIZE seek=2k format fmtcmd=\"fdformat $FLOPPY\" reopen shmcopy" >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
echo "# $TAPE device entry" >> /tmp/brutab.temp
echo "$TAPE \\" >> /tmp/brutab.temp
echo "    size=$TSIZE seek=0 bufsize=20k shmseg=7 shmmax=200k \\" >> /tmp/brutab.temp
echo "    reopen rawtape tape rewind shmcopy" >> /tmp/brutab.temp
		fi
echo "#" >> /tmp/brutab.temp
echo "# /dev/nrmt0 norewind device entry" >> /tmp/brutab.temp
echo "/dev/nrmt0 \\" >> /tmp/brutab.temp
echo "    size=0 seek=0 bufsize=20k shmseg=7 shmmax=200k \\" >> /tmp/brutab.temp
echo "    reopen rawtape tape norewind shmcopy" >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
echo "#======================================================================" >> /tmp/brutab.temp
echo "#  This entry is a generic entry for stdin and stdout.  DO NOT put this" >> /tmp/brutab.temp
echo "#  first or user's will probably inadvertently write archives to their" >> /tmp/brutab.temp
echo "#  terminals." >> /tmp/brutab.temp
echo "#======================================================================" >> /tmp/brutab.temp
echo "- size=0 seek=0 " >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
echo "For more specific information on the contents of BRUTAB, please " >> /tmp/brutab.temp
echo "refer to the BRU manual." >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
echo "#" >> /tmp/brutab.temp
		cat brutab /tmp/brutab.temp > $BRUTAB
		dialog --title "$BRUTAB Edit Complete" --msgbox \
"\nThe $BRUTAB changes were made successfully!" 6 54
		rm -f /tmp/brutab.temp
		ACCEPT="1"
	fi
fi
return $ACCEPT
}

######################################################################
#
# START OF BRU INSTALLATION SCRIPT
#
######################################################################

#
#  set up bru file locations
#
BIN=/bin			# directory for executables
RESULTS=/tmp/bru.results

#
# check for the existance of dialog on the system
#
if [ -x /bin/dialog ]
then
	DIALOG=1
else
	cp ./dialog /bin/dialog
	DIALOG=1
fi

dialog --title "BRU 14.2 Linux Installation" --yesno \
"\nBy default, BRU executables are
placed into the $BIN directory
with other system executables.
\nDo you wish to install BRU into the\ndefault path location:\n
  /bin  (system executables)" \
15 42
DIRERROR=$?
if [ "$DIRERROR" = "255" ]
then	# user hit ESC
	errexit "Abort" "BRU 14.2 installation Aborted"
fi      # end of ESC trap
if [ "$DIRERROR" = "1" ] 	# User select no
then 
	BIN2=""
	while [ -z "$BIN2" ]
	do
		dialog --title "New Executables Directory" --inputbox \
		"\nEnter the new path into which all executable\nfiles should be placed. (This directory
will be created if it does not exist).\n\nThe default location is $BIN." \
		14 50 2>/tmp/BIN2
		DIRERROR=$?
		BIN2="`cat /tmp/BIN2`"
		rm /tmp/BIN2
		if [ "$DIRERROR" = "255" ]
		then
			errexit "Installation Aborted" "BRU 14.2 Installation Aborted!"
		fi
		if [ -z "$BIN2" ]   #  variable is STILL empty!
		then
			dialog --title "Directory name required" --yesno \
			"\nYou entered a NULL pathname. Do you wish
\nto use the default path \"$BIN\"?\n" 8 44 
			DIRERROR=$?
			if [ "$DIRERROR" = "0" ]  # user says, yes use /bru
			then
				BIN2="$BIN"
			fi
			if [ "$DIRERROR" = "255" ] # user hit ESC
			then
				errexit "No BIN Dir" "BRU Installation Aborted!"
			fi
		fi
		if [ -d "$BIN2" ] # check to see if the directory already exists
		then
			BIN="$BIN2"
		elif [ "$DIRERROR" = "0" ]
		then
			dialog --title "Directory not found" --yesno \
			"\n$BIN2 not found. Create it?" 7 45
			ERROR=$?
			if [ "$ERROR" = "255" ]
			then
				errexit "Abort, Abort!" "BRU Installation Aborted!"
			fi
			if [ "$ERROR" = "1" ]
			then
				BIN2=""
			fi
			if [ "$ERROR" = "0" ]
			then
				BIN="$BIN2"
				mkdir "$BIN"
			fi
		fi
	done
fi

if [ "$BRUTAB" = "" ]		# check for BRUTAB environment variable
then
	BRUTAB=/etc/brutab	# bru device table file	
fi

if [ "$BRUXPAT" = "" ]		# check for BRUXPAT environment variable
then
	BRUXPAT=/etc/bruxpat	# include/exclude pattern file
fi


if [ "$BRUSMARTREST" = "" ]	# check for BRUSMARTREST environment variable
then
	BRUSMARTREST=/etc/brusmartrest	# Smart Restore pattern file
fi

if [ "$BRUHELP" = "" ]
then
	BRUHELP=/etc/bruhelp
fi

BRU=${BIN}/bru			# bru executable
BRUTALK=${BIN}/brutalk		# brutalk executable
INCBRU=${BIN}/incbru		# incremental backup script
FULLBRU=${BIN}/fullbru		# full backup script
SHOWXLOG=${BIN}/showxlog	# show execution log script

OTHER_SCRIPTS="tunebru mountcmd.sh unmountcmd.sh"
OTHER_EXEC="shmtest"			# other executables
OTHER_FILES="README brutalk.c"		# other files

FILELIST="bru brutalk brutab bruxpat brusmartrest \
	  incbru fullbru showxlog bruhelp README_14.2 \
	  $OTHER_SCRIPTS $OTHER_EXEC $OTHER_FILES"

dialog --title "BRU 14.2 Install" --infobox "\nBeginning BRU Installation
Review /tmp/bru.results for\nspecific installation\nresults." 10 34

#
# set error trap
#
trap "$CLEANUP 1" 1 2 3 15
BRUDIR=/bru
if [ ! -d "$BRUDIR" ]
then
	mkdir $BRUDIR
fi

#
# change settings for $BRUDIR
#
chown root $BRUDIR
chgrp 0 $BRUDIR
chmod 755 $BRUDIR

PWD=`pwd`
#
# check for existing version of bru. save the old version 
#
if [ -f $BRU ]
then
	OLD_BRU=${BRU}.Old
	mv $BRU $OLD_BRU
	echo "Saved current version of bru as: '$OLD_BRU'" >> $RESULTS
fi
cp $FILELIST $BRUDIR
cd $BRUDIR
cp bru $BRU		# copy bru file
if [ "$?" -eq 0 ]
then
	echo "bru installed as: '$BRU'" >> $RESULTS
	chown root bru $BRU	# set ownership
	chgrp 0 bru $BRU	# set group
	chmod 4711 bru $BRU	# set permissions
else
	echo "Unable to install bru" >> $RESULTS
	dialog --Title "Installation Failed" --infobox \
"\nUnable to move the BRU executable to $BRU\n" 6 50
	$CLEANUP 1
fi


#
# check for existing version of brutalk. save the old version 
#
if [ -f $BRUTALK ]
then
	OLD_BRUTALK=${BRUTALK}.Old
	mv $BRUTALK $OLD_BRUTALK
	echo "Saved current version of brutalk as: '$OLD_BRUTALK'" >> $RESULTS
fi

cp brutalk $BRUTALK		# copy brutalk file
if [ "$?" -eq 0 ]
then
	echo "brutalk installed as: '$BRUTALK'" >> $RESULTS
	chown bin brutalk $BRUTALK	# set ownership
	chgrp bin brutalk $BRUTALK	# set group
	chmod 711 brutalk $BRUTALK	# set permissions
else
	echo "Unable to install brutalk" >> $RESULTS
fi


#
#  create file of brutab edit commands for sed
#  
SED_CMDS=/tmp/sedtmp$$

cat > $SED_CMDS <<EOT
/*BRUTAB ONLY/s//#+ BRUTABONLY=YES/
/*OVERWRITEPROTECT/s//#+ OVERWRITEPROTECT=YES/
/rct0/s//rmt0/
EOT


#
#  check for existing brutab file. do not overwrite the current file,
#  but edit it to use new global brutab parms.
#
EDIT_BRUTAB="N"
NEW=""
if [ -f $BRUTAB ]
then
	echo "Will use existing brutab file: '$BRUTAB'" >> $RESULTS

	#
	# this converts the following global brutab parameters:
	#
	#	BRUTAB ONLY		=>	BRUTABONLY=YES
	#	OVERWRITE PROTECT	=>	OVERWRITEPROTECT=YES
	#
	sed -f $SED_CMDS < $BRUTAB > ${BRUTAB}$$
	mv ${BRUTAB}$$ $BRUTAB
	rm -f $SED_CMDS

	BRUTAB=${BRUTAB}.New
	NEW="NEW "
else
	EDIT_BRUTAB="Y"
fi

cp brutab $BRUTAB		# copy brutab file
if [ "$?" -eq 0 ]
then
	echo "${NEW}brutab file installed as: '$BRUTAB'" >> $RESULTS
	chown bin brutab $BRUTAB	# set ownership
	chgrp bin brutab $BRUTAB	# set group
	chmod 644 brutab $BRUTAB	# set permissions
else
	echo "Unable to install brutab file" >> $RESULTS
fi

#
# check for existing bruxpat file. do not overwrite the current file.
#
NEW=""
if [ -f $BRUXPAT ]
then
	echo "Will use existing bruxpat file: '$BRUXPAT'" >> $RESULTS
	BRUXPAT=${BRUXPAT}.New
	NEW="NEW "
fi

cp bruxpat $BRUXPAT		# copy bruxpat file
if [ "$?" -eq 0 ]
then
	echo "${NEW}bruxpat file installed as: '$BRUXPAT'" >> $RESULTS
	chown bin bruxpat $BRUXPAT	# set ownership
	chgrp bin bruxpat $BRUXPAT	# set group
	chmod 644 bruxpat $BRUXPAT	# set permissions
else
	echo "Unable to install bruxpat file" >> $RESULTS
fi

#
# check for existing brusmartrest file. do not overwrite the current file.
#
NEW=""
if [ -f $BRUSMARTREST ]
then
	echo "Will use existing brusmartrest file: '$BRUSMARTREST'" >> $RESULTS
	BRUSMARTREST=${BRUSMARTREST}~
	NEW="NEW "
fi

cp brusmartrest $BRUSMARTREST		# copy brusmartrest file
if [ "$?" -eq 0 ]
then
	echo "${NEW}brusmartrest file installed as: '$BRUSMARTREST'" >> $RESULTS
	chown bin brusmartrest $BRUSMARTREST	# set ownership
	chgrp bin brusmartrest $BRUSMARTREST	# set group
	chmod 644 brusmartrest $BRUSMARTREST	# set permissions
else
	echo "Unable to install brusmartrest file" >> $RESULTS
fi

cp bruhelp $BRUHELP	# copy bruhelp file
if [ "$?" -eq 0 ]
then
	echo "${NEW}bruhelp file installed as: '$BRUHELP'" >> $RESULTS
	chown bin bruhelp $BRUHELP # set ownership
	chgrp bin bruhelp $BRUHELP # set group
	chmod 644 bruhelp $BRUHELP # set permissions
else
	echo "Unable to install bruhelp file" >> $RESULTS
fi


#
# check for existing incbru script. do not overwrite the current file.
#
NEW=""
if [ -f $INCBRU ]
then
	echo "Did not modify existing incremental backup script: '$INCBRU'" >> $RESULTS
	INCBRU=${INCBRU}.New
	NEW="NEW "
fi

cp incbru $INCBRU		# copy incbru file
if [ "$?" -eq 0 ]
then
	echo "${NEW}incremental backup script installed as: '$INCBRU'" >> $RESULTS
	chown bin incbru $INCBRU	# set ownership
	chgrp bin incbru $INCBRU	# set group
	chmod 755 incbru $INCBRU	# set permissions
else
	echo "Unable to install $INCBRU" >> $RESULTS
fi


#
# check for existing fullbru script. do not overwrite the current file.
#
NEW=""
if [ -f $FULLBRU ]
then
	echo "Did not modify existing full backup script: '$FULLBRU'" >> $RESULTS
	FULLBRU=${FULLBRU}.New
	NEW="NEW "
fi

cp fullbru $FULLBRU		# copy fullbru file
if [ "$?" -eq 0 ]
then
	echo "${NEW}full backup script installed as: '$FULLBRU'" >> $RESULTS
	chown bin fullbru $FULLBRU	# set ownership
	chgrp bin fullbru $FULLBRU	# set group
	chmod 755 fullbru $FULLBRU	# set permissions
else
	echo "Unable to install $FULLBRU" >> $RESULTS
fi


cp showxlog $SHOWXLOG		# copy showxlog script 
if [ "$?" -eq 0 ]
then
	echo "showxlog script installed as: '$SHOWXLOG'" >> $RESULTS
	chown bin showxlog $SHOWXLOG	# set ownership
	chgrp bin showxlog $SHOWXLOG	# set group
	chmod 755 showxlog $SHOWXLOG	# set permissions
else
	echo "Unable to install $SHOWXLOG" >> $RESULTS
fi


#
# create fifos for use by brutalk
#
QPIPE=/dev/bru.q	# query pipe
RPIPE=/dev/bru.r	# reply pipe
if [ ! -p $QPIPE ]
then
	echo "Creating fifos '$QPIPE' and '$RPIPE' for brutalk ..." >> $RESULTS
	mknod $QPIPE p
	mknod $RPIPE p
	chown bin $QPIPE $RPIPE
	chgrp bin $QPIPE $RPIPE
	chmod 0664 $QPIPE	# make readable by others
	chmod 0662 $RPIPE	# make writable by others
fi

#
# set ownership and permission for other script files
#
chown bin $OTHER_SCRIPTS
chgrp bin $OTHER_SCRIPTS
chmod 755 $OTHER_SCRIPTS

#
# set ownership and permission for other executables
#
chown bin $OTHER_EXEC
chgrp bin $OTHER_EXEC
chmod 711 $OTHER_EXEC

#
# set ownership and permission for other files
#
chown bin $OTHER_FILES
chgrp bin $OTHER_FILES
chmod 444 $OTHER_FILES

# $CLEANUP 0	# cleanup any old files

ACCEPT=0
while [ "$ACCEPT" = 0 ]
do
	buildBrutab
done

#
# Serialize and do a quick test of BRU
#
serialize
dialog --title "BRU Test" --infobox "\nTrying a test of the bru help command (bru -h) ..." 6 54
$BRU -h | grep "release:" 1> /dev/null 2>&1
if [ "$?" -eq 0 ]
then
	dialog --title "Success!" --infobox "\nInstallation of BRU is complete" 6 40 
	sleep 2
	dialog --title "BRU 14.2 Readme" --textbox /bru/README_14.2 23 80
	exit 0
else
	dialog --title "Failure" --infobox "\nInstallation of BRU failed" 6 36
	exit 1
fi
