#!/bin/csh
# distfiles2cd.csh by Julian H. Stacey 2001
# see also ctms2cd.csh & cvsup2cd.csh
# This script produces a cdrom images of a carved up tar of distfiles,

set date=`date -u +%Y-%m-%dT%H:%M:%SZ`
# set date="2001.06.18"	# over-ride date for a re-run

set tr_dir="/usr1/tmp/distfiles"

set dd_dir="/host/wind/usr1/tmp/distfiles"
# Warning: If dd_dir is an NFS filesystem, md5 will be a bit slow.

set cd_dir="/usr1/tmp/distfiles"
# Warning: mkisofs with output on an NFS filesystem is damn slow !

set tr_image="distfiles.$date.tar"
set dd_image="distfiles.$date.dd"
set cd_image="distfiles.$date.cd"

# set chunk="300000"	# 300000 records = 614400000 bytes
# set chunk="325000"	# 325000 records = 665600000 bytes
# set chunk="330000"	# 330000 records = 675840000 bytes
  set chunk="333000"	# 333000 records = 681984000 bytes
# For a single file of size 330000:675840000,
# mkisofs produces 330048 extents written (644 Mb) 675938304 bytes

# set mult="1"	# with this, dd from flip to wind was rather noisy.
set mult="100"
set lump=`echo "$chunk $mult / p" | dc`
set block=`echo "2 $mult * p" | dc`

echo "Zapping $tr_dir $dd_dir $cd_dir"
rm -rf $tr_dir
mkdir $tr_dir
rm -rf $dd_dir
mkdir $dd_dir
rm -rf $cd_dir
mkdir $cd_dir

cd /usr/ports/distfiles/..
# I've split the distfiles directory
tar -c -f $tr_dir/$tr_image README links 4.3-RELEASE current old
# 4.1.1-RELEASE 4.2-RELEASE

touch $dd_dir/md5
ls -l $tr_dir/$tr_image	>> $dd_dir/md5
md5   $tr_dir/$tr_image	>> $dd_dir/md5

foreach i ( 0 1 2 3 4 )	# {
  set skip=`echo "$chunk $i * p"|dc`
  echo calling dd if=$tr_dir/$tr_image bs=`echo $block`k count=$chunk of=$dd_dir/$dd_image.$i skip=$skip
  dd if=$tr_dir/$tr_image bs=2k count=$chunk of=$dd_dir/$dd_image.$i skip=$skip
  ls -l $dd_dir/$dd_image.$i	>> $dd_dir/md5
  md5   $dd_dir/$dd_image.$i	>> $dd_dir/md5
  end			# } i

rm $tr_dir/$tr_image
cp `which $0` $dd_dir/README

cd $dd_dir
foreach i ( 0 1 2 3 4 )	# {
    mkisofs	\
	-A "FreeBSD distfiles $date" \
	-P "http://www.berklix.com/~jhs/cv/" \
	-V distfiles \
	-copyright "JHS" \
	-o $cd_dir/$cd_image.$i \
	-p "Julian H. Stacey" \
	-pad \
	-r \
	md5 $dd_image.$i # README 
    ls -l $cd_dir/$cd_image.$i
    end			# } i
echo "Suggestions:"
echo "	vnconfig vn0 $cd_dir/$cd_image.0; mount -t cd9660 /dev/vn0c /mnt"
echo "	ls -al /mnt"
echo "	umount /dev/vn0c; vnconfig -u vn0"
echo "	rsh rain cdrecord -dummy -v -data $cd_dir/$cd_image.0"

# mkisofs: Volume set sequence number too big
#	-volset-seqno $i \
#	-volset-size 4 \
