# issue needs to be same group as root
cp baseexec /tmp
chmod +x /tmp/baseexec

echo "do you want to re-create the file 'files' (y/n) ?"
read ANS
if [ "$ANS" = 'y' ]
then
	echo "creating files, this may take a while"

# create dummy pslinks files so that update will include them

	for i in DWB acctcom admin base bc cflow config extfile fortran ipcrm \
		 lp mailx manprog profiler sccs sgs spell sysdef units uucp
	do
		touch /tmp/$i\links
	done
	awk -f awkscript /issue/BASE | update >files
	chmod 644 /etc/mkroom_list
fi


/bin/rm -f missing.files tmp.files .issueflop d/* 2> /dev/null

fgrep -v LINK_ files | filelist 2> missing.files |\
sort -t\	 +1 -2 >  tmp.files

# note that the awkscript can only cope with up to 10 product sets
# at the moment this is sufficient as not all product sets need links

/bin/rm -f /tmp/*links
fgrep LINK_ files |\
fgrep -v '?' |\
awk '{printf("ln %s %s\n",substr($3,6),$1) > "/tmp/" $4 "links"}'
chmod 700 /tmp/*links

if [ -f missing.files ]
then
	set `wc missing.files`
	echo "there are $1 files missing, they are listed in missing.files\n"
fi

sed -e 's/\([^ 	]*\).*/\1/' tmp.files | cat devfiles bootonly lfonly - \
     > winch.file 
echo tmp/dolinks > winch.cpio
echo tmp/baseexec >> winch.cpio
sed -e 's/^\///' -e '/^tmp\/.*links/d' winch.file >> winch.cpio
rm winch.file tmp.files

cat /tmp/*links > /tmp/iss$$
mv /tmp/iss$$ /tmp/dolinks

echo "do you want to build the issue winch (y/n) ?"

read ANS
if [ "$ANS" = 'y' ]
then
	layout -c /dev/dsk/6s0 < /etc/lay.comdex
	mkfs /dev/dsk/6s1 `sizepart /dev/dsk/6s0 1` 
	labelit /dev/rdsk/6s1 root 0s1
	: Make usr
	mkfs /dev/dsk/6s3 `sizepart /dev/dsk/6s0 3`
	labelit /dev/rdsk/6s3 usr 0s3
	sync ; sync ; sync
	mount /dev/dsk/6s1 /mnt
	mkdir /mnt/usr
	mount /dev/dsk/6s3 /mnt/usr

	cd / ; cpio -ov < /issue/winch.cpio | ( cd /mnt; cpio -id )

	>/mnt/etc/mnttab
	sync ; sync ; sync
	umount /dev/dsk/6s1
	ib -d w -f /dev/dsk/6s0 -b /etc/boot.hd -o boot -s bootsec.w
	dd if=bootsec.w of=/dev/dsk/6s0 bs=256 count=1
	dd if=boot of=/dev/dsk/6s0 bs=256 seek=8
	sync;sync;sync
fi
