#!/bin/sh

# configurable variables
pb=/var/portbuild

. ${pb}/portbuild.conf

unset DISPLAY

# copy one distfile to remote host
cpdistfile () {
  tar -C distfiles -cf - $1 | ssh $ftpsite -l $user tar -C $distfiledir -xvf -
}

echo "================================================"
echo "md5 generation started at $(date)"

cd $pb/bak/distfiles
find . -type f | sort | xargs md5 > ../../md5-2

echo "================================================"
echo "copying started at $(date)"

cd $pb/bak
for i in $(diff ../md5 ../md5-2 | grep '^>' | sed -e 's^.*(\./^^' -e 's/).*//'); do
  cpdistfile $i
done
mv ../md5-2 ../md5

echo "================================================"
echo "all done at $(date)"
