#!/bin/sh
##
## "dotest" is my stupid name for my patch-application script, which
## I never got around to renaming after I tested it. We're now on the
## second generation of scripts, still called "dotest".
##
## You give it a mbox-format collection of emails, and it will try to
## apply them to the kernel using "applypatch"
##
## applypatch [ -i ] patch1 [patch2...]
##

WORKDIR=`mktemp -d` || exit 1

case $1 in

	-i)	touch $WORKDIR/.confirm_apply
		shift;;
esac

#mailsplit $1 $WORKDIR || exit 1

for i in "$@"
do
	mailinfo $WORKDIR/msg $WORKDIR/patch $WORKDIR/files < $i > $WORKDIR/info || exit 1
	stripspace < $WORKDIR/msg > $WORKDIR/msg-clean
	~/lib/apply_parsed_patch $WORKDIR
	ret=$?
	if [ $ret -ne 0 ]; then
		# 2 is a special exit code from applypatch to indicate that
		# the patch wasn't applied, but continue anyway
		[ $ret -ne 2 ] && exit $ret
	fi
done

rm -fr $WORKDIR
