Script helps add a new patch to the soruce tree. It enables the builid macro and uses the name of the patch as label instead of using rpmdev-bumpspec. Signed-off-by: Miguel Flores Silverio <floresmigu3l@xxxxxxxxx> --- *v1 - Fixed: Fail adding a patch with no description - Fixed: Fail to add a patch outside the tree - Fixed: Fail when adding a patch already in the tree directory - Fixed: Fail to add to git when running script outside tree scripts/newpatch.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/newpatch.sh diff --git a/scripts/newpatch.sh b/scripts/newpatch.sh new file mode 100755 index 0000000..2153fc8 --- /dev/null +++ b/scripts/newpatch.sh @@ -0,0 +1,41 @@ +#! /bin/sh + +# Facilitates the addition of a new patch to the source tree. +# -- Moves patch to tree +# -- Adds patch to kernel.spec list of patches +# -- Adds patch to git +# -- change buildid macro to the name of the patch being added + +# Base directory is relative to where the script is. +BASEDIR="$(dirname "$(cd $(dirname $BASH_SOURCE[0]) && pwd)")" +pushd $BASEDIR > /dev/null +# Check for at least patch +if [ "$#" -lt 1 ]; then + echo "usage: $0 [ /path/to/patch/ ] [ description ]" + exit 1 +fi +PATCHDIR=$1 +DESC=$2 +PATCH="$(basename "$PATCHDIR")" +# Kernel.spec file in the current tree +SPECFILE="$BASEDIR/kernel.spec" +# If adding patch from outside the source tree move it to the source tree +if [ -z "$(ls | grep $PATCH)" ]; then + mv $PATCHDIR $BASEDIR/ +fi + +if [ ! -z "$(grep $PATCH $SPECFILE)" ] +then + echo "$PATCH already in kernel.spec" + exit 1 +fi +# ID number of the last patch in kernel.spec +LPATCH_ID=$(grep ^Patch $SPECFILE | tail -n1 | awk '{ print $1 }' | sed s/Patch// | sed s/://) +# ID of the next patch to be added to kernel.spec +NPATCH_ID=$(($LPATCH_ID + 1 )) +# Add patch with new id at the end of the list of patches +sed -i "/^Patch$LPATCH_ID:\ /a#\ $DESC\nPatch$NPATCH_ID:\ $PATCH" $SPECFILE +# Add it to git +git add $PATCH +sed -i "s/^.*define buildid .*$/%define buildid .$PATCH/" $SPECFILE +popd > /dev/null -- 2.7.4 Some tests I performed: # running script within tree and patch also withing tree, no description - $ ./scripts/newpatch.sh some_patch.patch # running script outside tree and patch outside tree, no description - $ bash ~/kernel/scripts/newpatch.sh ~/Documents/fix_all_the_things.patch # running within tree and patch outside tree, with decription - $ ./scripts/newpatch.sh ~/Documents/fix_all_the_things.patch "It is magic!" _______________________________________________ kernel mailing list kernel@xxxxxxxxxxxxxxxxxxxxxxx https://lists.fedoraproject.org/admin/lists/kernel@xxxxxxxxxxxxxxxxxxxxxxx