:
# sprinkle - script to install a specified component of the Skunkware CD-ROM
#            to the hard disk. This is necessary for some components which 
#            need setuid/setgid bits since we are not currently permitting
#            this (e.g. xmcd).
#
# Written 09-Mar-94 by rr@sco.com
#
# Usage: sprinkle [all comp1 comp2 ...]
#

PROGRAMS="sockinfo u386mon atc memhog seyon xc warp vg \
		  ecu xmcd sfs lsof xlock pidentd"

usage() {
	echo "Usage: sprinkle [-u] [-m mnt-pt] [-d inst-bin] [all comp1 comp2 ...]"
	echo "\tWhere comp1, comp2, ... are one or more of"
	echo "\tthe following components :"
	echo "\t\tatc seyon xmcd memhog warp xc vg ecu"
	echo "\t\tsockinfo u386mon sfs pidentd lsof xlock"
	echo "\tAn argument of all indicates all of the above."
	echo "\tThe -m argument is used to specify the absolute pathname "
	echo "\tof the CD-ROM mount point. If it is omitted, you will be"
	echo "\tprompted for a pathname (/usr/skunk is the default)."
	echo "\tThe -d argument is used to specify the absolute pathname "
	echo "\tof the installation bin. If it is omitted, you will be"
	echo "\tprompted for a pathname (/usr/bin is the default)."
	exit 1
}

getyn() {
	ans=
	while [ "$ans" = "" ]
	do
		read ans
		[ "$ans" = "Y" ] || [ "$ans" = "y" ] && {
			ans=Y
			break
		}
		[ "$ans" = "n" ] || [ "$ans" = "N" ] && {
			ans=N
			break
		}
		ans=
		echo "\nPlease answer with a Y or N \c"
	done
}

setroot() {
	cp $mntpt/bin/$1.real $inspt/$1
	chown root $inspt/$1
	chgrp root $inspt/$1
	chmod 4711 $inspt/$1
}

setuucp() {
	cp $mntpt/bin/$1.real $inspt/$1
	chown uucp $inspt/$1
	chgrp uucp $inspt/$1
	chmod 4711 $inspt/$1
}

echo "Welcome to sprinkle, a tool for copying and setting permissions"
echo "for portions of the SCO Skunkware CD-ROM."
echo "This script is mainly useful for making one or more of the programs"
echo "provided on the CD-ROM run as a setuid or setgid program."

fuid=`id`
uid=`echo $fuid | awk ' { print $1 } '`
[ "$uid" = "uid=0(root)" ] || {
	echo "In order to execute sprinkle, you must have root privelege."
	exit 1
}

mntpt=
inspt=

while case "$1" in
	-u) usage
		;;
	-m) [ "$2" ] || usage
		mntpt=$2
		shift
		;;
	-d) [ "$2" ] || usage
		inspt=$2
		shift
		;;
	"") break
		;;
	 *) break
		;;
	esac
do
	shift
done

if [ "$mntpt" = "" ]
then
	echo "\nPlease enter the absolute pathname of the CD-ROM mount point : [/usr/skunk] \c"
	read mntpt
fi
[ "$mntpt" = "" ] && mntpt=/usr/skunk

if [ "$inspt" = "" ]
then
	echo "\nPlease enter the absolute pathname of the installation bin: [/usr/bin] \c"
	read inspt
fi
[ "$inspt" = "" ] && inspt=/usr/bin
[ -d $inspt ] || [ -h $inspt ] || mkdir -p $inspt

