#!/bin/sh
URL=$1
MD5_FILE="g2v_md5_fixes"

rm -f $MD5_FILE >/dev/null 2>&1
wget "${URL}/${MD5_FILE}"

ARCHS=$(cat $MD5_FILE | cut -f 3 -d " ")

for i in $ARCHS ; do
   WP=""
   if [ -f ${i} ] ; then
      echo "Checking md5sum <${i}> ..."
      MD5=$(md5sum ${i} | cut -f 1 -d " ")
      if [ "$(grep ${i} ${MD5_FILE} | grep $MD5)" != "" ] ; then
         continue
      else
         rm -f ${i}
      fi    
   fi
   echo "Downloading <${i}> ..."
   wget $WP ${URL}/${i}
   MD5=$(md5sum ${i} | cut -f 1 -d " ")
   if [ "$(grep ${i} ${MD5_FILE} | grep $MD5)" = "" ] ; then
      echo "Error getting ${i}"
      exit -1
   fi
done

for i in $ARCHS ; do
   echo "<$i>"
   if [ "$i" = "rc4inst.tar.bz2" ] ; then
      bzip2 -d -c rc4inst.tar.bz2 > rc4inst.tar
      tar -xvf rc4inst.tar
      rm rc4inst.tar
   else
      cp -f $i g2v_inst
   fi
done
