#!/bin/sh

TDIR=COMPONENTS/${DH_COMPONENT}
SDIR=debian/components/${DH_COMPONENT}

if [ -z ${DH_COMPONENT} ]
then
    echo DH_COMPONENT not set
    exit 1
fi

if [ ! -d ${TDIR} ]
then
    echo ${TDIR} not a directory
    exit 1
fi

if [ ! -d ${SDIR}/patches ]
then
    # if no patches directory in source exit quietly
    exit 0;
fi

if mkdir ${TDIR}/debian 
then
    if ! ln -s ../../../${SDIR}/patches ${TDIR}/debian/patches
    then
        echo "Cannot link ${TDIR}/debian/patches"
        exit 1
    fi
else
    echo "Cannot make ${TDIR}/debian"
    exit 1
fi

cd ${TDIR}

SERIES=`quilt series`

if [ -z $SERIES ]
then
    cd ../..
    exit 0
fi

if quilt push -a
then
    EXIT_STATUS=0
else
    EXIT_STATUS=1
fi

cd ../..
exit $EXIT_STATUS


