#!/bin/sh
set -e

cd "$ADTTMP"

sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
sed -i "s|incoming: /incoming|incoming: $ADTTMP/incoming|" /etc/debomatic/debomatic.conf
grep /etc/debomatic/debomatic.conf -e "incoming: $ADTTMP/incoming" || exit 1

mkdir -p $HOME/.dput.d/profiles
cat > $HOME/.dput.d/profiles/local.json << EOF
{
    "meta": "debomatic",
    "incoming": "$ADTTMP/incoming",
    "method": "local",
    "check-debs": {
        "skip": true
    }
}
EOF

mkdir "$ADTTMP"/incoming
version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
upstream=$(echo $version | cut -d"-" -f1 | xargs)
component=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 3 | cut -d"/" -f2 | sed 's/unstable/main/' | xargs)
dget -u http://deb.debian.org/debian/pool/$component/h/hello/hello_$version.dsc
cd hello-$upstream/
debuild -S -d -uc -us
dput local ../hello_"$version"_source.changes
debomatic -c /etc/debomatic/debomatic.conf -o "$ADTTMP"/incoming/hello_"$version"_source.changes -i
cat "$ADTTMP"/incoming/unstable/pool/hello_$version/hello_$version.buildlog
grep "$ADTTMP"/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
