9
# Check the existence of a kernel named as $1
10
_is_kernel_name_correct() {
14
for kernel in /boot/config-*; do
16
if [ ${KERNEL} = ${KERNEL_NAME} ]; then
26
# Get the most recent kernel on Debian based systems. This keeps
27
# into account both the version and the ABI. If the current kernel
28
# is the most recent kernel then the function will print a null string.
29
_get_newest_kernel_debian() {
34
for kernel in /boot/config-*; do
36
KERNEL_VERSION=${KERNEL%%-*}
40
if [ -z $NEWEST_KERNEL ]; then
41
# The 1st time get a version which is bigger than $1
44
# Get the biggest version
45
COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
48
# if $kernel is greater than $COMPARE_TO
49
if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
50
echo "no"` = "yes" ]; then
52
NEWEST_VERSION=$KERNEL_VERSION
60
# Get the most recent kernel in Rhel based systems. If the current kernel
61
# is the most recent kernel then the function will print a null string.
62
_get_newest_kernel_rhel() {
65
LAST_INSTALLED_KERNEL=$(rpm -q --whatprovides kernel --last | grep kernel -m1 | cut -f1 -d' ')
67
LIK_FORMATTED_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}\n")
69
if [ `echo $LIK_FORMATTED_NAME | grep 2.6 >/dev/null` ]; then
71
NEWEST_KERNEL=$LIK_FORMATTED_NAME
73
# Hack for Mandriva where $LIK_FORMATTED_NAME is broken
74
LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n")
75
LIK_TYPE=${LIK_NAME#kernel-}
76
LIK_TYPE=${LIK_TYPE%%-*}
77
LIK_STRIPPED=${LIK_NAME#kernel-}
78
LIK_STRIPPED=${LIK_STRIPPED#$LIK_TYPE-}
79
LIK_STRIPPED_BASE=${LIK_STRIPPED%%-*}
80
LIK_STRIPPED_END=${LIK_STRIPPED#$LIK_STRIPPED_BASE-}
81
LIK_FINAL=$LIK_STRIPPED_BASE-$LIK_TYPE-$LIK_STRIPPED_END
83
NEWEST_KERNEL=$LIK_FINAL
89
# Get the newest kernel on Debian and Rhel based systems.
92
# Try Debian first as rpm can be installed in Debian based distros
93
if [ -e /usr/bin/dpkg ]; then
96
CURRENT_VERSION=${CURRENT_KERNEL%%-*}
97
CURRENT_ABI=${CURRENT_KERNEL#*-}
98
CURRENT_FLAVOUR=${CURRENT_ABI#*-}
99
CURRENT_ABI=${CURRENT_ABI%%-*}
100
NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
102
elif [ `which rpm &>/dev/null` ]; then
104
NEWEST_KERNEL=$(_get_newest_kernel_rhel)
107
# Make sure that kernel name that we extracted corresponds to an installed
109
if [ $NEWEST_KERNEL ] && [ `_is_kernel_name_correct $NEWEST_KERNEL` = "no" ]; then
76
183
KERNELS=$CURRENT_KERNEL
79
if [ ! -z "$ARCH" ]; then
186
# Here we look for the most recent kernel so that we can
187
# build the module for it (in addition to doing it for the
189
NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
191
if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
192
echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
193
KERNELS="$KERNELS $NEWEST_KERNEL"
195
echo "Building only for $CURRENT_KERNEL"
199
if [ -n "$ARCH" ]; then
80
200
echo "Building for architecture $ARCH"