2f50aa1
#!/bin/sh
2f50aa1
#
2f50aa1
# Author: Laura Abbott <labbott@fedoraproject.org>
2f50aa1
#
2f50aa1
# Apply a stable patch update to the Fedora tree. This takes care of
2f50aa1
# - Downloading the patch from kernel.org
2f50aa1
# - Uploading the source file
2f50aa1
# - Removing old patch files
2f50aa1
# - Updating the spec file stable version
2f50aa1
# - Adding a proper changelog entry
2f50aa1
#
2f50aa1
# Based on steps from https://fedoraproject.org/wiki/Kernel/DayToDay#Stable_kernel_update
2f50aa1
#
2f50aa1
# Args: Stable version to update (e.g. 4.7.7, 4.8.1)
2f50aa1
2f50aa1
if [ $# -lt 1 ]; then
2f50aa1
	echo "Need a version"
2f50aa1
	exit 1
2f50aa1
fi
2f50aa1
2f50aa1
VERSION=`echo $1 | cut -d . -f 1`
2f50aa1
if [ -z $VERSION ]; then
2f50aa1
	echo "Malformed version $1"
2f50aa1
	exit 1
2f50aa1
fi
2f50aa1
PATCHLEVEL=`echo $1 | cut -d . -f 2`
2f50aa1
if [ -z $VERSION ]; then
2f50aa1
	echo "Malformed version $1"
2f50aa1
	exit 1
2f50aa1
fi
2f50aa1
SUBLEVEL=`echo $1 | cut -d . -f 3`
2f50aa1
if [ -z $VERSION ]; then
2f50aa1
	echo "Malformed version $1"
2f50aa1
	exit 1
2f50aa1
fi
2f50aa1
2f50aa1
if [ ! -f patch-$1.xz ]; then
2f50aa1
	wget https://cdn.kernel.org/pub/linux/kernel/v4.x/patch-$1.xz
2f50aa1
	if [ ! $? -eq 0 ]; then
2f50aa1
		echo "Download fail"
2f50aa1
		exit 1
2f50aa1
	fi
2f50aa1
fi
2f50aa1
192ccb6
if [ ! -f "patch-$1.sign" ]; then
192ccb6
        wget "https://cdn.kernel.org/pub/linux/kernel/v4.x/patch-$1.sign"
192ccb6
        if [ ! $? -eq 0 ]; then
192ccb6
                echo "Signature download failed"
192ccb6
                exit 1
192ccb6
        fi
192ccb6
fi
192ccb6
192ccb6
xzcat "patch-$1.xz" | gpg2 --verify "patch-$1.sign" -
192ccb6
if [ ! $? -eq 0 ]; then
192ccb6
        echo "Patch file has invalid or untrusted signature!"
192ccb6
        echo "See https://www.kernel.org/category/signatures.html"
192ccb6
        exit 1
192ccb6
fi
192ccb6
2f50aa1
grep $1 sources &> /dev/null
2f50aa1
if [ ! $? -eq 0 ]; then
2f50aa1
	fedpkg upload patch-$1.xz
2f50aa1
2f50aa1
	# Cryptic awk: search for the previous patch level (if one exists) and
2f50aa1
	# remove it from the source file
2f50aa1
	awk -v VER=$VERSION.$PATCHLEVEL.$((SUBLEVEL-1)) '$0 !~ VER { print $0; }' < sources > sources.tmp
2f50aa1
	mv sources.tmp sources
2f50aa1
fi
2f50aa1
2f50aa1
# Update the stable level
2f50aa1
awk -v STABLE=$SUBLEVEL '/%define stable_update/ \
2f50aa1
			{ print "%define stable_update " STABLE } \
2f50aa1
			!/%define stable_update/ { print $0 }' \
2f50aa1
			< kernel.spec > kernel.spec.tmp
2f50aa1
mv kernel.spec.tmp kernel.spec
2f50aa1
1b957b6
# Reset the base release for use with rpmdev-bumpspec
1b957b6
BASERELEASE=`cat kernel.spec | grep "%global baserelease" | cut -d ' ' -f 3 | head -c 1`00
1b957b6
BASERELEASE=$(($BASERELEASE-1))
1b957b6
BASERELEASE=$BASERELEASE perl -p -i -e 's|%global baserelease.*|%global baserelease $ENV{'BASERELEASE'}|' kernel.spec
2f50aa1
1b957b6
rpmdev-bumpspec -c "Linux v$1" kernel.spec