if [ $# = 0 ]
then
	echo "Please enter the Skunkware component to be installed : [all] \c"
	read cmpnt
	[ "$cmpnt" = "" ] && cmpnt=all
	set -- $cmpnt
else
	cmpnt=$1
fi

while case "$cmpnt" in
	all)
		$mntpt/bin/sprinkle -m $mntpt -d $inspt $PROGRAMS
		;;
	sockinfo*)
		echo "sprinkle: setting up sockinfo ..."
		SOCKBIN=$inspt
		cp $mntpt/bin/sockinfo.osr5 ${SOCKBIN}/sockinfo
		chown root ${SOCKBIN}/sockinfo
		chgrp mem ${SOCKBIN}/sockinfo
		chmod 2511 ${SOCKBIN}/sockinfo
		;;
	u386mon*)
		echo "sprinkle: setting up u386mon ..."
		U386BIN=$inspt
		cp $mntpt/bin/u386mon.real ${U386BIN}/u386mon
		chown root ${U386BIN}/u386mon
		chgrp uucp ${U386BIN}/u386mon
		chmod 4755 ${U386BIN}/u386mon
		cp $mntpt/bin/nlsym.real ${U386BIN}/nlsym
		chown root ${U386BIN}/nlsym
		chgrp uucp ${U386BIN}/nlsym
		chmod 4755 ${U386BIN}/nlsym
		${U386BIN}/nlsym > /dev/null 2>&1
		;;
	atc*)
		echo "sprinkle: setting up atc ..."
		ATCDIR=/usr/games/lib/atc
		export ATCDIR
		cd $mntpt/games/lib/atc
		[ -d $ATCDIR ] || mkdir -p $ATCDIR
		find . -depth -print | cpio -pdm $ATCDIR > /dev/null 2>&1
		chmod 666 $ATCDIR $ATCDIR/*
		;;
	xmcd*) 
		echo "sprinkle: setting up xmcd ..."
		if [ -r $inspt/X11/xmcd ]
		then
		 echo "A copy of xmcd already exists in $inspt/X11."
		 echo "If you would like to replace it with the Skunkware"
		 echo "xmcd package, remove the existing xmcd installation"
		 echo "and, as root, execute the commands :"
		 echo "\ncustom -p SKUNK:default -L SKUNK:xmcd -z /usr/skunk/cdmt/archives/TAPE"
		 echo "custom -p SKUNK:default -e SKUNK:xmcd "
		 echo "mkdev xmcd"
		else
		 custom -p SKUNK:default -L SKUNK:xmcd -z /usr/skunk/cdmt/archives/TAPE
		 custom -p SKUNK:default -e SKUNK:xmcd
		 echo "In order to use xmcd, you must configure your CD-ROM drive"
		 echo "To do so, you can run the command 'mkdev xmcd'."
		 echo "Would you like to run mkdev xmcd at this time ? <Y/N> \c"
		 getyn
		 [ "$ans" = "Y" ] && mkdev xmcd
		fi
		;;
	xlock*)
		echo "sprinkle: setting up xlock ..."
		LOCKBIN=$inspt/X11
		cp $mntpt/bin/X11/xlock.real ${LOCKBIN}/xlock
		chown root ${LOCKBIN}/xlock
		chgrp auth ${LOCKBIN}/xlock
		chmod 2511 ${LOCKBIN}/xlock
		;;
	pidentd*)
		echo "sprinkle: setting up pidentd ..."
		PIDENTBIN=/etc
		SERVICES="ident 113/tcp auth tap"
		INETCONF="ident  stream  tcp  nowait  nouser  /etc/in.identd in.identd"
		cp $mntpt/etc/in.identd.real ${PIDENTBIN}/in.identd
		chown root ${PIDENTBIN}/in.identd
		chgrp mem ${PIDENTBIN}/in.identd
		chmod 2511 ${PIDENTBIN}/in.identd
		grep ident /etc/services /etc/inetd.conf > /dev/null && {
			echo "\nApparently ident services have already been configured in"
			echo "/etc/services and/or /etc/inetd.conf."
			echo "\nPlease consult the file :\n"
			echo "\t/usr/skunk/src/Tools/pidentd/pidentd-2.6.1/INSTALL"
			echo "\nfor further instructions."
			shift
			cmpnt=$1
			continue
		}
		echo "\nIn order to complete the installation of pidentd,"
		echo "The lines :\n"
		echo "\t$SERVICES"
		echo "\nand\n"
		echo "\t$INETCONF"
		echo "\nneed to be added to the files"
		echo "/etc/services and /etc/inetd.conf, respectively."
	echo "\nWould you like to append these lines to these files at this time ? <Y/N>\c"
		getyn
		[ "$ans" = "Y" ] && {
			echo $SERVICES >> /etc/services
			echo $INETCONF >> /etc/inetd.conf
			kill -1 `cat /etc/inetd.pid`
		}
		;;
	lsof*)
		echo "sprinkle: setting up lsof ..."
		LSOFBIN=$inspt
		cp $mntpt/bin/lsof.real ${LSOFBIN}/lsof
		chown root ${LSOFBIN}/lsof
		chgrp mem ${LSOFBIN}/lsof
		chmod 2511 ${LSOFBIN}/lsof
		;;
	sfs*)
		echo "sprinkle: setting up sfs ..."
		[ -d /usr/games/lib/sfs ] || mkdir -p /usr/games/lib/sfs
		[ -x /usr/games/lib/sfs/sfs ] || {
			cp $mntpt/games/lib/sfs/* /usr/games/lib/sfs
			chmod 777 /usr/games/lib/sfs
		}
		;;
	memhog|iohog|cpuhog)
		echo "sprinkle: setting up memhog ..."
		cp $mntpt/bin/memhog.real $inspt/memhog
		chown bin $inspt/memhog
		chgrp mem $inspt/memhog
		chmod 2711 $inspt/memhog
		cd $inspt
		[ -f iohog ] || ln -s memhog iohog
		[ -f cpuhog ] || ln -s memhog cpuhog
		;;
	ecu*)
		echo "sprinkle: setting up ecu ..."
		[ -d /usr/lib/ecu ] || mkdir -p /usr/lib/ecu
		cp $mntpt/lib/ecu/ecuungetty /usr/lib/ecu/ecuungetty
		chown root /usr/lib/ecu/ecuungetty
		chgrp root /usr/lib/ecu/ecuungetty
		chmod 4711 /usr/lib/ecu/ecuungetty
		;;
	vg*) 
		echo "sprinkle: setting up vg ..."
		setroot vg
		;;
	warp*)
		echo "sprinkle: setting up warp ..."
		WARPDIR=/usr/games/lib/warp
		export WARPDIR
		cd $mntpt/games/lib/warp
		[ -d $WARPDIR ] || mkdir -p $WARPDIR
		find . -depth -print | cpio -pdm $WARPDIR > /dev/null 2>&1
		cp $mntpt/bin/warp.real /usr/games/warp
		chown 9999 /usr/games/warp
		chmod 4755 /usr/games/warp
		cd /usr/games/lib/warp
		find . -print | xargs chown 9999
		;;
	seyon*) 
		echo "sprinkle: setting up seyon ..."
		setuucp seyon
		;;
	xc*) 
		echo "sprinkle: setting up xc ..."
		setuucp xc
		;;
	"") break
		;;
	*)
		for i in X11 Tools Games
		do
			[ -d $mntpt/$i/$cmpnt ] && {
				echo "In order to install $cmpnt, you can copy the source"
				echo "directory $mntpt/$i/$cmpnt to your hard disk and follow"
				echo "the build and install instructions for this component."
				foundit=1
			}
		done
		[ "$foundit" ] || echo "Unrecognized component : $cmpnt"
		;;
	esac
do
	shift
	cmpnt=$1
done
