:
# spray - script to create necessary symbolic links in /usr/lib/X11
#         and /usr/skunk in order to be able to run the software provided
#         on the SCO Skunkware CD-ROM
#
# Written 09-Mar-94 by rr@sco.com
#
# Usage : spray <mount-point>
#         Where <mount-point> is the directory on which the CD-ROM is mounted
#         If mounted on /usr/skunk, no argument is necessary
#

usage() {
	echo "Usage: spray [mount-point]"
	echo "\tWhere mount-point refers to the directory on which"
	echo "\tthe CD-ROM is mounted. If no arguments are given, it"
	echo "\tis assumed the CD-ROM is mounted on /usr/skunk."
	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
}

[ $# = 0 ] && MOUNT_PT=/usr/skunk

[ $# = 1 ] && MOUNT_PT=$1

[ $# -gt 1 ] && usage

#
# check to see if the user has root privelege
#
fuid=`id`
uid=`echo $fuid | awk ' { print $1 } '`
[ "$uid" = "uid=0(root)" ] || {
	echo "You must have root priveleges to run spray."
	usage
	exit 1
}

#
# check to make sure the cd is mounted and what we expect is there
#
[ -f $MOUNT_PT/pics/README ] || usage
[ -d $MOUNT_PT/lib/X11/app-defaults ] || usage

APPDEFDIR=/usr/lib/X11/app-defaults
SKUNKLIST="README RELEASE.NOTES \
	audio bin cdmt etc games include info lib man pics \
	src tls usr xc"
#
# set up the X11 app-defaults directory
#
[ -d $APPDEFDIR ] || mkdir -p $APPDEFDIR
cd $APPDEFDIR
for i in $MOUNT_PT/lib/X11/app-defaults/*
do
	[ "$i" = "$MOUNT_PT/lib/X11/app-defaults/XMcd" ] && continue
	[ -r `basename $i` ] || ln -s $i .
done

#
# set up the Willow directory
#
WILLOW_DIR=lib/X11/willow

[ -d /usr/$WILLOW_DIR ] || {
	[ -h /usr/$WILLOW_DIR ] || ln -s $MOUNT_PT/$WILLOW_DIR /usr/$WILLOW_DIR
}

#
# set up the Periodic uid file
#
UID_DIR=lib/X11/uid
UIDFILE=$UID_DIR/periodic.uid

[ -f /usr/$UIDFILE ] || {
	[ -d /usr/$UID_DIR ] || mkdir -p /usr/$UID_DIR
	ln -s $MOUNT_PT/$UIDFILE /usr/$UIDFILE
}

#
# set up directory links in /usr/local/lib (for now)
#
[ -d /usr/local/lib ] || {
	mkdir -p /usr/local/lib
}
[ -d /usr/local/lib/xboing ] || {
	mkdir -p /usr/local/lib/xboing
}
LOCALLIBDIRS="gcc-lib povray sc-6.21 xboing/levels xc xconq mosaic lynx \
	X11"
LOCALLIBFILS="libg++.a"
for i in $LOCALLIBDIRS
do
	[ -d /usr/local/lib/$i ] || ln -s $MOUNT_PT/lib/$i /usr/local/lib/$i
done
for i in $LOCALLIBFILS
do
	[ -f /usr/local/lib/$i ] || ln -s $MOUNT_PT/lib/$i /usr/local/lib/$i
done

# Now setup the Fresco DLL's so you don't need to modify LD_LIBRARY_PATH
cd /usr/lib
for i in $MOUNT_PT/lib/*.so $MOUNT_PT/lib/*.so.1.0
do
	ln -s $i .
done

#
# Setup the Flying directory in /usr/games
#
FLYINGDIR=/usr/games/lib/flying-6.11/fly.dta
[ -d $FLYINGDIR ] || [ -h $FLYINGDIR ] || mkdir -p $FLYINGDIR
[ -d $FLYINGDIR ] && chmod 777 $FLYINGDIR
touch $FLYINGDIR/logfile.txt
chmod a+r $FLYINGDIR/logfile.txt

#
# Setup the various scorefiles in usr/games and /usr/local
#

[ -d /usr/games/lib ] || mkdir -p /usr/games/lib
[ -f /usr/games/lib/spatial.sco ] || {
	cp $MOUNT_PT/games/lib/spatial.sco /usr/games/lib/spatial.sco
	chmod 666 /usr/games/lib/spatial.sco
}

XBDIR=/usr/local/lib/xboing
[ -d $XBDIR ] || mkdir -p $XBDIR
[ -f $XBDIR/xboing.scores ] || {
	cp $MOUNT_PT/lib/xboing/xboing.scores $XBDIR/xboing.scores
	chmod 666 $XBDIR/xboing.scores
}

[ -f /usr/games/lib/xtetris-scores ] || {
	cp $MOUNT_PT/games/lib/xtetris-scores /usr/games/lib/xtetris-scores
	chmod 666 /usr/games/lib/xtetris-scores
}

[ -f /usr/games/lib/mosaic.scores ] || {
	cp $MOUNT_PT/games/lib/mosaic.scores /usr/games/lib/mosaic.scores
	chmod 666 /usr/games/lib/mosaic.scores
}

#
# Setup the Nethack directory in /usr/games
#
NETHACKDIR=/usr/games/lib/nethackdir
HACKIT=1

[ -d $NETHACKDIR ] || {
	if [ -h $NETHACKDIR ]
	then
		echo "It looks like $NETHACKDIR is a symlink."
		echo "I will leave it up to you to configure this directory."
		HACKIT=
	else
		mkdir -p $NETHACKDIR
	fi
}

[ "$HACKIT" ] && {
	chmod 777 $NETHACKDIR
	cd $NETHACKDIR
	for i in $MOUNT_PT/games/lib/nethackdir/*
	do
		name=`basename $i`
		[ -h $name ] || [ -f $name ] || ln -s $i .
	done
	ls -l perm | grep $MOUNT_PT > /dev/null && {
		rm -f perm
		touch perm
		chmod 666 perm
	}
	ls -l logfile | grep $MOUNT_PT > /dev/null && {
		rm -f logfile
		touch logfile
		chmod 666 logfile
	}
	ls -l record | grep $MOUNT_PT > /dev/null && {
		rm -f record
		touch record
		chmod 666 record
	}
	ls -l save | grep $MOUNT_PT > /dev/null && {
		rm -f save
		mkdir save
		chmod 777 save
	}
}

[ "$MOUNT_PT" = "/usr/skunk" ] || {
	if [ -d /usr/skunk ]
	then
	  for foo in $SKUNKLIST
	  do
		if [ -d /usr/skunk/$foo ]
		then
		# /usr/skunk/$foo is a directory for some reason so we cd there
		# and try to create symbolic links out to the mount point
			cd /usr/skunk/$foo
			for i in $MOUNT_PT/$foo/*
			do
				[ -r `basename $i` ] || ln -s $i .
			done
		elif [ -h /usr/skunk/$foo ]
		then
		# /usr/skunk/$foo is a symbolic link to a previous mount point
		# so we remove it and re-link it
			rm -f /usr/skunk/$foo
			ln -s $MOUNT_PT/$foo /usr/skunk/$foo
		else
		# /usr/skunk/$foo is neither a symbolic link or directory so
		# let's just try to make it a symbolic link to the mount point
			rm -f /usr/skunk/$foo
			ln -s $MOUNT_PT/$foo /usr/skunk/$foo
		fi
	  done
	else
		rm -f /usr/skunk
		ln -s $MOUNT_PT /usr/skunk
	fi
}

echo "\nInitial SCO Skunkware configuration complete.\n"
echo "Some SCO Skunkware files need to be copied to the hard disk"
echo "in order to function properly. Others need to be setuid/setgid."
echo "Would you like to perform this additional setup at this time ? <Y/N> \c"

getyn

if [ "$ans" = "Y" ] 
then
	/usr/skunk/bin/sprinkle -m $MOUNT_PT
else
	echo "\nThe additional configuration necessary for some SCO Skunkware"
	echo "components can be performed later by running (as root) the command :"
	echo "\n\t/usr/skunk/bin/sprinkle\n"
fi

echo "\nSCO Skunkware 5 contains both the NCSA Mosaic graphical web browser"
echo "and Lynx, a character mode web browser. A wealth of information"
echo "about Skunkware components is available via these browsers. I have"
echo "temporarily set your PATH for browser use. See the RELEASE.NOTES for"
echo "instructions on how to take full advantage of these documents."
echo "\nWould you like to browse the SCO Skunkware 5 CD-ROM ? <Y/N> \c"

getyn

if [ "$ans" = "Y" ] 
then
	echo "\nStarting the SCO Skunkware 5 prowl program."
	echo "Please wait while i load the pages ...\c"
	/usr/skunk/bin/prowl -s
else
	echo "\nThe SCO Skunkware 5 CD-ROM can be browsed at your convenience"
	echo "by running the command :"
	echo "\n\t/usr/skunk/bin/prowl\n"
fi

exit 0
