#! /bin/sh
#
# instl
#
# Shell script to install the software source distribution.
# It updates /etc/versionlog to log installation of software. It also
# checks to make sure that there is enough space in /usr/src prior
# to installing the sources. Must be run as root.
#
# This file is the first tape file on distribution tape.
# The second tape file is a tar image of tools, libraries and header files.
# The third tape file is a tar image of Dynix utilities sources.
# The fourth tape file is a tar image of System V Applications Environment.
#
PATH=:/bin:/usr/bin:/usr/ucb:/etc; export PATH

if [ `whoami` != root ]; then
	echo "Sorry, this script must be run as super-user to work properly."
	exit 1
fi

if [ ! -d /usr/lost+found ]; then
	echo "/usr filesystem is not mounted (or /usr/lost+found is missing)."
	echo "Please mount /usr and try again."
	exit 1
fi

if [ ! -d /usr/src ]; then
	mkdir /usr/src
fi

SRCDIR=/usr/src/dynix
if [ ! -d $SRCDIR ]; then
	mkdir $SRCDIR
fi

echo -n 'Do you want Dynix utilities sources installed?[y/n]'
read DYNIX

if [ "$DYNIX" = "y" ] ;then
	SIZEALL=`expr 11225 + 38409`
else
	SIZEALL=11225
fi

echo -n 'Do you want System V Applications Environment sources installed?[y/n]'
read SYS5

if [ "$SYS5" = "y" ] ;then
	SIZEALL=`expr $SIZEALL + 11891`
fi

AVAIL=`df $SRCDIR | awk '/\/dev\//{print $4}'`
if [ $AVAIL -lt $SIZEALL ]; then
	echo "$SRCDIR has $AVAIL blocks available.  $SIZEALL are required."
	echo "See tape instruction sheet."
	exit 1
fi

CWD=`pwd`
cd $SRCDIR
echo "Installing mandatory tools, libraries and header files."
(mt -f /dev/rts8 rew; mt -f /dev/rts8 fsf 1; tar xpf /dev/rts8) &
CNT=1
while ps | grep -s "^ *$! "; do
	if [ $CNT -gt 79 ] ;then 
		CNT=1
		echo ""
	fi
	echo -n .
	CNT=`expr $CNT + 1`
	sleep 3
done
echo ""
if [ "$DYNIX" = "y" ] ;then
	echo "Installing Dynix utilities sources."
	(tar xpf /dev/rts8) &
	CNT=1
	while ps | grep -s "^ *$! "; do
		if [ $CNT -gt 79 ] ;then 
			CNT=1
			echo ""
		fi
		echo -n .
		CNT=`expr $CNT + 1`
		sleep 3
	done
	echo ""
else
	mt -f /dev/rts8 fsf 1
fi
if [ "$SYS5" = "y" ] ;then
	echo "Installing System V Applications Environment sources."
	(tar xpf /dev/rts8) &
	CNT=1
	while ps | grep -s "^ *$! "; do
		if [ $CNT -gt 79 ] ;then 
			CNT=1
			echo ""
		fi
		echo -n .
		CNT=`expr $CNT + 1`
		sleep 3
	done
	echo ""
fi
echo "`/bin/date`  - DYNIX V3.0.17 Utilities Source Distribution PN: 1003-51291" >> /etc/versionlog
echo ""
echo "DYNIX V3.0.17 Utilities Source Distribution installed."
echo "Rewinding tape..."
mt -f /dev/rts8 rew
echo "Done."
cd $CWD
rm instl
