#!/bin/bash
#
#  Update slackware
#
#  JM 7/1998

# usage:   slackware.wget [anything]
# any argument at all skips mirroring, moves right to cleanup.

site=ftp://sunsite.unc.edu
sitedir=pub/Linux/distributions/slackware-3.6; cutdirs=3
localdir=`basename $sitedir`
log=slackware.log
excludes=""
for exclude in bootdsks.12 source slaktest live kernels; do
  [ "$excludes" ] && excludes="${excludes},"
  excludes="${excludes}${sitedir}/${exclude}"
done

# Do the mirroring:

if [ ! "$*" ]; then
 echo -n "Mirroring from $site (see $log) ... "
 wget -w 5 --mirror $site/$sitedir -o $log -nH --cut-dirs=$cutdirs -X"$excludes"
 echo "done."
fi

# Remove old stuff
# (important, but wipes out extra stuff you might have added)

echo "Removing old stuff ..."
for d in `find $localdir -depth -type d`; do
  pushd $d > /dev/null
  for f in *; do
     grep -q "$f" .listing || { rm -rf "$f" && echo $d/$f; }
  done
  popd > /dev/null
done
echo "Done."