#!/bin/sh
[ -f ~/mips64el/temp/stamp ] && exit 0
SECONDS=`date +%s`
YESTERDAY=`echo $SECONDS-5*24*60*60|bc`
DT=`LANG=C date --date=@$YESTERDAY`
touch -m -d"$DT" ~/mips64el/temp/stamp

TO_REMOVE=
remove_dummy(){
     NAME=$(echo $1 |cut -d'_' -f1)
     VERSION=$(echo $1 |cut -d'_' -f2)
     ARCH=$(echo $1 |cut -d'_' -f3 |cut -d'.' -f1)
     TYPE=$(echo $1 |cut -d'_' -f3 |cut -d'.' -f2)
     V_REPO_CAP=$(reprepro -b ~/mips64el -A${ARCH} -T${TYPE} list sid $NAME |cut -d' ' -f3)
     V_REPO=$(echo $V_REPO_CAP|cut -d':' -f2)
     [ "$V_REPO" = "$VERSION" ] && reprepro -b ~/mips64el -A${ARCH} -T${TYPE} remove sid $NAME > /dev/null
}

#remove_dummy di_4.30-1_mips64el.deb

for i in `ls ~/mips64el/incoming/ |grep "deb$" 2>/dev/null`;do
    remove_dummy $i
done
reprepro -b ~/mips64el export
reprepro -b ~/mips64el update 2>&1 > /dev/null

reprepro includedeb sid `find -name *_all.deb -cnewer ~/mips64el/temp/stamp` > /dev/null 2>&1 
#reprepro includedeb sid `ls ./incoming/*perl*_all.deb`
#reprepro includedsc sid `find -name *_source_changes -mtime -4` > /dev/null 2>&1 

reprepro -b ~/mips64el processincoming only-unstable > /dev/null
rm ~/mips64el/temp/stamp
