#!/bin/sh
# /etc/apt/sources.list
# deb-src http://e-tobi.net/vdr-experimental sid base vdr
# deb-src http://e-tobi.net/vdrdevel-experimental sarge vdr-multipatch

#PLUGINS=$(wget -qO- http://e-tobi.net/vdrdevel-experimental/dists/sarge/vdr-multipatch/source/Sources.gz|zcat|awk '/^Package/{print $2}'|sort -u|grep vdr-plugin-)
PLUGINS="vdr-plugin-svdrpservice $(wget -qO- http://e-tobi.net/vdr-experimental/dists/sid/vdr/source/Sources.gz|zcat|awk '/^Package/{print $2}'|sort -u|grep vdr-plugin-|grep -v vdr-plugin-svdrpservice)"

mkdir -p compile
cd compile

LOG=build.log

compile() {
 [ "$2" == "-d" ] || apt-get source -d $1
 echo "building $1 ($(date -R))" | tee -a $LOG
 rm -f $1.log
 if pbuilder-adv.sh build --logfile $1.log $1_*.dsc; then
  echo "completed $1 ($(date -R))" | tee -a $LOG
  rm -f $1.log
 else
  echo "error $1 ($(date -R))" | tee -a $LOG
 fi
}

rm -f $LOG

# use multipatch
DIR=$(apt-get source vdr 2>&1|awk '/dpkg-source: extracting/{print$5}')
cd $DIR
wget -qO debian/patches/00list http://www.e-tobi.net/vdrdevel/sarge/experimental/patchlists/multipatch.00list
debuild -S
cd ..

compile vdr -d

# plugin depends
compile graphlcd-base
compile serdisplib

for p in $PLUGINS; do
 compile $p
done
