#!/bin/bash
pushd ~/cvs/rpmfusion
repoquery --disablerepo=* --enablerepo=rpmfusion-{non,}free-rawhide --whatrequires --source `repoquery --provides --disablerepo=* --enablerepo=rpmfusion-free-rawhide ffmpeg-libs` | sort | sed 's/-[^-]*-[^-]*\.[^.]*\.[^.]*$//' | uniq > ffmpeg-deps.txt
sed -i '/^ffmpeg$/d' ffmpeg-deps.txt
if ! [ -d ffmpeg-rebuild ]; then
    mkdir ffmpeg-rebuild
fi
pushd ffmpeg-rebuild
for i in `cat ../ffmpeg-deps.txt`; do
    if ! [ -d $i ]; then
        rfpkg clone free/$i        
        pushd $i
    else
        pushd $i
        git pull
    fi
    if ! [ -f ../../`rfpkg verrel`.src.rpm ]; then
        rfpkg srpm
        mv `rfpkg verrel`.src.rpm ..
    fi
    popd
done
pushd ../ffmpeg
rfpkg srpm
FFMPEGVERREL=`rfpkg verrel`
popd
mockchain --continue -l . -r fedora-rawhide-x86_64-rpmfusion_free -m --enable-plugin=yum_cache ../ffmpeg/$FFMPEGVERREL.src.rpm  *.src.rpm
popd
popd
