:
# 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="atc memhog seyon xc warp vg xboing xtile nwho ecu xmcd"

usage() {
	echo "Usage: sprinkle [-u] [-m mount-point] [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 xboing xtile nwho ecu"
	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."
	exit 1
}

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

setuucp() {
	cp $mntpt/bin/$1 /usr/bin/$1
	chown uucp /usr/bin/$1
	chgrp uucp /usr/bin/$1
	chmod 4711 /usr/bin/$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
}

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

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 $PROGRAMS
		;;
	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 /usr/bin/X11/xmcd ]
		then
			echo "A copy of xmcd already exists in /usr/bin/X11."
			echo "If you would like to replace it with the Skunkware"
			echo "xmcd binary, as root execute the command"
			echo "\tcp $mntpt/bin/X11/xmcd.real /usr/bin/X11/xmcd"
			echo "and set the permissions and ownership to root/root 4711."
		else
			cp $mntpt/bin/X11/xmcd.real /usr/bin/X11/xmcd
			chown root /usr/bin/X11/xmcd
			chmod 4711 /usr/bin/X11/xmcd
			[ -d /usr/lib/X11/xmcd ] || mkdir -p /usr/lib/X11/xmcd
			cd /usr/lib/X11/xmcd
			tar xf $mntpt/lib/X11/xmcd/xmcd.tar > /dev/null 2>&1
			APPDEFDIR=/usr/lib/X11/app-defaults
			[ -r $APPDEFDIR/XMcd ] || cp ../app-defaults/XMcd $APPDEFDIR/XMcd
			[ -w /usr/lib/mkdev ] && {
				rm -f /usr/lib/mkdev/xmcd
				ln -s /usr/lib/X11/xmcd/config/configure.sh /usr/lib/mkdev/xmcd
			}
			if [ -x /usr/lib/mkdev/xmcd ]
			then
				mkdev xmcd
			else
				sh /usr/lib/X11/xmcd/config/configure.sh
			fi
		fi
		;;
	xboing*)
		echo "sprinkle: setting up xboing ..."
		XBDIR=/usr/local/lib/xboing
		[ -d $XBDIR ] || mkdir -p $XBDIR
		[ -f $XBDIR/xboing.scores ] || {
			cp $mntpt/lib/xboing/xboing.scores $XBDIR/xboing.scores
			chmod 666 $XBDIR/xboing.scores
		}
		;;
	xtile*)
		echo "sprinkle: setting up xtile ..."
		[ -d /usr/games/lib ] || mkdir -p /usr/games/lib
		[ -f /usr/games/lib/mosaic.scores ] || {
			cp $mntpt/games/lib/mosaic.scores /usr/games/lib/mosaic.scores
			chmod 666 /usr/games/lib/mosaic.scores
		}
		;;
	nwho*)
		echo "sprinkle: setting up nwho ..."
		cp $mntpt/bin/nwho /usr/bin/nwho
		chown bin /usr/bin/nwho
		chgrp mem /usr/bin/nwho
		chmod 2711 /usr/bin/nwho
		;;
	memhog|iohog|cpuhog)
		echo "sprinkle: setting up memhog ..."
		cp $mntpt/bin/memhog /usr/bin/memhog
		chown bin /usr/bin/memhog
		chgrp mem /usr/bin/memhog
		chmod 2711 /usr/bin/memhog
		cd /usr/bin
		[ -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 /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
