~ubuntu-branches/ubuntu/raring/dkms/raring

« back to all changes in this revision

Viewing changes to .pc/666023.patch/dkms_common.postinst

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2012-07-26 11:43:22 UTC
  • mfrom: (2.1.19 sid)
  • Revision ID: package-import@ubuntu.com-20120726114322-vjtfqxvkgd2y4t2a
Tags: 2.2.0.3-1.1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add apport_supported_kernel_packages.diff:
    Only report bugs about supported kernel versions.
  - Add Add-support-for-forcing-modules-installation.patch, backported
    from trunk:
    Add support to force module installation by adding files to
    /usr/share/dkms/modules_to_force_install
  - Add apport_python3.patch: Port apport hook to Python 3 and
    take care of opening the output file in binary mode
  - debian/control: added 'dpkg-dev' and 'debhelper' to Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Copyright (C) 2002-2005 Flavio Stanchina
 
3
# Copyright (C) 2005-2006 Aric Cyr
 
4
# Copyright (C) 2007 Mario Limonciello
 
5
# Copyright (C) 2009 Alberto Milone
 
6
 
 
7
set -e
 
8
 
 
9
uname_s=$(uname -s)
 
10
 
 
11
_get_kernel_dir() {
 
12
    KVER=$1
 
13
    case ${uname_s} in
 
14
        Linux)          DIR="/lib/modules/$KVER/build" ;;
 
15
        GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
 
16
    esac
 
17
    echo $DIR
 
18
}
 
19
 
 
20
_check_kernel_dir() {
 
21
    DIR=$(_get_kernel_dir $1)
 
22
    case ${uname_s} in
 
23
        Linux)          test -e $DIR/include ;;
 
24
        GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
 
25
        *)              return 1 ;;
 
26
    esac
 
27
    return $?
 
28
}
 
29
 
 
30
# Check the existence of a kernel named as $1
 
