#!/bin/bash

source ./scripts/pkgver

cd $SRCDIR

# bash
if [ ! -f bash-$BASH_VER.tar.gz ]; then
  wget http://ftp.gnu.org/gnu/bash/bash-$BASH_VER.tar.gz
fi

if [ $BASH_PATCHLEVEL -gt 000 ]; then
  for p in $(seq -w 001 $BASH_PATCHLEVEL); do
      if [ ! -f bash${BASH_VER/.}-$p ]; then
        wget http://ftp.gnu.org/gnu/bash/bash-$BASH_VER-patches/bash${BASH_VER/.}-$p
      fi
  done
fi

# binutils
if [ ! -f binutils-$BINUTILS_VER.tar.bz2 ]; then
  wget http://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VER.tar.bz2
fi

# bison
if [ ! -f bison-$BISON_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/bison/bison-$BISON_VER.tar.gz
fi

# bzip2
if [ ! -f bzip2-$BZIP2_VER.tar.gz ]; then
  wget http://www.bzip.org/$BZIP2_VER/bzip2-$BZIP2_VER.tar.gz
fi

# cloog-ppl
if [ ! -f cloog-ppl-$CLOOG_PPL_VER.tar.gz ]; then
  wget ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-ppl-$CLOOG_PPL_VER.tar.gz
fi

# coreutils
if [ ! -f coreutils-$COREUTILS_VER.tar.gz ]; then
  wget http://ftp.gnu.org/gnu/coreutils/coreutils-$COREUTILS_VER.tar.gz
fi

# diffutils
if [ ! -f diffutils-$DIFFUTILS_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/diffutils/diffutils-$DIFFUTILS_VER.tar.gz
fi

# e2fsprogs
if [ ! -f e2fsprogs-$E2FSPROGS_VER.tar.gz ]; then
  wget http://downloads.sourceforge.net/sourceforge/e2fsprogs/e2fsprogs-$E2FSPROGS_VER.tar.gz
fi

# fakeroot
if [ ! -f fakeroot_$FAKEROOT_VER.orig.tar.bz2 ]; then
  wget http://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_$FAKEROOT_VER.orig.tar.bz2
fi

# findutils
if [ ! -f findutils-$FINDUTILS_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/pub/gnu/findutils/findutils-$FINDUTILS_VER.tar.gz
fi

# file
if [ ! -f file-$FILE_VER.tar.gz ]; then
  wget ftp://ftp.astron.com/pub/file/file-$FILE_VER.tar.gz
fi

# flex
if [ ! -f flex-$FLEX_VER.tar.bz2 ]; then
  wget http://downloads.sourceforge.net/sourceforge/flex/flex-$FLEX_VER.tar.bz2
fi

# gawk
if [ ! -f gawk-$GAWK_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/gawk/gawk-$GAWK_VER.tar.gz
fi

# gcc
if [ ! -f gcc-core-$GCC_VER.tar.bz2 ]; then
  wget http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/gcc-core-$GCC_VER.tar.bz2
fi
if [ ! -f gcc-g++-$GCC_VER.tar.bz2 ]; then
  wget http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/gcc-g++-$GCC_VER.tar.bz2
fi

# gettext
if [ ! -f gettext-$GETTEXT_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VER.tar.gz
fi

# glibc
if [ ! -f glibc-$GLIBC_VER.tar.bz2 ]; then
  wget http://ftp.gnu.org/gnu/glibc/glibc-$GLIBC_VER.tar.bz2
fi

# gmp
if [ ! -f gmp-$GMP_VER.tar.bz2 ]; then
  wget ftp://ftp.gnu.org/gnu/gmp/gmp-$GMP_VER.tar.bz2
fi

# grep
if [ ! -f grep-$GREP_VER.tar.bz2 ]; then
  wget ftp://ftp.gnu.org/gnu/grep/grep-$GREP_VER.tar.bz2
fi

# grub
if [ ! -f grub-$GRUB_VER.tar.gz ]; then
  wget ftp://alpha.gnu.org/gnu/grub/grub-$GRUB_VER.tar.gz
fi

# gzip
if [ ! -f gzip-$GZIP_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/pub/gnu/gzip/gzip-$GZIP_VER.tar.gz
fi

# m4
if [ ! -f m4-$M4_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/m4/m4-$M4_VER.tar.gz
fi

# make
if [ ! -f make-$MAKE_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/make/make-$MAKE_VER.tar.gz
fi

# mpfr
if [ ! -f mpfr-$MPFR_VER.tar.bz2 ]; then
  wget http://mpfr.loria.fr/mpfr-current/mpfr-$MPFR_VER.tar.bz2
fi

# nano
if [ ! -f nano-$NANO_VER.tar.gz ]; then
  wget http://www.nano-editor.org/dist/v2.2/nano-$NANO_VER.tar.gz
fi

# ncurses
if [ ! -f ncurses-$NCURSES_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses-$NCURSES_VER.tar.gz
fi

# patch
if [ ! -f patch-$PATCH_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/patch/patch-$PATCH_VER.tar.gz
fi

# ppl
if [ ! -f ppl-$PPL_VER.tar.gz ]; then
  wget http://www.cs.unipr.it/ppl/Download/ftp/releases/$PPL_VER/ppl-$PPL_VER.tar.gz
fi

# sed
if [ ! -f sed-$SED_VER.tar.bz2 ]; then
  wget ftp://ftp.gnu.org/gnu/sed/sed-$SED_VER.tar.bz2
fi

# tar
if [ ! -f tar-$TAR_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/gnu/tar/tar-$TAR_VER.tar.gz
fi

# texinfo
if [ ! -f texinfo-$TEXINFO_VER.tar.gz ]; then
  wget ftp://ftp.gnu.org/pub/gnu/texinfo/texinfo-$TEXINFO_VER.tar.gz
fi

# xz-utils
if [ ! -f xz-$XZ_UTILS_VER.tar.gz ]; then
  wget http://tukaani.org/xz/xz-$XZ_UTILS_VER.tar.gz
fi

# zlib
if [ ! -f zlib-$ZLIB_VER.tar.gz ]; then
  wget http://www.zlib.net/zlib-$ZLIB_VER.tar.gz
fi

# gnumach-git
if [ -d $SRCDIR/gnumach ]; then
  cd $SRCDIR/gnumach && git pull origin
else
  cd $SRCDIR
  git clone git://git.sv.gnu.org/hurd/gnumach.git
fi

# hurd-git
if [ -d $SRCDIR/hurd ]; then
  cd $SRCDIR/hurd && git pull origin
else
  cd $SRCDIR
  git clone git://git.sv.gnu.org/hurd/hurd.git
fi

# libpthread-git
if [ -d $SRCDIR/libpthread ]; then
  cd $SRCDIR/libpthread && git pull origin
else
  cd $SRCDIR
  git clone git://git.sv.gnu.org/hurd/libpthread.git
fi

# mig-git
if [ -d $SRCDIR/mig ]; then
  cd $SRCDIR/mig && git pull origin
else
  cd $SRCDIR
  git clone git://git.sv.gnu.org/hurd/mig.git
fi

cd $ROOT
