:
# 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
}

[ $# = 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="CONTENTS DIRS.LIST INSTALL.NOTES LINKS.LIST README RELEASE.NOTES \
	audio bin custom etc games include info interviews 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
CHAPPDEFDIR=/usr/lib/charm/app-defaults
#
# set up the Charm app-defaults directory
#
[ -d $CHAPPDEFDIR ] || mkdir -p $CHAPPDEFDIR
cd $CHAPPDEFDIR
for i in $MOUNT_PT/lib/charm/app-defaults/*
do
	[ -r `basename $i` ] || ln -s $i .
done
STARTUPDIR=/usr/lib/X11/sco/startup
#
# set up the SCO startup directory
#
[ -d $STARTUPDIR ] || mkdir -p $STARTUPDIR
cd $STARTUPDIR
for i in $MOUNT_PT/lib/X11/sco/startup/*
do
	[ -r `basename $i` ] || ln -s $i .
done

#
# set up the Interviews directory
#
[ -d /interviews ] || {
	ln -s /usr/skunk/interviews /interviews
}

#
# 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="g++include gcc-lib povray sc-6.21 xboing/levels xc xconq"
LOCALLIBFILS="libg++.a"
for i in $LOCALLIBDIRS
do
	[ -d /usr/local/lib/$i ] || ln -s /usr/skunk/lib/$i /usr/local/lib/$i
done
for i in $LOCALLIBFILS
do
	[ -f /usr/local/lib/$i ] || ln -s /usr/skunk/lib/$i /usr/local/lib/$i
done

[ "$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
}
