#!/bin/sh # bbconfig # AUTOMATIC CONFIG SCRIPT # Sean MacGuire # # (c) Copyright Quest Software, Inc. 1997-2003 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" 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 isroot=FALSE idline=`id 2>/dev/null` if [ "$idline" != "" ] then set $idline 2>/dev/null idline=`echo $1 | sed 's/=/ /' | sed 's/(/ /' | sed 's/)/ /'` set $idline 2>/dev/null BBUID=$3 if [ "$2" -eq 1 -o "$BBUID" = "root" ] then isroot=TRUE fi fi if [ ! -f $BBHOME/src/minimake/client ] then if [ "$isroot" != "TRUE" ] then echo "" echo "*** You are installing Big Brother logged in as $BBUID" echo "*** You need to be root to install Big Brother" echo "*** Please become root and re-run bbconfig - EXITING" echo "" exit 1 fi fi tput clear chmod 1777 $BBHOME/tmp # STICKY DIR if test ! -f $BBHOME/tmp/.license then more $BBHOME/LICENSE echo echo $ECHOOPTION "Do you agree to the terms of this license (y/n): $ECHOTAIL" read ANS ANS=`echo "$ANS" | tr '[A-Z]' '[a-z]'` if [ "$ANS" != "y" ] then echo echo "Exiting..." exit 1 else echo echo "Thank you, installation continuing..." sleep 2 tput clear echo > $BBHOME/tmp/.license fi fi #-------------------------------------------------------- # WE REALLY SHOULD TRY TO FIGURE WHAT MACHINE WE'RE ON. #-------------------------------------------------------- # # bbmachine # if [ "$OSARG" = "" ] then MACHINE=`$BBHOME/install/bbmachine` else MACHINE=$OSARG fi OS="bsdi bsdi4 sco3 sco freebsd solaris hpux9 hpux linux sunos netbsd osf osf1 ultrix irix unixware unixware7 redhat redhatES fedora aix dynix debian dgux openbsd caldera mandrake sinix suse darwin gentoo" #-------------------------------------------------------- # SET UP BBHOME #-------------------------------------------------------- if test "$ARGNUM" != "1" then echo " Welcome to the Big Brother installation procedure." echo $ECHOOPTION "Please confirm 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 "---> We'll configure for $MACHINE..." fi LINUX=FALSE 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 PSARG="-ef" ;; linux|redhat*|suse|fedora ) PSARG="ax" LINUX=TRUE ;; aix ) PSARG="axuww" ;; hpux ) PSARG="-ef" ;; freebsd ) PSARG="auxw" ;; mandrake|caldera|debian ) LINUX=TRUE ;; esac #-------------------------------------------------------- # FORBID RUNNING BB AS root #-------------------------------------------------------- STOPROOT=TRUE BBUSER="" while [ "$BBUSER" = "" ] do echo " Big Brother needs it's own user id. If your BB user doesn't exist, you'll have to create it then re-run bbconfig. " BBUSER="bb" echo $ECHOOPTION "What will be the user ID for BB [$BBUSER]: $ECHOTAIL" read ANS ANS=`echo "$ANS"` if [ "$ANS" != "" ] then BBUSER="$ANS" fi if [ "$BBUSER" = "root" -a "$STOPROOT" = "TRUE" ] then echo "---> User root is not allowed" BBUSER="" continue fi # Hummmmm, id should be fine for everything id $BBUSER >/dev/null 2>&1 if [ "$?" -eq 0 ] then echo "---> BB will only run from user '$BBUSER'" else echo "" echo "*** Your BB user doesn't exist - Please create it now!" echo "*** and re-run bbconfig - EXITING" echo "" exit 1 fi done # What is the BBGROUP ? # IDLINE="`id $BBUSER 2>/dev/null`" if [ "$?" -ne 0 ] then BBGROUP=$BBUSER else set bogus $IDLINE shift set bogus `echo "$2" | sed 's/[()=]/ /g' 2>/dev/null` shift if [ $# -lt 2 ] then BBGROUP=$BBUSER else BBGROUP=$2 fi fi #-------------------------------------------------------- # SET UP BBHOME #-------------------------------------------------------- echo " Making sure BBHOME <$BBHOME> is writable... " if [ ! -w "$BBHOME" ] then echo "*** <$BBHOME> is not a writable directory" echo "*** Please adjust the permissions and re-run bbconfig" echo "*** EXITING" echo "" exit 1 ANS="" fi echo "---> OK, $BBHOME is fine..." # 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 #-------------------------------------------------------- # 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 if [ ! -f $BBHOME/src/minimake/client ] then #-------------------------------------------------------- # 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 host 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 host 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 elif [ "$ANS" = 'n' -o "$ANS" = 'N' ] then 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 [ "$ANS" = 'y' -o "$ANS" = 'Y' ] then DOPAGE=TRUE elif [ "$ANS" = 'n' -o "$ANS" = 'N' ] then DOPAGE=FALSE fi done # # WHEN IN BTF MODE, ONLY DO THE PREVIOUS STEPS IF IT'S A BB SERVER # (if [ ! -f $BBHOME/src/minimake/client ] ... ) # fi #-------------------------------------------------------- # SET UP DEFAULT NOTIFICATIONS #-------------------------------------------------------- DEFAULTPAGE="" if [ "$DOPAGE" = "TRUE" ] then while [ "$DEFAULTPAGE" = "" ] do DEFAULTPAGE="root@${THISHOST}" echo $ECHOOPTION " Enter the default e-mail address to send notifications to: [$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 if [ "$BBWEB" = "/" ] then rc=1 else echo "$BBWEB" | grep ".*/$" >/dev/null 2>&1 rc=$? fi if [ "$rc" -eq 0 ] then echo " The base URL <$BBWEB> is invalid, it should not end 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 echo "" 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" echo "" done fi # "$DOWEB" = TRUE cd $BBHOME #-------------------------------------------------------- # NOW COPY STUFF ACROSS #-------------------------------------------------------- echo " -------------------------------------------------------- " 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 if [ "$LINUX" = "TRUE" ] then echo "--> UPDATING bbsys.local for LINUX requiring -w3 option in PINGPAR1" ping -w3 -c1 localhost >/dev/null 2>/dev/null if [ $? -eq 0 ] then # It understands -w3 WOPTION="-w3" else WOPTION="" fi cat etc/bbsys.local | sed "s/&WOPTION/${WOPTION}/" > tmp/bbsys.local.$MACHINE mv tmp/bbsys.local.$MACHINE etc/bbsys.local fi 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 BBHOME into bbmv & bbrm scripts cat bin/bbrm.DIST | sed "s!&BBHOME!$BBHOME!g" > bin/bbrm cat bin/bbmv.DIST | sed "s!&BBHOME!$BBHOME!g" > bin/bbmv cat bin/bbprune.DIST | sed "s!&BBHOME!$BBHOME!g" > bin/bbprune chmod 755 bin/bbrm bin/bbmv bin/bbprune fi 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-server.sh.DIST | sed "s!&BBWEBHOST!$BBWEBHOST!g" > tmp/bbdef-server.sh.$$ # Base URL location cat tmp/bbdef-server.sh.$$ | sed "s!&BBWEB!$BBWEB!g" > tmp/bbdef-server.sh # Base URL location of CGI scripts cat tmp/bbdef-server.sh | sed "s!&CGIBINURL!$CGIBINURL!g" > tmp/bbdef-server.sh.$$ mv tmp/bbdef-server.sh.$$ etc/bbdef-server.sh chown $BBUSER:$BBGROUP etc/bbdef-server.sh rm -f tmp/bbdef-server.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 chown $BBUSER:$BBGROUP 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 chown $BBUSER:$BBGROUP www/help/bb-rep.html 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 # Validate web server ID touch $BBHOME/tmp/bbconfig.$$ chown $WEBUSER $BBHOME/tmp/bbconfig.$$ if [ "$?" -ne 0 ] then echo "Invalid user id: $WEBUSER" WEBUSER="" else userline=`id $WEBUSER 2>/dev/null` if [ "$userline" = "" ] then # If "id" fails then try thru /etc/passwd userline=`grep "^$WEBUSER:" /etc/passwd 2>/dev/null` if [ "$userline" = "" ] then echo "Invalid user id: $WEBUSER" WEBUSER="" else OLDIFS=$IFS IFS=':' set -f set $userline 2>/dev/null set +f IFS=$OLDIFS groupid=$4 groupline=`grep ":$4:" /etc/group 2>/dev/null` if [ "$groupline" != "" ] then OLDIFS=$IFS IFS=':' set -f set $groupline 2>/dev/null set +f IFS=$OLDIFS TMPWEBGROUP=$1 else 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 fi fi else set $userline 2>/dev/null shift idline=`echo $1 | sed 's/=/ /' | sed 's/(/ /' | sed 's/)/ /'` set $idline 2>/dev/null TMPWEBGROUP=$3 if [ "$TMPWEBGROUP" = "" ] 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 fi fi fi rm $BBHOME/tmp/bbconfig.$$ 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 touch $BBHOME/tmp/bbconfig.$$ chgrp $WEBGROUP $BBHOME/tmp/bbconfig.$$ if [ "$?" -ne 0 ] then groupline=`grep "^$WEBGROUP:" /etc/group` if [ "$?" -ne 0 ] then echo "Invalid group name: $WEBGROUP" WEBGROUP="" fi fi rm $BBHOME/tmp/bbconfig.$$ done # CREATE THE BBVAR DIRECTORIES IF THEY DON'T ALREADY EXIST if test ! -d $BBVAR then mkdir $BBVAR chown $BBUSER $BBVAR chgrp $BBGROUP $BBVAR fi for dir in acks archive data disabled hist histlogs logs do if test ! -d "${BBVAR}/${dir}" then mkdir ${BBVAR}/${dir} chown $BBUSER ${BBVAR}/${dir} chgrp $BBGROUP ${BBVAR}/${dir} 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 pager scripts" case ${MACHINE} in solaris ) # Force the use of /usr/xpg4/bin if it's available if [ -d /usr/xpg4/bin ] then 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 etc/bbchkwarnrules.sh.DIST etc/bbchkwarnrules.sh ;; esac chmod 755 etc/bbchkwarnrules.sh chown $BBUSER:$BBGROUP etc/bbchkwarnrules.sh # Insert the default recipient cat etc/bbwarnrules.cfg.DIST | sed "s/&DEFAULTPAGE/$DEFAULTPAGE/g" > etc/bbwarnrules.cfg chown $BBUSER:$BBGROUP etc/bbwarnrules.cfg fi echo " -------------------------------------------------------- " echo " -------------------------------------------------------- " echo "--> Done. Now do" if [ ! -f $BBHOME/src/minimake/client ] then echo " chown -R $BBUSER $BBVAR $BBHOME" echo " su - $BBUSER" echo " to continue installation using that user ID" else echo " chown -R $BBUSER $BBHOME" fi echo " Now compile Big Brother " echo " cd $BBHOME/src" echo " make" echo " make install" echo " -------------------------------------------------------- " if [ ! -f $BBHOME/src/minimake/client -a "$MACHINE" = "redhat" ] then echo "" echo "Note to RedHat 6.1 users, ping is broken, please use ping from" echo "http://bb4.com/netkit-base-0.10-29.i386.rpm.gz" fi exit 0