#!/bin/sh

set -e

PACKAGE=$1

cd ../build

CHANGES="$(find -name "$PACKAGE"'_*.changes')"
LOG_LINK="$(find -name "$PACKAGE"'_*amd64.build')"

if [ -L "$LOG_LINK" ]; then
    LOG="$(readlink "$LOG_LINK")"
    if [ -f "$LOG" ]; then
        mv "$LOG_LINK" "$LOG" ../pool
    fi
fi

if [ -f "$CHANGES" ] && [ "$(dcmd "$CHANGES" | grep '\.deb$' | wc -l)" -ge 1 ]; then
    dcmd mv "$CHANGES" ../pool
fi
