#!/bin/sh

# Shell script to test changes files with piuparts. This script is useful if
# we want to write seperate logs for each changes file processed.
# To use this script, do the following.
# piuparts-changes-test [changes1 changes2 ...]

CHANGES_LIST="$*"

# Directory where log files should be written.
LOGFILE_DIR="$HOME/piuparts-logs"

# Options to pass to piuparts aside from --log-file
PIUPARTS_OPTIONS="--basetgz=/media/sdb/pbuilder/unstable-i386-base.tgz"

for CHANGES in $CHANGES_LIST; do
    if ! $(basename $CHANGES | grep -q '.*\.changes$'); then
        echo "$CHANGES is not a changes file."
        continue
    fi
    if [ ! -r $CHANGES ]; then
        echo "Cannot read $CHANGES."
        continue
    fi
    echo "Testing packages in $CHANGES with piuparts."
    # piuparts appends the log to a file rather than overwriting. The line
    # below will erase the log file so we can start a new log.
    printf "" >$LOGFILE_DIR/$(basename $CHANGES | sed 's/\.changes$//').piuparts.log
    piuparts \
        --log-file=$LOGFILE_DIR/$(basename $CHANGES | sed 's/\.changes$//').piuparts.log \
        $PIUPARTS_OPTIONS \
        $CHANGES
done
