Roland McGrath 11487c5
#!/bin/sh
Roland McGrath 11487c5
a98ed5c
# Facilitates the addition of a new patch to the source tree.
a98ed5c
# -- Moves patch to tree
a98ed5c
# -- Adds  patch to kernel.spec list of patches
a98ed5c
# -- Adds patch to git
a98ed5c
# -- change buildid macro to the name of the patch being added
Roland McGrath 11487c5
a98ed5c
# Base directory is relative to where the script is.
a98ed5c
BASEDIR="$(dirname "$(cd $(dirname $BASH_SOURCE[0]) && pwd)")"
a98ed5c
pushd $BASEDIR > /dev/null
a98ed5c
# Check for at least patch
a98ed5c
if [ "$#" -lt 1 ]; then
a98ed5c
    echo "usage: $0 [ /path/to/patch/ ] [ description ]"
a98ed5c
    exit 1
a98ed5c
fi
a98ed5c
PATCHDIR=$1
a98ed5c
DESC=$2
a98ed5c
PATCH="$(basename "$PATCHDIR")"
a98ed5c
# Kernel.spec file in the current tree
a98ed5c
SPECFILE="$BASEDIR/kernel.spec"
a98ed5c
# If adding patch from outside the source tree move it to the source tree
a98ed5c
if [ -z "$(ls | grep $PATCH)" ]; then
a98ed5c
    cp $PATCHDIR $BASEDIR/
a98ed5c
fi
Roland McGrath 11487c5
a98ed5c
if [ ! -z "$(grep $PATCH $SPECFILE)" ]
a98ed5c
then
a98ed5c
    echo "$PATCH already in kernel.spec"
a98ed5c
    exit 1
a98ed5c
fi
a98ed5c
# ID number of the last patch in kernel.spec
a98ed5c
LPATCH_ID=$(grep ^Patch $SPECFILE | tail -n1 | awk '{ print $1 }' | sed s/Patch// | sed s/://)
a98ed5c
# ID of the next patch to be added to kernel.spec
a98ed5c
NPATCH_ID=$(($LPATCH_ID + 1 ))
a98ed5c
# Add patch with new id at the end of the list of patches
a98ed5c
sed -i "/^Patch$LPATCH_ID:\ /a#\ $DESC\nPatch$NPATCH_ID:\ $PATCH" $SPECFILE
a98ed5c
# Add it to git
a98ed5c
git add $PATCH
a98ed5c
BUILDID_PATCH="$(echo $PATCH | sed 's/\-/\_/g' )"
a98ed5c
sed -i "s/^.*define buildid .*$/%define buildid .$BUILDID_PATCH/" $SPECFILE
a98ed5c
popd > /dev/null