#!/bin/bash
#
# prersync: pre check an rsync tree to try to save rsync d/l
# author: Allen Bolderoff <allen@gist.net.au>

#edit these to suit your preference.
REMOTE_ROOT="ftp.sunet.se::Mandrake-devel/7.2beta/i586"
LOCAL_ROOT="/mnt/disk/Mandrake/7.2beta/i586"
REMOTE_LIST="/tmp/remote"
LOCAL_LIST="/tmp/local"
clear
echo 
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++"
echo "Rsync Minimiser"
echo
echo "THIS Script is released under GPL 2.0"
echo "it comes with no warranty or any other claim to work or otherwise do anything" 
echo "that you want/think it might do."
echo 
echo "Make sure you edit the variables at the top before you start"
echo
echo "Getting Local RPM List"
ls -1 $LOCAL_ROOT/Mandrake/RPMS/ > $LOCAL_LIST
echo
echo "About to download remote RPM LIST"
mkdir /tmp/test/

rsync -anv ftp.sunet.se::Mandrake-devel/7.2beta/i586/Mandrake/RPMS/ 
/tmp/test >
 $REMOTE_LIST



for i in `cat $LOCAL_ROOT/Mandrake/base/rpmslist`
   do
      LOC=`grep "^$i" $LOCAL_LIST | head -n1`
      REM=`grep "^$i" $REMOTE_LIST | head -n1`
      clear
      echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
      echo "$i"
      if [ "$REM" != "" ]; then
         if [ "$LOC" != "" ] ; then
            if [ "$REM" != "$LOC" ]; then
               echo "NEED TO MOVE" 
               echo "  $LOC"
               echo "to        $REM"
               echo "DO YOU WANT TO DO THIS? y/n"
               read a
               if [ "$a" = "y" ]; then
                  mv $LOCAL_ROOT/Mandrake/RPMS/$LOC $LOCAL_ROOT/Mandrake/RPMS/$REM
               else
                  echo "Not Moved"
               fi
            fi
         fi
      fi
   done
