blob: 36d03a39c4d385663d4753b1e7fae1c93e0d7738 [file] [log] [blame]
#!/bin/sh -efu
# Copyright 2011-2012 Intel Corporation
# Author: Artem Bityutskiy
# License: GPLv2
srcdir="$(readlink -ev -- ${0%/*})"
PATH="$srcdir:$srcdir/..:$srcdir/../helpers:$srcdir/../helpers/libshell:$PATH"
. shell-error
. shell-signal
. aiaiai-sh-functions
. aiaiai-email-sh-functions
PROG="${0##*/}"
message_time="yes"
# This is a small trick to make sure the script is portable - check if 'dash'
# is present, and if yes - use it.
if can_switch_to_dash; then
exec dash -euf -- "$srcdir/$PROG" "$@"
exit $?
fi
show_usage()
{
cat <<-EOF
Usage: $PROG [options] <mbox> <fail_file> <queuedir> <cfgfile.ini>
This is a helper program which runs the aiaiai-email-test-patchset program for
the <mbox> file. If aiaiai-email-test-patchset returns success - just exit.
Otherwise it moves the <mbox> file back to the <queuedir> directory and create
file <fail_file>.
aiaiai-email-test-patchset will return failure only in case of internal bug or
error, and not if any test on the patch <mbox> failed. So the reason we move
<mbox> back to the queue is to make sure we do not lose the patch in case of an
internal bug.
<mbox> - the mbox file to feed to aiaiai-email-test-patchset
<fail_file> - the file to create in case of failure
<queuedir> - the directory containing the queue of patches
<cfgfile.ini> - aiaiai-email-test-patchset's configuration
Options:
-v, --verbose be verbose;
-h, --help show this text and exit.
EOF
}
fail_usage()
{
[ -z "$1" ] || printf "%s\n" "$1"
show_usage
exit 1
}
tmpdir=
cleanup_handler()
{
rm $verbose -rf -- "$tmpdir" >&2
}
set_cleanup_handler cleanup_handler
TEMP=`getopt -n $PROG -o v,h --long verbose,help -- "$@"` ||
fail_usage ""
eval set -- "$TEMP"
verbose=
while true; do
case "$1" in
-v|--verbose) verbose=-v
;;
-h|--help)
show_usage
exit 0
;;
--) shift; break
;;
*) fail_usage "Unrecognized option: $1"
;;
esac
shift
done
[ "$#" -eq 4 ] || fail_usage "Insufficient or too many arguments"
mbox="$(readlink -fv -- "$1")"; shift
fail_file="$1"; shift
queuedir="$(readlink -fv -- "$1")"; shift
cfgfile="$1"; shift
# Parse the configuration file
parse_config "$cfgfile"
tmpdir="$(mktemp -dt "$PROG.XXXX")"
verbose "Validating \"$mbox\", queue directory is: $queuedir"
verbose "Configuration file: $cfgfile"
mv $verbose -- "$mbox" "$tmpdir" >&2
file="$tmpdir/${mbox##*/}"
if ! cat -- "$file" | aiaiai-email-test-patchset "$verbose" "$cfgfile"; then
verbose "Validation failed"
touch -- "$fail_file"
mv $verbose -- "$file" "$queuedir" >&2
exit 1
fi
verbose "Validated successfully"