diff --git a/debian/changelog b/debian/changelog index c96c41a..b371c5c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,10 @@ dkms (2.1.0.1-1) UNRELEASED; urgency=low * New upstream version + + [ Alberto Milone ] + * dkms_common.postinst: try to build the module for the most recent + kernel in addition to building it for the current kernel (LP: #474917). -- Mario Limonciello Fri, 21 Aug 2009 15:49:58 -0500 diff --git a/dkms_common.postinst b/dkms_common.postinst index 0424b76..e31561b 100644 --- a/dkms_common.postinst +++ b/dkms_common.postinst @@ -6,6 +6,51 @@ set -e +# See if $1 is greater than $2 and print either "yes" or "no" +is_greater_than() { + if [ -e /usr/bin/dpkg ]; then + dpkg --compare-versions "$1" gt "$2" && echo "yes" || echo "no" + else + # TODO: Implement something similar for systems which do not + # rely on dpkg + echo "no" + fi +} + +# Get the most recent kernel. +# +# This keeps into account both the version and the ABI. If the current +# kernel is the most recent kernel then the function will print a null +# string. +get_newest_kernel() { + NEWEST_KERNEL= + NEWEST_VERSION= + NEWEST_ABI= + + for kernel in /boot/config-*; do + KERNEL=${kernel#*-} + KERNEL_VERSION=${KERNEL%%-*} + ABI=${KERNEL#*-} + ABI=${ABI%%-*} + + if [ -z $NEWEST_KERNEL ]; then + # The 1st time get a version which is bigger than $1 + COMPARE_TO=$1 + else + # Get the biggest version + COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI" + fi + + if [ `is_greater_than "$KERNEL_VERSION-$ABI" "$COMPARE_TO"` = "yes" ]; then + NEWEST_KERNEL=$KERNEL + NEWEST_VERSION=$KERNEL_VERSION + NEWEST_ABI=$ABI + fi + done + + echo "$NEWEST_KERNEL" +} + NAME=$1 VERSION=$2 TARBALL_ROOT=$3 @@ -76,6 +121,24 @@ else KERNELS=$CURRENT_KERNEL fi +# Here we look for the most recent kernel so that we can +# build the module for it (in addition to doing it for the +# current kernel. +CURRENT_KERNEL=$KERNELS +CURRENT_VERSION=${CURRENT_KERNEL%%-*} +CURRENT_ABI=${CURRENT_KERNEL#*-} +CURRENT_ABI=${CURRENT_ABI%%-*} + +NEWEST_KERNEL=$(get_newest_kernel "$CURRENT_VERSION-$CURRENT_ABI") + +if [ $NEWEST_KERNEL ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then + echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL" + KERNELS="$KERNELS $NEWEST_KERNEL" +else + echo "Building only for $CURRENT_KERNEL" +fi + + if [ ! -z "$ARCH" ]; then echo "Building for architecture $ARCH" ARCH="-a $ARCH" @@ -116,3 +179,4 @@ for KERNEL in $KERNELS; do dkms install -m $NAME -v $VERSION -k $KERNEL $ARCH fi done +