The script may be executed multiple times from the same directory. It will detect the changes made in the repositoty, it will remove the obsolete local files and will only download the newer files that are not present in the local copy.
#!/bin/sh
# Copyright 2008-2009 Nikos Skalkotos, Athens, Greece
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
server=ftp://ftp.ntua.gr
url_path=pub/linux/slackware/slackware-current/testing/packages/kde4
url=$server/$url_path
dirs="deps extragear kde kde3-compat kde-l10n"
files="remove-kde3.sh remove-kde4.sh"
if [ "$1" = "--clean" ]; then
echo -n "Cleaning up..."
rm -fr $files $dirs
echo "done"
exit 0
fi
remove_obsolete() {
echo "Checking local directory \"$1\" for obsolete files..."
(cd $1
for i in `ls`; do
exists=`echo "$2" | grep $i`
if [ $i != "" -a "$exists" = "" ] ; then
echo "Removing file: $1/$i"
rm -f $i
fi
done
)
}
for filename in $files; do
#Those are small scripts, so I'll download them every time
rm -f $filename
wget -c $url/$filename
done
for dir in $dirs; do
#I need to create the dir the first time
mkdir -p "$dir"
echo
#Clean old files no longer listened in the repository
echo -n "Listing kde4/$dir content..."
dir_content=`curl -sl $url/$dir/`
echo "done"
remove_obsolete $dir "$dir_content"
#Now mirror the directory
(cd $dir; wget --mirror -nH -nd $url/$dir/)
done