#!/usr/bin/bash
#
# Configuration by env:
#  - REPO=dir - specify repository directory, component will be guessed based
#    on basename

[ "$DEBUG" = "1" ] && set -x

# For additionally download sources
MAKE=${MAKE:-make}

[ -n "$REPO" ] && COMPONENT="`basename $REPO`"

have_src_targets() {
    [ "$REPO" == "." ] && return 1;
    $MAKE -C $REPO -n get-sources verify-sources >/dev/null 2>/dev/null
}

set -e

if have_src_targets; then
    export GNUPGHOME="$PWD/keyrings/$COMPONENT"
    mkdir -m 700 -p "$GNUPGHOME"
    echo "--> Downloading additional sources for $COMPONENT..."
    $MAKE -C $REPO get-sources
    echo "--> Verifying the sources..."
    $MAKE -C $REPO verify-sources
fi
