#!/bin/bash
# download_packages

DIR_DOWNLOAD=downloads
INPUT=
SERVER=

echo "Download packages"
echo ""
echo "Instead of downloading the required packages to build your LFS system from the"
echo "official distribution sites, you can download all of them conviniently from one"
echo "of our FTP sites."
echo ""
echo -n "Enter mirror number (type L to list numbers): "

read INPUT

if [ "$INPUT" = "L" ]; then
	echo ""
	echo "FTP Mirrors"
	echo ""
	echo "Please pick a mirror site that's geographically closest to your location."
	echo ""
	echo "North America"
	echo " 1  Fremont, California, USA [FTP] [8 Mbit]"
	echo " 2  Fremont, California, USA [HTTP] [8 Mbit]"
	echo " 3  Lufkin, Texas, USA [FTP] [6 Mbit]"
	echo " 4  Lufkin, Texas, USA [HTTP] [6 Mbit]"
	echo ""
	echo "Europe"
	echo " 5  Univ. of Twente, The Netherlands [HTTP] [100 Mbit]"
	echo " 6  Univ. of Twente, The Netherlands [FTP] [100 Mbit]"
	echo " 7  Oslo, Norway [FTP] [100 Mbit]"
	echo " 8  Lancaster, UK [HTTP] [100 Mbit]"
	echo " 9  Vienna Univ. of Tech., Austria [FTP] [64 Mbit]"
	echo "10  Vienna Univ. of Tech., Austria [HTTP] [64 Mbit]"
	echo "11  Karlskrona, Sweden [FTP] [10 Mbit]"
	echo "12  Freising, Germany [HTTP] [4 Mbit]"
	echo "13  Freising, Germany [FTP] [4 Mbit]"
	echo ""
	echo "Australia"
	echo "14  Brisbane, Australia [FTP] [155 Mbit]"
	echo ""
	echo "Asia"
	echo "15  Singapore, Singapore [FTP] [45 Mbit]"
	echo "16  Singapore, Singapore [HTTP] [45 Mbit]"
	echo ""
	echo "Other"
	echo " 0  Custom server"
	echo ""
	echo -n "Enter mirror number: "
	read INPUT
fi

if [ "$INPUT" = "1" ]; then
	SERVER=ftp://ftp.linuxfromscratch.org
elif [ "$INPUT" = "2" ]; then
	SERVER=http://ftp.linuxfromscratch.org
elif [ "$INPUT" = "3" ]; then
	SERVER=ftp://linuxfromscratch.idge.net/linuxfromscratch
elif [ "$INPUT" = "4" ]; then
	SERVER=http://ftp.idge.net/linuxfromscratch
elif [ "$INPUT" = "5" ]; then
	SERVER=http://ftp.snt.utwente.nl/os/linux/lfs
elif [ "$INPUT" = "6" ]; then
	SERVER=ftp://ftp.snt.utwente.nl/pub/os/linux/lfs
elif [ "$INPUT" = "7" ]; then
	SERVER=ftp://ftp.no.linuxfromscratch.org/mirrors/lfs
elif [ "$INPUT" = "8" ]; then
	SERVER=http://www.mirror.ac.uk/sites/ftp.linuxfromscratch.org
elif [ "$INPUT" = "9" ]; then
	SERVER=ftp://ftp.at.linuxfromscratch.org/pub/lfs
elif [ "$INPUT" = "10" ]; then
	SERVER=http://ftp.at.linuxfromscratch.org/pub/lfs
elif [ "$INPUT" = "11" ]; then
	SERVER=ftp://ftp.se.linuxfromscratch.org/lfs
elif [ "$INPUT" = "12" ]; then
	SERVER=http://ftp.de.linuxfromscratch.org
elif [ "$INPUT" = "13" ]; then
	SERVER=ftp://ftp.de.linuxfromscratch.org/mirrors/ftp.linuxfromscratch.org
elif [ "$INPUT" = "14" ]; then
	SERVER=ftp://ftp.planetmirror.com/pub/lfs
elif [ "$INPUT" = "15" ]; then
	SERVER=ftp://ftp.sg.linuxfromscratch.org/pub/lfs
elif [ "$INPUT" = "16" ]; then
	SERVER=http://ftp.sg.linuxfromscratch.org
elif [ "$INPUT" = "0" ]; then
	echo -n "Enter server (i.e. ftp://10.0.0.1/mirror/ftp.linuxfromscratch.org): "
	read SERVER
else
	echo "Error - incorrect or missing argument"
	exit 1
fi

if [ ! -d $DIR_DOWNLOAD ]; then
	mkdir $DIR_DOWNLOAD
fi

cd $DIR_DOWNLOAD
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3-HTML.tar.bz2
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3-NOCHUNKS.html.bz2
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3.pdf.bz2
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3.ps.bz2
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3.txt.bz2
wget -c $SERVER/lfs-books/3.3/LFS-BOOK-3.3-XML.tar.bz2
wget -c $SERVER/lfs-commands/lfs-commands-3.3.tar.bz2
wget -c $SERVER/lfs-packages/3.3/lfs-packages-3.3.tar

cat > MD5SUM << "EOF"
25be464ffa58f7a305e8891587849279  LFS-BOOK-3.3-HTML.tar.bz2
8aa1eeed92f4f704d6c466eafdda1550  LFS-BOOK-3.3-NOCHUNKS.html.bz2
c939850dde13096aa7dc771d42541474  LFS-BOOK-3.3.pdf.bz2
9c4cbf1b65a2726fcae1804f8a634cbc  LFS-BOOK-3.3.ps.bz2
168dcac2dad4a7799bfd4e10ac2198a3  LFS-BOOK-3.3.txt.bz2
ad06e6bf6f8592fbaf016290a335b726  LFS-BOOK-3.3-XML.tar.bz2
0c0ff1eca7fab1a423b3ec66a8b387ba  lfs-commands-3.3.tar.bz2
e24dcf32976c8f0019a4794aafc07afb  lfs-packages-3.3.tar
EOF

md5sum -c MD5SUM -v
