#!/bin/sh
#
# Copyright (C) 2003 Simon "janus" Dassow <janus@errornet.de>
#
# This `software' is released under the BSD-license
#



server=ftp2.de.openbsd.org
path=/pub/OpenBSD
ver=3.4
arch=i386
startdir=`pwd`
script="$startdir/fetch.sh"
mkisofs=`which mkisofs`
packagefile=custom.packages


mkdir -p $ver/$arch
mkdir -p $ver/packages/$arch

# ftp connect
echo "ftp -n $server <<EOFTP" > $script
echo 'user anonymous "me@"' >> $script
echo "prompt" >> $script

# sources
echo "cd $path/$ver/" >> $script
echo "get ANNOUNCEMENT" >> $script
echo "get HARDWARE" >> $script
echo "get PACKAGES" >> $script
echo "get PORTS" >> $script
echo "get README" >> $script
echo "get XF4.tar.gz" >> $script
echo "get ftplist" >> $script
echo "get ports.tar.gz" >> $script
echo "get root.mail" >> $script
echo "get src.tar.gz" >> $script
echo "get sys.tar.gz" >> $script

# base
echo "cd $path/$ver/$arch" >> $script
echo "lcd $startdir/$ver/$arch" >> $script
echo "mget *" >> $script


echo "cd $path/$ver/packages/$arch" >> $script
echo "lcd $startdir/$ver/packages/$arch" >> $script

for file in `cat $startdir/$packagefile`; do
	echo "get $file" >> $script
done

echo "bye" >> $script
echo "EOFTP" >> $script

echo -n "Start download? [Yn] "
read go
case "$go" in
	[nN]|[nN][oO])
		echo "Skipping..."
		;;
	*)
		. $script
		;;
esac

cd $startdir

if [ ! -x $mkisofs ]; then
	echo "No mkisofs installed!"
	echo "Skipping ISO creation."
else
	mkiso=y
	echo -n "Generate ISO file? [Yn] "
	read mkiso
	case "$mkiso" in
		[nN]|[nN][oO])
			echo "ISO creation aborted!"
			echo "But files all fetched:"
			find $ver
			;;
		*	)
			echo "Creating ISO file..."
			mkisofs -v -r -l -L -T -J -V "OpenBSD $ver" -A "OpenBSD $ver" -b $ver/$arch/cdrom${ver/.}.fs -c boot.catalog -o obsd${ver/.}.iso -x obsd${ver/.}.iso .
			echo ""
			echo "Ok, your ISO (obsd${ver/.}.iso) is ready, simply burn it with cdrecord."
			;;
	esac
fi

echo ""
echo "Enjoy :)"
echo ""


