Salut,
Find appended the configure'd version of a preliminary script to
faciliate patch generation following the methods defined earlier
in conversations. It's probably ugly, but it's one more quick
thing, and hey, it works!
The system variables are mostly determined by the running system,
which may not always be right - but some build.sh-like flags can
be passed to overcome this. The OpenSSL key has a default in
/etc/openssl/private/$OS.pem - e.g. NetBSD.pem - and also doesn't
need to be passed. The plist file is generated using diff if
not given; for that to work, the builddir must be kept in the
same location for both builds.
The pullup ID is required to retrieve the message. I'm not sure
there's a better way.
An example would be:
mkpatch /usr/oobj/destdir /usr/obj/destdir 423
It is certainly still going to undergo a lot of work, and your
input is really valued.
Now toast. ;-)
Tonnerre
#!/bin/sh
#
# (c) 2009, Tonnerre Lombard <tonnerre%NetBSD.org@localhost>,
# The NetBSD Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of the The NetBSD Foundation nor the name of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $patchadd$
#
## Basic definitions
OPENSSL="/usr/bin/openssl"
TAR="/bin/tar"
OSABI=`uname -s`
OSVERS=`uname -r`
OSARCH=`uname -m`
BSPATCH="/usr/pkg/bin/bspatch"
BASENAME="/usr/bin/basename"
BSDIFF="/usr/pkg/bin/bsdiff"
CP="/bin/cp"
MV="/bin/mv"
RM="/bin/rm"
MKDIR="/bin/mkdir"
AWK="gawk"
LYNX="/usr/pkg/bin/lynx"
PULLUP_TRACKER_BASE="http://releng.netbsd.org/cgi-bin/req-{}.cgi"
exitcode=0
## Actual code
usage() {
echo "$0 [-p <plist-file>] [-m <machine-arch>] [-r <release>]" 1>&2
echo " [-k <keyfile>] <olddir> <builddir> <pullup-id>" 1>&2
echo 1>&2
echo " -p plist-file" 1>&2
echo " PLIST file containing a list of files to diff." 1>&2
echo " -k keyfile" 1>&2
echo " Path to the patch signing key." 1>&2
echo " -s os-abi" 1>&2
echo " The OS ABI of the build, if differing." 1>&2
echo " -m machine-arch" 1>&2
echo " The architecture of the build, if differing." 1>&2
echo " -r release" 1>&2
echo " The release of the build, if differing." 1>&2
exit 1
}
args=`getopt p:k:s:m:r: $*`
[ $? -eq 0 ] || usage
set -- $args
PLIST=''
KEYFILE=''
while [ $# -gt 0 ]
do
case "$1" in
-p)
PLIST="$2"
shift
;;
-s)
OSABI="$2"
shift
;;
-m)
OSARCH="$2"
shift
;;
-r)
OSVERS="$2"
shift
;;
-k)
KEYFILE="$2"
shift
;;
--)
shift; break
;;
esac
shift
done
if [ "$#" -lt 3 ]
then
echo "Too few arguments." 1>&2
usage
fi
OSMAJ=`echo "${OSVERS}" | awk -F. '{ print $1 }'`
OSFULL=`echo "${OSVERS}" | awk -F_ '{ print $1 }'`
PULLUP_TRACKER=`echo "${PULLUP_TRACKER_BASE}" | sed -e"s@{}@${OSMAJ}@g"`
ORIGDIR="$1"
BUILDDIR="$2"
PULLUP="$3"
shift; shift; shift
if [ -z "${KEYFILE}" ]
then
KEYFILE="/etc/openssl/private/${OSABI}.pem"
fi
if [ ! -f "${KEYFILE}" ]
then
echo "Key file ${KEYFILE} not found." 1>&2
usage
fi
if [ -z "${PLIST}" ]
then
PLIST=`mktemp /tmp/mkpatch-XXXXXX`
diff -rq "${ORIGDIR}" "${BUILDDIR}" | sed -e's/^Files //g' \
-e's@ and .* differ$@@g' -e"s@${ORIGDIR}@@g" > "${PLIST}"
fi
WRKDIR=`mktemp -d /tmp/mkpatch-XXXXXX`
OUTDIR=`pwd`
"${LYNX}" -dump "${PULLUP_TRACKER}?show=${PULLUP}" | \
sed -e '1,/Modified Files:/d' -e \
'/To generate a diff of this commit/,$d' | \
sed -e'1,3d' > "${WRKDIR}/+COMMENT"
SHORTCOMMENT=`head -1 "${WRKDIR}/+COMMENT"`
cat << EOT > "${WRKDIR}/+INFO"
ABI=${OSABI}
OS_VERSION=${OSFULL}
MACHINE_ARCH=${OSARCH}
PATCHTOOLS=0.1
NAME=${OSFULL}-${PULLUP}
COMMENT=${SHORTCOMMENT}
EOT
(while read file
do
PFILE=`echo "${file}" | tr '/' '_' | sed -e's/^_//'`
OSUM=`sha1 -n "${ORIGDIR}/${file}" | awk '{ print $1 }'`
NSUM=`sha1 -n "${BUILDDIR}/${file}" | awk '{ print $1 }'`
"${BSDIFF}" "${ORIGDIR}/${file}" "${BUILDDIR}/${file}" \
"${WRKDIR}/${PFILE}"
echo "${file}" "${PFILE}" "${OSUM}" "${NSUM}" "${OSUM}" >> \
"${WRKDIR}/+CONTENTS"
done) < "${PLIST}"
(cd "${WRKDIR}"; "${TAR}" cjvf "${OUTDIR}/${OSFULL}-${PULLUP}.tbz" *)
"${OPENSSL}" smime -sign -binary -outform PEM -signer "${KEYFILE}" \
-in "${OUTDIR}/${OSFULL}-${PULLUP}.tbz" -out \
"${OUTDIR}/${OSFULL}-${PULLUP}.tbz.sig"
exit $exitcode
Attachment:
pgpODwLyeg8is.pgp
Description: PGP signature