31
_is_kernel_name_correct() {
 
32
    CORRECT="no"
 
33
    KERNEL_NAME=$1
 
34
 
 
35
    for kernel in /boot/config-*; do
 
36
        KERNEL=${kernel#*-}
 
37
        if [ "${KERNEL}" = "${KERNEL_NAME}" ]; then
 
38
            CORRECT="yes"
 
39
            break
 
40
        fi
 
41
    done
 
42
 
 
43
    echo $CORRECT
 
44
}
 
45
 
 
46
 
 
47
# Get the most recent kernel on Debian based systems. This keeps
 
48
# into account both the version and the ABI. If the current kernel
 
49
# is the most recent kernel then the function will print a null string.
 
50
_get_newest_kernel_debian() {
 
51
    NEWEST_KERNEL=
 
52
    NEWEST_VERSION=
 
53
    NEWEST_ABI=
 
54
 
 
55
    for kernel in /boot/config-*; do
 
56
        KERNEL=${kernel#*-}
 
57
        KERNEL_VERSION=${KERNEL%%-*}
 
58
        ABI=${KERNEL#*-}
 
59
        ABI=${ABI%%-*}
 
60
 
 
61
        if [ -z "$NEWEST_KERNEL" ]; then
 
62
            # The 1st time get a version which is bigger than $1
 
63
            COMPARE_TO=$1
 
64
        else
 
65
            # Get the biggest version
 
66
            COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
 
67
        fi
 
68
 
 
69
        # if $kernel is greater than $COMPARE_TO
 
70
        if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
 
71
              echo "no"` = "yes" ]; then
 
72
            NEWEST_KERNEL=$KERNEL
 
73
            NEWEST_VERSION=$KERNEL_VERSION
 
74
            NEWEST_ABI=$ABI
 
75
        fi
 
76
    done
 
77
 
 
78
    echo "$NEWEST_KERNEL"
 
79
}
 
80
 
 
81
# Get the most recent kernel in Rhel based systems. If the current kernel
 
82
# is the most recent kernel then the function will print a null string.
 
83
_get_newest_kernel_rhel() {
 
84
    NEWEST_KERNEL=
 
85
 
 
86
    LAST_INSTALLED_KERNEL=$(rpm -q --whatprovides kernel  --last | grep kernel -m1 | cut -f1 -d' ')
 
87
 
 
88
    LIK_FORMATTED_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}\n")
 
89
 
 
90
    if [ `echo $LIK_FORMATTED_NAME | grep 2.6 >/dev/null` ]; then
 
91
        # Fedora and Suse
 
92
        NEWEST_KERNEL=$LIK_FORMATTED_NAME
 
93
    else
 
94
        # Hack for Mandriva where $LIK_FORMATTED_NAME is broken
 
95
        LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n")
 
96
        LIK_TYPE=${LIK_NAME#kernel-}
 
97
        LIK_TYPE=${LIK_TYPE%%-*}
 
98
        LIK_STRIPPED=${LIK_NAME#kernel-}
 
99
        LIK_STRIPPED=${LIK_STRIPPED#$LIK_TYPE-}
 
100
        LIK_STRIPPED_BASE=${LIK_STRIPPED%%-*}
 
101
        LIK_STRIPPED_END=${LIK_STRIPPED#$LIK_STRIPPED_BASE-}
 
102
        LIK_FINAL=$LIK_STRIPPED_BASE-$LIK_TYPE-$LIK_STRIPPED_END
 
103
 
 
104
        NEWEST_KERNEL=$LIK_FINAL
 
105
    fi
 
106
 
 
107
    echo $NEWEST_KERNEL
 
108
}
 
109
 
 
110
# Get the newest kernel on Debian and Rhel based systems.
 
111
get_newest_kernel() {
 
112
    NEWEST_KERNEL=
 
113
    # Try Debian first as rpm can be installed in Debian based distros
 
114
    if [ -e /usr/bin/dpkg ]; then
 
115
        # If DEB based
 
116
        CURRENT_KERNEL=$1
 
117
        CURRENT_VERSION=${CURRENT_KERNEL%%-*}
 
118
        CURRENT_ABI=${CURRENT_KERNEL#*-}
 
119
        CURRENT_FLAVOUR=${CURRENT_ABI#*-}
 
120
        CURRENT_ABI=${CURRENT_ABI%%-*}
 
121
        NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
 
122
 
 
123
    elif [ `which rpm >/dev/null` ]; then
 
124
        # If RPM based
 
125
        NEWEST_KERNEL=$(_get_newest_kernel_rhel)
 
126
    fi
 
127
 
 
128
    # Make sure that kernel name that we extracted corresponds to an installed
 
129
    # kernel
 
130
    if [ -n "$NEWEST_KERNEL" ] && [ `_is_kernel_name_correct $NEWEST_KERNEL` = "no" ]; then
 
131
        NEWEST_KERNEL=
 
132
    fi
 
133
 
 
134
    echo $NEWEST_KERNEL
 
135
}
 
136
 
 
137
NAME=$1
 
138
VERSION=$2
 
139
TARBALL_ROOT=$3
 
140
ARCH=$4
 
141
UPGRADE=$5
 
142
 
 
143
if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
 
144
    echo "Need NAME, and VERSION defined"
 
145
    echo "ARCH is optional"
 
146
    exit 1
 
147
fi
 
148
 
 
149
KERNELS=$(ls /lib/modules/)
 
150
CURRENT_KERNEL=$(uname -r)
 
151
 
 
152
#We never want to keep an older version side by side to prevent conflicts
 
153
if [ -e "/var/lib/dkms/$NAME/$VERSION" ]; then
 
154
    echo "Removing old $NAME-$VERSION DKMS files..."
 
155
    dkms remove -m $NAME -v $VERSION --all
 
156
fi
 
157
 
 
158
#Load new files, by source package and by tarball
 
159
if [ -f "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz" ]; then
 
160
    if ! dkms ldtarball --archive "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz"; then
 
161
        echo ""
 
162
        echo ""
 
163
        echo "Unable to load DKMS tarball $TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz."
 
164
        echo "Common causes include: "
 
165
        echo " - You must be using DKMS 2.1.0.0 or later to support binaries only"
 
166
        echo "   distribution specific archives."
 
167
        echo " - Corrupt distribution specific archive"
 
168
        echo ""
 
169
        echo ""
 
170
        exit 2
 
171
    fi
 
172
elif [ -d "/usr/src/$NAME-$VERSION" ]; then
 
173
    echo "Loading new $NAME-$VERSION DKMS files..."
 
174
    dkms add -m $NAME -v $VERSION > /dev/null
 
175
fi
 
176
 
 
177
# On 1st installation, let us look for a directory
 
178
# in /lib/modules which matches `uname -r`. If none
 
179
# is found it is possible that buildd is being used
 
180
# and that uname -r is giving us the name of the
 
181
# kernel used by the buildd machine.
 
182
#
 
183
# If this is the case we try to build the kernel
 
184
# module for each kernel which has a directory in
 
185
# /lib/modules. Furthermore we will have to tell
 
186
# DKMS which architecture it should build the module
 
187
# for (e.g. if the buildd machine is using a
 
188
# 2.6.24-23-xen 64bit kernel).
 
189
#
 
190
# NOTE: if the headers are not installed then the
 
191
#       module won't be built, as usual
 
192
if [ -z "$UPGRADE" ]; then
 
193
    echo "First Installation: checking all kernels..."
 
194
    for KERNEL in $KERNELS; do
 
195
        if [ ${KERNEL} = ${CURRENT_KERNEL} ]; then
 
196
            # Kernel found
 
197
            KERNELS=$CURRENT_KERNEL
 
198
            break
 
199
        fi
 
200
    done
 
201
else
 
202
    KERNELS=$CURRENT_KERNEL
 
203
fi
 
204
 
 
205
# Here we look for the most recent kernel so that we can
 
206
# build the module for it (in addition to doing it for the
 
207
# current kernel.
 
208
NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
 
209
 
 
210
# If the current kernel doesn't come from the host of a chroot
 
211
if [ `_is_kernel_name_correct $CURRENT_KERNEL` = "yes" ]; then
 
212
    # See if it's worth building the module for both the newest kernel
 
213
    # and for the current kernel
 
214
    if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
 
215
        echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
 
216
        KERNELS="$CURRENT_KERNEL $NEWEST_KERNEL"
 
217
    else
 
218
        echo "Building only for $CURRENT_KERNEL"
 
219
    fi
 
220
# The current kernel is not useful as it's the host's
 
221
else
 
222
    echo "It is likely that $CURRENT_KERNEL belongs to a chroot's host"
 
223
 
 
224
    # Let's use only the newest kernel
 
225
    if [ -n "$NEWEST_KERNEL" ]; then
 
226
        KERNELS="$NEWEST_KERNEL"
 
227
        echo "Building only for $NEWEST_KERNEL"
 
228
    fi
 
229
fi
 
230
 
 
231
if [ -n "$ARCH" ]; then
 
232
    if which lsb_release >/dev/null && [ $(lsb_release -s -i) = "Ubuntu" ]; then
 
233
        case $ARCH in
 
234
            amd64)
 
235
                ARCH="x86_64"
 
236
                ;;
 
237
            lpia|i?86)
 
238
                ARCH="i686"
 
239
                ;;
 
240
        esac
 
241
    fi
 
242
    echo "Building for architecture $ARCH"
 
243
    ARCH="-a $ARCH"
 
244
fi
 
245
 
 
246
for KERNEL in $KERNELS; do
 
247
    dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
 
248
    if [ `echo $KERNEL | grep -c "BOOT"` -gt 0 ]; then
 
249
        echo ""
 
250
        echo "Module build and install for $KERNEL was skipped as "
 
251
        echo "it is a BOOT variant"
 
252
        continue
 
253
    fi
 
254
 
 
255
 
 
256
    #if the module isn't yet built, try to build it
 
257
    if [ `echo $dkms_status | grep -c ": built"` -eq 0 ]; then
 
258
        if [ ! -L /var/lib/dkms/$NAME/$VERSION/source ]; then
 
259
            echo "This package appears to be a binaries-only package"
 
260
            echo " you will not be able to build against kernel $KERNEL"
 
261
            echo " since the package source was not provided"
 
262
            continue
 
263
        fi
 
264
        if _check_kernel_dir $KERNEL; then
 
265
            echo "Building initial module for $KERNEL"
 
266
            set +e
 
267
            dkms build -m $NAME -v $VERSION -k $KERNEL $ARCH > /dev/null
 
268
            case $? in
 
269
            9)
 
270
                set -e
 
271
                echo "Skipped."
 
272
                continue
 
273
                ;;
 
274
            0)
 
275
                set -e
 
276
                echo "Done."
 
277
                ;;
 
278
            *)
 
279
                exit $?
 
280
                ;;
 
281
            esac
 
282
            dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
 
283
        else
 
284
            echo "Module build for the currently running kernel was skipped since the"
 
285
            echo "kernel source for this kernel does not seem to be installed."
 
286
        fi
 
287
    fi
 
288
 
 
289
    #if the module is built (either pre-built or just now), install it
 
290
    if [ `echo $dkms_status | grep -c ": built"` -eq 1 ] && 
 
291
       [ `echo $dkms_status | grep -c ": installed"` -eq 0 ]; then
 
292
        dkms install -m $NAME -v $VERSION -k $KERNEL $ARCH
 
293
    fi
 
294
done
 
295