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

« back to all changes in this revision

Viewing changes to .pc/use-system-tmpdir.patch/dkms

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano, Michael Gilbert, Giuseppe Iuculano
  • Date: 2010-06-04 13:53:23 UTC
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20100604135323-gq71k8zml0ateckx
Tags: 2.1.1.2-3
[ Michael Gilbert ]
* Update to source format 3 (quilt) for better patch management/handling.
* Improve the status info displayed during the kernel postinst, and
  provide informative/useful messages when things go awry.
* Fix bashism in dkms_common.postinst (closes: #581079).
* Document odd behavior of MAKE[#] (closes: #553625).
* Document package naming convention (closes: #571753).
* Use system TMPDIR setting in all scripts (closes: #581568).

[ Giuseppe Iuculano ]
* [208b229] Added a lintian override for python-script-but-no-python-
  dep, dkms.py is an apport hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
#  Dynamic Kernel Module Support (DKMS) <dkms-devel@dell.com>
 
4
#  Copyright (C) 2003-2008 Dell, Inc.
 
5
#  by Gary Lerhaupt, Matt Domsch, & Mario Limonciello
 
6
#
 
7
#    This program is free software; you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License as published by
 
9
#    the Free Software Foundation; either version 2 of the License, or
 
10
#    (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU General Public License
 
18
#    along with this program; if not, write to the Free Software
 
19
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
#
 
21
 
 
22
function invoke_command ()
 
23
{
 
24
    local exitval=0
 
25
    local exitval_file=`mktemp $tmp_location/dkms.XXXXXX`
 
26
    [ -z "$verbose" ] && echo -en "$2..." || echo -e "$1"
 
27
    if [ "$3" == background ] && [ -z "$verbose" ]; then
 
28
        (eval $1 >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
 
29
        while [ -e "$exitval_file" ] && ! [ -s "$exitval_file" ]; do
 
30
            sleep 3
 
31
            echo -en "."
 
32
        done
 
33
        . "$exitval_file"
 
34
    else
 
35
        eval $1; exitval=$?
 
36
    fi
 
37
    [ $exitval -gt 0 ] && echo -en "(bad exit status: $exitval)"
 
38
    rm -f "$exitval_file"
 
39
    echo -en "\n"
 
40
    return $exitval
 
41
}
 
42
 
 
43
function show_usage ()
 
44
{
 
45
    echo $"Usage: $0 [action] [options]"
 
46
    echo $"  [action]  = { add | remove | build | install | uninstall | match"
 
47
    echo $"               | mkdriverdisk | mktarball | ldtarball | mkrpm | mkkmp | mkdeb | status }"
 
48
    echo $"  [options] = [-m module] [-v module-version] [-k kernel-version] [-a arch]"
 
49
    echo $"              [-d distro] [-c dkms.conf-location] [-q] [--force] [--all]"
 
50
    echo $"              [--templatekernel=kernel] [--directive='cli-directive=cli-value']"
 
51
    echo $"              [--config=kernel-.config-location] [--archive=tarball-location]"
 
52
    echo $"              [--kernelsourcedir=source-location] [--no-prepare-kernel]"
 
53
    echo $"              [--binaries-only] [--source-only] [-r release (SuSE)] [--verbose]"
 
54
    echo $"              [--size] [--spec=specfile] [--media=floppy|iso|tar] [--legacy-postinst=0|1]"
 
55
}
 
56
 
 
57
function readlink()
 
58
{
 
59
    # $1 = the symlink to read
 
60
    read_link=""
 
61
    if [ -L "$1" ]; then
 
62
        read_link="$1"
 
63
        while [ -L "$read_link" ]; do
 
64
            read_link=`ls -l $read_link | sed 's/.*-> //'`
 
65
        done
 
66
    fi
 
67
}
 
68
 
 
69
function VER()
 
70
{
 
71
    # $1 = kernel version string
 
72
 
 
73
    # Pad all numbers in $1 so that they have at least three digits, e.g.,
 
74
    #   2.6.9-1cvs200409091247 => 002.006.009-001cvs200409091247
 
75
    # The result should compare correctly as a string.
 
76
 
 
77
    echo $1 | sed -e 's:\([^0-9]\)\([0-9]\):\1 \2:g' \
 
78
                  -e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
 
79
                  -e 's:\(.*\): \1 :' \
 
80
                  -e 's: \([0-9]\) : 00\1 :g' \
 
81
                  -e 's: \([0-9][0-9]\) : 0\1 :g' \
 
82
                  -e 's: ::g'
 
83
}
 
84
 
 
85
function set_module_suffix ()
 
86
{
 
87
    # $1 = the kernel to base the module_suffix on
 
88
    kernel_test="$1"
 
89
    [ -z "$kernel_test" ] && kernel_test=`uname -r`
 
90
 
 
91
    if [[ $(VER $kernel_test) < $(VER 2.5) ]]; then
 
92
        module_suffix=".o"
 
93
    else
 
94
        module_suffix=".ko"
 
95
    fi
 
96
}
 
97
 
 
98
function set_kernel_source_dir ()
 
99
{
 
100
    # $1 = the kernel to base the directory on
 
101
    if [ -z "$kernel_source_dir" ] && [ -d "$install_tree/$1/build" ]; then
 
102
        kernel_source_dir="$install_tree/$1/build"
 
103
    fi
 
104
}
 
105
 
 
106
function setup_kernels_arches ()
 
107
{
 
108
    # Error if # of arches doesn't match # of kernels
 
109
    if [ ${#kernelver_array[@]} -ne ${#arch_array[@]} ] && [ ${#arch_array[@]} -gt 1 ]; then
 
110
        echo $"" >&2
 
111
        echo $"Error!  If more than one arch is specified on the command line, then there" >&2
 
112
        echo $"must be an equal number of kernel versions also specified (1:1 relationship)." >&2
 
113
        exit 1
 
114
    fi
 
115
 
 
116
    # Check that kernel version and all aren't both set simultaneously
 
117
    if [ -n "${kernelver_array[0]}" ] && [ -n "$all" ]; then
 
118
        echo $"" >&2
 
119
        echo $"Error!  You cannot specify a kernel version and also specify" >&2
 
120
        echo $"--all on the command line." >&2
 
121
        exit 2
 
122
    fi
 
123
 
 
124
    # Check that arch and all aren't both set simultaneously
 
125
    if [ -n "${arch_array[0]}" ] && [ -n "$all" ]; then
 
126
        echo $"" >&2
 
127
        echo $"Error!  You cannot specify an arch and also specify" >&2
 
128
        echo $"--all on the command line." >&2
 
129
        exit 3
 
130
    fi
 
131
 
 
132
    # Check that the actions supports multiple kernels
 
133
    case "$1" in
 
134
    add | build | install | match | uninstall | mkkmp )
 
135
        if [ ${#kernelver_array[@]} -gt 1 ]; then
 
136
            echo $"" >&2
 
137
            echo $"Error! The action $1 does not support multiple kernel version" >&2
 
138
            echo $"parameters on the command line." >&2
 
139
            exit 4
 
140
        fi
 
141
        if [ -n "$all" ]; then
 
142
            echo $"" >&2
 
143
            echo $"Error! The action $1 does not support the --all" >&2
 
144
            echo $"parameter." >&2
 
145
            exit 5
 
146
        fi
 
147
        ;;
 
148
    esac
 
149
 
 
150
    # If all is set, use dkms status to fill the arrays
 
151
    if [ -n "$all" ] && [ "$1" != "status" ]; then
 
152
        local i=0
 
153
        while read line; do
 
154
            # (I would leave out the delimiters in the status output
 
155
            #  in the first place.)
 
156
            kernelver_array[$i]=`echo $line | awk {'print $3'} | sed 's/,$//'`
 
157
            arch_array[$i]=`echo $line | awk {'print $4'} | sed 's/:$//'`
 
158
            i=$(($i + 1))
 
159
        done < <($0 status -m "$module" -v "$module_version" 2>/dev/null | \
 
160
            egrep "built|installed" | egrep -v 'installed-weak')
 
161
    fi
 
162
 
 
163
    # Set default kernel version and arch, if none set (but only --all isn't set)
 
164
    if [ "$1" != "status" ]; then
 
165
        [ -z "${kernelver_array[0]}" ] && [ -z "$all" ] && kernelver_array[0]=`uname -r`
 
166
        if [ -z "${arch_array[0]}" ] && [ -n "${kernelver_array[0]}" ]; then
 
167
            kernelver_rpm=`rpm -qf "/lib/modules/${kernelver_array[0]}" 2>/dev/null | grep -v "not owned by any package" | grep kernel | head -n 1`
 
168
            if ! arch_array[0]=`rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null`; then
 
169
                arch_array[0]=`uname -m`
 
170
                if [ ${arch_array[0]} == "x86_64" ] && \
 
171
                    grep -q Intel /proc/cpuinfo && \
 
172
                    ls $install_tree/${kernelver_array[0]}/build/configs \
 
173
                    2>/dev/null | grep -q "ia32e"; then
 
174
                    arch_array[0]="ia32e"
 
175
                fi
 
176
            fi
 
177
        fi
 
178
    fi
 
179
 
 
180
    # If only one arch is specified, make it so for all the kernels
 
181
    if [ ${#arch_array[@]} -eq 1 ] && [ ${#kernelver_array[@]} -gt 1 ]; then
 
182
        while [ ${#arch_array[@]} -lt ${#kernelver_array[@]} ]; do
 
183
            arch_array[${#arch_array[@]}]=${arch_array[0]}
 
184
        done
 
185
    fi
 
186
 
 
187
    # Set global multi_arch
 
188
    multi_arch=""
 
189
    local i=0
 
190
    while [ $i -lt ${#arch_array[@]} ]; do
 
191
        [ "${arch_array[0]}" != "${arch_array[$i]}" ] && multi_arch="true"
 
192
        i=$(($i + 1))
 
193
    done
 
194
}
 
195
 
 
196
function do_depmod()
 
197
{
 
198
    # $1 = kernel version
 
199
    /sbin/depmod -au "$1" -F "/boot/System.map-$1"
 
200
}
 
201
 
 
202
function remake_initrd()
 
203
{
 
204
    # $1 = kernel version
 
205
    # $2 = arch
 
206
 
 
207
    local exitval="0"
 
208
    local mkinitrd='mkinitrd'
 
209
 
 
210
 
 
211
    # Support initramfs distributions (Debian/Ubuntu).
 
212
    if [ -x "/usr/sbin/update-initramfs" ]; then
 
213
        mkinitrd='update-initramfs'
 
214
    fi
 
215
 
 
216
    $mkinitrd --version >/dev/null 2>&1
 
217
    if [ "$?" -eq 0 ]; then
 
218
        echo $""
 
219
        initrd_dir="/boot"
 
220
        [ "$2" == "ia64" ] && [ -d "/boot/efi/efi/redhat" ] && initrd_dir="/boot/efi/efi/redhat"
 
221
        echo $"Saving old initrd as $initrd_dir/initrd-$1_old.img"
 
222
        cp -f "$initrd_dir/initrd-$1.img" "$initrd_dir/initrd-$1_old.img"
 
223
        echo $"Making new initrd as $initrd_dir/initrd-$1.img"
 
224
        echo $"(If next boot fails, revert to the _old initrd image)"
 
225
        invoke_command "$mkinitrd -f $initrd_dir/initrd-$1.img $1" "$mkinitrd" background
 
226
        exitval="$?"
 
227
    elif [ -e /etc/SuSE-release ] || [ -d /etc/SuSEconfig ]; then
 
228
        echo $""
 
229
        initrd_dir="/boot"
 
230
        kernel_file="vmlinuz"
 
231
        if [ ! -f "$initrd_dir/$kernel_file-$1" ]; then
 
232
            kernel_file="vmlinux"
 
233
            if [ ! -f "$initrd_dir/$kernel_file-$1" ]; then
 
234
                echo $"Error! Unable to find valid kernel file under " >&2
 
235
                echo $"$initrd_dir for kernel version $1" >&2
 
236
                echo $"" >&2
 
237
                return 1;
 
238
            fi
 
239
        fi
 
240
        echo $"Saving old initrd as $initrd_dir/initrd-$1_old"
 
241
        cp -f "$initrd_dir/initrd-$1" "$initrd_dir/initrd-$1_old"
 
242
        echo $"Making new initrd as $initrd_dir/initrd-$1"
 
243
        echo $"(If next boot fails, revert to the _old initrd image)"
 
244
        invoke_command "$mkinitrd -k $kernel_file-$1 -i initrd-$1" "$mkinitrd" background
 
245
        exitval="$?"
 
246
    elif [ -e /etc/debian_version ]; then
 
247
        echo $""
 
248
        initrd_dir="/boot"
 
249
        echo $"Updating initrd"
 
250
        echo $"Making new initrd as $initrd_dir/initrd.img-$1"
 
251
        echo $"(If next boot fails, revert to the .bak initrd image)"
 
252
        if [ "$mkinitrd" == "update-initramfs" ]; then
 
253
            invoke_command "$mkinitrd -u" "$mkinitrd" background
 
254
        else
 
255
            echo $"Saving old initrd as $initrd_dir/initrd.img-$1.bak"
 
256
            # we use the same convention as update-initramfs, so that we just
 
257
            # print the warning once
 
258
            cp -f "$initrd_dir/initrd.img-$1" "$initrd_dir/initrd.img-$1.bak"
 
259
            invoke_command "$mkinitrd -o $initrd_dir/initrd.img-$1 $1" "$mkinitrd" background
 
260
        fi
 
261
        exitval="$?"
 
262
    else
 
263
        echo $""
 
264
        echo $"Calling $mkinitrd (bad exit status 9 may occur)"
 
265
        invoke_command "$mkinitrd" "$mkinitrd" background
 
266
        exitval="$?"
 
267
    fi
 
268
 
 
269
    return $exitval
 
270
}
 
271
 
 
272
function distro_version_rpm()
 
273
{
 
274
    local whatprovides_redhat
 
275
    local whatprovides_suse
 
276
    local whatprovides_sles
 
277
    local whatprovides_ovm
 
278
    local DISTRO
 
279
    local VER
 
280
    local dist=unknown
 
281
 
 
282
    if ! which rpm > /dev/null 2>&1 ; then
 
283
        echo "${dist}"
 
284
        return
 
285
    fi
 
286
 
 
287
    whatprovides_redhat=$(rpm -q --whatprovides redhat-release)
 
288
    if [ $? -eq 0 ]; then
 
289
        case "${whatprovides_redhat}" in
 
290
        redhat*)     DISTRO=redhat ;;
 
291
        centos*)     DISTRO=centos ;;
 
292
        enterprise*) DISTRO=oel ;; # Oracle Enterprise Linux
 
293
        sl*)         DISTRO=sl ;;  # Scientific Linux
 
294
        fedora*)     DISTRO=fedora ;;
 
295
        *) ;;
 
296
        esac
 
297
    fi
 
298
    whatprovides_sles=$(rpm -q --whatprovides sles-release)
 
299
    [ $? -eq 0 ] && DISTRO=sles
 
300
    whatprovides_suse=$(rpm -q --whatprovides suse-release)
 
301
    [ $? -eq 0 ] && DISTRO=suse
 
302
    whatprovides_ovm=$(rpm -q --whatprovides ovs-release)
 
303
    [ $? -eq 0 ] && DISTRO=ovm
 
304
 
 
305
    case "${DISTRO}" in
 
306
    redhat)
 
307
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
 
308
        # format is 3AS, 4AS, 5Desktop...
 
309
        VER=$(echo "${VER}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
 
310
        dist=el${VER}
 
311
        ;;
 
312
    centos)
 
313
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
 
314
        # format is 3, 4, ...
 
315
        dist=el${VER}
 
316
        ;;
 
317
    oel)
 
318
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
 
319
        # format is 3, 4, ...
 
320
        dist=el${VER}
 
321
        ;;
 
322
    ovm)
 
323
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_ovm})
 
324
        # format is 2.1
 
325
        dist=ovm${VER}
 
326
        ;;
 
327
    sl)
 
328
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
 
329
        # format is 4.7, 5.3
 
330
        VER=$(echo "${VER}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
 
331
        dist=el${VER}
 
332
        ;;
 
333
    fedora)
 
334
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
 
335
        dist=fc${VER}
 
336
        ;;
 
337
    sles)
 
338
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_sles})
 
339
        dist=sles${VER}
 
340
        ;;
 
341
    suse)
 
342
        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_suse})
 
343
        dist=suse${VER}
 
344
        ;;
 
345
    *)
 
346
        dist=unknown
 
347
        ;;
 
348
    esac
 
349
    echo "$dist"
 
350
}
 
351
 
 
352
function distro_version()
 
353
{
 
354
# What distribution are we running?
 
355
    local LSB_RELEASE
 
356
    local LSB_DESCRIPTION
 
357
    local DISTRIB_ID
 
358
    local DISTRIB_RELEASE
 
359
    local VER
 
360
    local dist=unknown
 
361
 
 
362
# try the LSB-provided strings first
 
363
    if [ -r /etc/lsb-release ]; then
 
364
        . /etc/lsb-release
 
365
        LSB_RELEASE=1
 
366
    elif type lsb_release >/dev/null 2>&1; then
 
367
        DISTRIB_ID=$(lsb_release -i -s)
 
368
        DISTRIB_RELEASE=$(lsb_release -r -s)
 
369
        LSB_RELEASE=1
 
370
    fi
 
371
 
 
372
    case "${DISTRIB_ID}" in
 
373
    Fedora)     dist=fc${DISTRIB_RELEASE} ;;
 
374
    RedHatEnterprise*)  # OEL also reports as such
 
375
        # format is 4.7, 5.3
 
376
        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
 
377
        dist=el${VER}
 
378
        ;;
 
379
    CentOS)
 
380
        # format is 4.7, 5.3
 
381
        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
 
382
        dist=el${VER}
 
383
        ;;
 
384
    ScientificSL)
 
385
        # format is 4.7, 5.3
 
386
        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
 
387
        dist=el${VER}
 
388
        ;;
 
389
    SUSE*)
 
390
        LSB_DESCRIPTION="$(lsb_release -d -s)"
 
391
        if echo "${LSB_DESCRIPTION}" | grep Enterprise > /dev/null 2>&1; then
 
392
            dist=sles${DISTRIB_RELEASE}
 
393
        else
 
394
            dist=suse${DISTRIB_RELEASE}
 
395
        fi
 
396
        ;;
 
397
    *)
 
398
        if [ -n "${LSB_RELEASE}" -a -n "${DISTRIB_ID}" -a -n "${DISTRIB_RELEASE}" ]; then
 
399
            dist="${DISTRIB_ID}${DISTRIB_RELEASE}"
 
400
        fi
 
401
        ;;
 
402
    esac
 
403
 
 
404
    if [ "${dist}" == "unknown" ]; then
 
405
        dist=$(distro_version_rpm)
 
406
    fi
 
407
    echo "$dist"
 
408
}
 
409
 
 
410
function override_dest_module_location()
 
411
{
 
412
    local orig_location="$1"
 
413
    [ -n "${addon_modules_dir}" ] && echo "/${addon_modules_dir}" && return
 
414
 
 
415
    case "$running_distribution" in
 
416
    fc[12345]) ;;
 
417
    el[1234]) ;;
 
418
    sles[123456789]) ;;
 
419
    suse[123456789]) ;;
 
420
    suse10\.[01]) ;;
 
421
    fc*) echo "/extra" && return ;;
 
422
    el*) echo "/extra" && return ;;
 
423
    ovm*) echo "/extra" && return ;;
 
424
    sles*) echo "/updates" && return ;;
 
425
    suse*) echo "/updates" && return ;;
 
426
    Ubuntu*) echo "/updates/dkms" && return ;;
 
427
    Debian*) echo "/updates/dkms" && return ;;
 
428
    *) ;;
 
429
    esac
 
430
    echo "$orig_location"
 
431
}
 
432
 
 
433
function read_conf ()
 
434
{
 
435
    # $1 kernel version (required)
 
436
    # $2 arch (required)
 
437
    # $3 dkms.conf location (optional)
 
438
 
 
439
    local return_value=0
 
440
    local read_conf_file
 
441
 
 
442
    # Find which conf file to check
 
443
    if [ -n "$3" ]; then
 
444
        read_conf_file="$3"
 
445
    elif [ -n "$conf" ]; then
 
446
        read_conf_file="$conf"
 
447
    else
 
448
        read_conf_file="$dkms_tree/$module/$module_version/source/dkms.conf"
 
449
    fi
 
450
 
 
451
    # Clear variables
 
452
    MAKE=""
 
453
    CLEAN=""
 
454
    REMAKE_INITRD=""
 
455
    remake_initrd=""
 
456
    PACKAGE_NAME=""
 
457
    PACKAGE_VERSION=""
 
458
    POST_ADD=""
 
459
    POST_BUILD=""
 
460
    POST_INSTALL=""
 
461
    POST_REMOVE=""
 
462
    PRE_BUILD=""
 
463
    PRE_INSTALL=""
 
464
    BUILD_EXCLUSIVE_KERNEL=""
 
465
    BUILD_EXCLUSIVE_ARCH=""
 
466
    build_exclude=""
 
467
    OBSOLETE_BY=""
 
468
 
 
469
    # Clear arrays
 
470
    unset MAKE
 
471
    unset MAKE_MATCH
 
472
    unset MODULES_CONF
 
473
    unset modules_conf_array
 
474
    unset PATCH
 
475
    unset PATCH_MATCH
 
476
    unset patch_array
 
477
    unset BUILT_MODULE_NAME
 
478
    unset built_module_name
 
479
    unset BUILT_MODULE_LOCATION
 
480
    unset built_module_location
 
481
    unset DEST_MODULE_NAME
 
482
    unset dest_module_name
 
483
    unset DEST_MODULE_LOCATION
 
484
    unset dest_module_location
 
485
    unset MODULES_CONF_OBSOLETES
 
486
    unset modules_conf_obsoletes
 
487
    unset MODULES_CONF_ALIAS_TYPE
 
488
    unset modules_conf_alias_type
 
489
    unset MODULES_CONF_OBSOLETE_ONLY
 
490
    unset modules_conf_obsolete_only
 
491
    unset STRIP
 
492
    unset strip
 
493
 
 
494
    # Set variables supported in dkms.conf files (eg. $kernelver)
 
495
    kernelver="$1"
 
496
    arch="$2"
 
497
    set_kernel_source_dir "$1"
 
498
 
 
499
    # Source in the dkms.conf
 
500
    . $read_conf_file 2>/dev/null
 
501
 
 
502
    # check environment for directives
 
503
    # You can't have an array of variables exported
 
504
    # so look for DKMS_DIRECTIVE0, DKMS_DIRECTIVE1, ...
 
505
    for directive in `set | grep ^DKMS_DIRECTIVE | cut -d = -f 2-3`; do
 
506
        directive_name=${directive%%=*}
 
507
        directive_value=${directive#*=}
 
508
        export $directive_name="$directive_value"
 
509
        echo $"DIRECTIVE: $directive_name=\"$directive_value\""
 
510
    done
 
511
 
 
512
    # Source in the directive_array
 
513
    for directive in "${directive_array[@]}"; do
 
514
        directive_name=${directive%%=*}
 
515
        directive_value=${directive#*=}
 
516
        export $directive_name="$directive_value"
 
517
        echo $"DIRECTIVE: $directive_name=\"$directive_value\""
 
518
    done
 
519
 
 
520
    # Set variables
 
521
    clean="$CLEAN"
 
522
    package_name="$PACKAGE_NAME"
 
523
    package_version="$PACKAGE_VERSION"
 
524
    post_add="$POST_ADD"
 
525
    post_build="$POST_BUILD"
 
526
    post_install="$POST_INSTALL"
 
527
    post_remove="$POST_REMOVE"
 
528
    pre_build="$PRE_BUILD"
 
529
    pre_install="$PRE_INSTALL"
 
530
    obsolete_by="$OBSOLETE_BY"
 
531
 
 
532
    # Set module naming/location arrays
 
533
    local index=0
 
534
    array_size=`echo -e "${#BUILT_MODULE_NAME[@]}\n${#BUILT_MODULE_LOCATION[@]}\n${#DEST_MODULE_NAME[@]}\n${#DEST_MODULE_LOCATION[@]}\n" | sort -n | tail -n 1`
 
535
    while [ "$index" -lt "$array_size" ]; do
 
536
        # Set values
 
537
        built_module_name[$index]=${BUILT_MODULE_NAME[$index]}
 
538
        built_module_location[$index]=${BUILT_MODULE_LOCATION[$index]}
 
539
        dest_module_name[$index]=${DEST_MODULE_NAME[$index]}
 
540
        dest_module_location[$index]=${DEST_MODULE_LOCATION[$index]}
 
541
        modules_conf_obsoletes[$index]=${MODULES_CONF_OBSOLETES[$index]}
 
542
        modules_conf_alias_type[$index]=${MODULES_CONF_ALIAS_TYPE[$index]}
 
543
        case "${MODULES_CONF_OBSOLETE_ONLY[$index]}" in
 
544
        [yY]*)
 
545
            modules_conf_obsolete_only[$index]="yes"
 
546
            ;;
 
547
        esac
 
548
        case "${STRIP[$index]}" in
 
549
        [nN]*)
 
550
            strip[$index]="no"
 
551
            ;;
 
552
        *)
 
553
            strip[$index]="yes"
 
554
            ;;
 
555
        esac
 
556
 
 
557
        # If unset, set by defaults
 
558
        [ -z "${built_module_name[$index]}" ] && [ ${#DEST_MODULE_LOCATION[@]} -eq 1 ] && built_module_name[$index]=$module
 
559
        [ -z "${dest_module_name[$index]}" ] && dest_module_name[$index]=${built_module_name[$index]}
 
560
        if [ -n "${built_module_location[$index]}" ] && \
 
561
           [ "${built_module_location[$index]:(-1)}" != "/" ]; then
 
562
            built_module_location[$index]="${built_module_location[$index]}/"
 
563
        fi
 
564
 
 
565
        # FAIL if no built_module_name
 
566
        if [ -z "${built_module_name[$index]}" ]; then
 
567
            echo $"dkms.conf: Error! No 'BUILT_MODULE_NAME' directive specified for record #$index." >&2
 
568
            return_value=1
 
569
        fi
 
570
 
 
571
        # FAIL if built_module_name ends in .o or .ko
 
572
        case "${built_module_name[$index]}" in
 
573
        *.o | *.ko)
 
574
            echo $"dkms.conf: Error! 'BUILT_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
 
575
            return_value=1
 
576
            ;;
 
577
        esac
 
578
 
 
579
        # FAIL if dest_module_name ends in .o or .ko
 
580
        case "${dest_module_name[$index]}" in
 
581
        *.o | *.ko)
 
582
            echo $"dkms.conf: Error! 'DEST_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
 
583
            return_value=1
 
584
            ;;
 
585
        esac
 
586
 
 
587
        # Override location for specific kernels
 
588
        dest_module_location[$index]="$(override_dest_module_location ${dest_module_location[$index]})"
 
589
 
 
590
        # Fail if no DEST_MODULE_LOCATION
 
591
        if [ -z "${DEST_MODULE_LOCATION[$index]}" ]; then
 
592
            echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified for record #$index.">&2
 
593
            return_value=1
 
594
        fi
 
595
            # Fail if bad DEST_MODULE_LOCATION
 
596
        case "${DEST_MODULE_LOCATION[$index]}" in
 
597
        /kernel*) ;;
 
598
        /updates*) ;;
 
599
        /extra*) ;;
 
600
        *)
 
601
            echo $"dkms.conf: Error! Directive 'DEST_MODULE_LOCATION' does not begin with">&2
 
602
            echo $"'/kernel', '/updates', or '/extra' in record #$index.">&2
 
603
            return_value=1
 
604
            ;;
 
605
        esac
 
606
 
 
607
        index=$(($index+1))
 
608
    done
 
609
 
 
610
    # Get the correct make command
 
611
    index=0
 
612
    [ -z "${MAKE_MATCH[0]}" ] && make_command="${MAKE[0]}"
 
613
    while [ "$index" -lt ${#MAKE[@]} ]; do
 
614
        if [ -n "${MAKE[$index]}" ] && \
 
615
            [ -n "${MAKE_MATCH[$index]}" ] && \
 
616
            echo $1 | egrep -q "${MAKE_MATCH[$index]}"; then
 
617
            make_command="${MAKE[$index]}"
 
618
        fi
 
619
        index=$(($index+1))
 
620
    done
 
621
 
 
622
    # Use the generic make and make clean commands if not specified
 
623
    if [[ $(VER $1) < $(VER 2.6.6) ]]; then
 
624
        if [ -z "$make_command" ]; then
 
625
            make_command="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build modules"
 
626
        fi
 
627
        if [ -z "$clean" ]; then
 
628
            clean="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build clean"
 
629
        fi
 
630
    else
 
631
        if [ -z "$make_command" ]; then
 
632
            make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
 
633
        fi
 
634
        if [ -z "$clean" ]; then
 
635
            clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
 
636
        fi
 
637
    fi
 
638
 
 
639
    # Set modules_conf_array
 
640
    index=0
 
641
    while [ "$index" -lt ${#MODULES_CONF[@]} ]; do
 
642
        [ -n "${MODULES_CONF[$index]}" ] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
 
643
        index=$(($index+1))
 
644
    done
 
645
 
 
646
    # Set patch_array (including kernel specific patches)
 
647
    index=0
 
648
    count=0
 
649
    while [ "$index" -lt ${#PATCH[@]} ]; do
 
650
        if [ -n "${PATCH[$index]}" ]; then
 
651
            if [ -z "${PATCH_MATCH[$index]}" ] || \
 
652
                echo $1 | egrep -q "${PATCH_MATCH[$index]}"; then
 
653
                patch_array[$count]="${PATCH[$index]}"
 
654
                count=$(($count+1))
 
655
            fi
 
656
        fi
 
657
        index=$(($index+1))
 
658
    done
 
659
 
 
660
    # Set remake_initrd
 
661
    [ `echo "$REMAKE_INITRD" | grep -ic "^y"` -gt 0 ] && remake_initrd="yes"
 
662
 
 
663
    # Set build_exclude
 
664
    if [ -n "$BUILD_EXCLUSIVE_KERNEL" ]; then
 
665
        echo $1 | egrep -q "$BUILD_EXCLUSIVE_KERNEL" || build_exclude="yes"
 
666
    fi
 
667
    if [ -n "$BUILD_EXCLUSIVE_ARCH" ]; then
 
668
        echo $2 | egrep -q "$BUILD_EXCLUSIVE_ARCH" || build_exclude="yes"
 
669
    fi
 
670
 
 
671
    # Fail if absolutely no DEST_MODULE_LOCATION
 
672
    if [ ${#dest_module_location[@]} -eq 0 ]; then
 
673
        echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified." >&2
 
674
        return_value=1
 
675
    fi
 
676
 
 
677
    # Fail if no PACKAGE_NAME
 
678
    if [ -z "$package_name" ]; then
 
679
        echo $"dkms.conf: Error! No 'PACKAGE_NAME' directive specified.">&2
 
680
        return_value=1
 
681
    fi
 
682
 
 
683
    # Fail if no PACKAGE_VERSION
 
684
    if [ -z "$package_version" ]; then
 
685
        echo $"dkms.conf: Error! No 'PACKAGE_VERSION' directive specified.">&2
 
686
        return_value=1
 
687
    fi
 
688
 
 
689
    # Set clean
 
690
    [ -z "$clean" ] && clean="make clean"
 
691
 
 
692
    return $return_value
 
693
}
 
694
 
 
695
 
 
696
function check_version_sanity ()
 
697
{
 
698
    # $1 = kernel_version
 
699
    # $2 = arch
 
700
    # $3 = obs by kernel version
 
701
    # $4 = dest_module_name
 
702
 
 
703
    local lib_tree="$install_tree/$1"
 
704
    echo $"Running module version sanity check."
 
705
    local module_count=`find $lib_tree -name ${4}$module_suffix | wc -l | awk {'print $1'}`
 
706
    if [ $module_count -gt 1 ]; then
 
707
        echo $"Warning! Cannot do version sanity checking because multiple ${4}$module_suffix" >&2
 
708
        echo $"modules were found in kernel $1." >&2
 
709
    elif [ $module_count -eq 1 ]; then
 
710
        local kernels_module=`find $lib_tree -name ${4}$module_suffix`
 
711
        local kernels_ver_string=`modinfo $kernels_module | grep "^version:"`
 
712
        local kernels_ver_value=`echo $kernels_ver_string | awk {'print $2'}`
 
713
        local dkms_module="$dkms_tree/$module/$module_version/$1/$2/module/${4}$module_suffix"
 
714
        local dkms_ver_string=`modinfo $dkms_module | grep "^version:"`
 
715
        local dkms_ver_value=`echo $dkms_ver_string | awk {'print $2'}`
 
716
 
 
717
        # there are 2 possible srcversion checksums
 
718
        # one in the 'srcversion' tag alone (preferred)
 
719
        # and one following the version field in the 'version' tag (deprecated)
 
720
        local kernels_ver_checksum=`modinfo $kernels_module | awk '/^srcversion:/ {print $2}'`
 
721
        local dkms_ver_checksum=`modinfo $dkms_module | awk '/^srcversion:/ {print $2}'`
 
722
        if [ -z "$kernels_ver_checksum" -a -z "$dkms_ver_checksum" ]; then
 
723
            kernels_ver_checksum=`echo $kernels_ver_string | awk {'print $3'}`
 
724
            dkms_ver_checksum=`echo $dkms_ver_string | awk {'print $3'}`
 
725
        fi
 
726
 
 
727
        if [ -n "$kernels_ver_checksum" -a -n "$dkms_ver_checksum" -a \
 
728
            "$kernels_ver_checksum" == "$dkms_ver_checksum" -a -z "$force" ]; then
 
729
            echo $"" >&2
 
730
            echo $"Good news! Module version $dkms_ver_value for ${4}$module_suffix" >&2
 
731
            echo $"exactly matches what is already found in kernel $1." >&2
 
732
            echo $"DKMS will not replace this module." >&2
 
733
            echo $"You may override by specifying --force." >&2
 
734
            return 1
 
735
        fi
 
736
 
 
737
        if [ -n "$kernels_ver_value" -a -n "$dkms_ver_value" ]; then
 
738
            if [[ ! ( $(VER $dkms_ver_value) > \
 
739
                      $(VER $kernels_ver_value) ) && -z "$force" ]]; then
 
740
                echo $"" >&2
 
741
                echo $"Error! Module version $dkms_ver_value for ${4}$module_suffix" >&2
 
742
                echo $"is not newer than what is already found in kernel $1 ($kernels_ver_value)." >&2
 
743
                echo $"You may override by specifying --force." >&2
 
744
                return 1
 
745
            fi
 
746
        fi
 
747
 
 
748
        local obs_upstream=`echo $3 | cut -d- -f 1`
 
749
        local obs_local=`echo $3 | cut -d- -f 2`
 
750
        local my_upstream=`echo $1 | cut -d- -f 1`
 
751
        local my_local=`echo $1 | cut -d- -f 2`
 
752
        local obsolete=0
 
753
        if [ -n "$obs_upstream" -a -n "$my_upstream" ]; then
 
754
            if [[ ( $(VER $obs_upstream) == $(VER $my_upstream) ) && -z "$force" ]]; then
 
755
            #they get obsoleted possibly in this kernel release
 
756
                if [ -z "$obs_local" ]; then
 
757
                #they were obsoleted in this upstream kernel
 
758
                    obsolete=1
 
759
                elif [[ ( $(VER $my_local) > $(VER $obs_local) ) ]]; then
 
760
                #they were obsoleted in an earlier ABI bump of the kernel
 
761
                    obsolete=1
 
762
                elif [[ ( $(VER $my_local) = $(VER $obs_local) ) ]]; then
 
763
                #they were obsoleted in this ABI bump of the kernel
 
764
                    obsolete=1
 
765
                fi
 
766
            elif [[ ( $(VER $my_upstream) > $(VER $obs_upstream) ) && -z "$force" ]]; then
 
767
            #they were obsoleted in an earlier kernel release
 
768
                obsolete=1
 
769
            fi
 
770
        fi
 
771
 
 
772
        if [ "$obsolete" == 1 ]; then
 
773
            echo $"" >&2
 
774
            echo $"Module has been obsoleted due to being included" >&2
 
775
            echo $"in kernel $3.  We will avoid installing" >&2
 
776
            echo $"for future kernels above $3." >&2
 
777
            echo $"You may override by specifying --force." >&2
 
778
            return 1
 
779
        fi
 
780
    fi
 
781
    return 0
 
782
}
 
783
 
 
784
 
 
785
function moduleconfig_add ()
 
786
{
 
787
    # $1 = kernel version
 
788
 
 
789
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
790
    modconfig_files=""
 
791
    [ -e /etc/modprobe.d/dkms.conf ] && modconfig_files="/etc/modprobe.d/dkms.conf"
 
792
    [ -e /etc/modprobe.d/dkms ] && modconfig_files="/etc/modprobe.d/dkms"
 
793
    [ -e /etc/modules.conf ] && modconfig_files="$modconfig_files /etc/modules.conf"
 
794
    [ -e /etc/modprobe.conf ] && modconfig_files="$modconfig_files /etc/modprobe.conf"
 
795
    [ -e /etc/modprobe.d/$package_name.conf ] && modconfig_files="/etc/modprobe.d/$package_name.conf"
 
796
 
 
797
    if [ -z "$modconfig_files" ]; then
 
798
        modconfig_files="/etc/modprobe.d/$package_name.conf"
 
799
    fi
 
800
 
 
801
 
 
802
    for moduleconfig in $modconfig_files; do
 
803
        local index=0
 
804
        while [ $index -lt ${#dest_module_name[@]} ]; do
 
805
            # Replace obsolete references in module-config-file with the new module name
 
806
            if [ -n "${modules_conf_obsoletes[$index]}" ]; then
 
807
                for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
 
808
                    sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) $obsolete_module$/\1 ${dest_module_name[$index]}/g" $moduleconfig > $temp_dir_name/moduleconfig.new
 
809
                    if ! diff $moduleconfig $temp_dir_name/moduleconfig.new >/dev/null 2>&1; then
 
810
                        cp -fp $temp_dir_name/moduleconfig.new $moduleconfig 2>/dev/null
 
811
                        rm -f $temp_dir_name/moduleconfig.new 2>/dev/null
 
812
                        echo $"$moduleconfig: obsolete alias '$obsolete_module' changed to '${dest_module_name[$index]}'"
 
813
                    fi
 
814
                    if [ -e /etc/sysconfig/kernel ]; then
 
815
                       sed -e "s/\(INITRD_MODULES.*\)$obsolete_module\b\(.*\)/\1${dest_module_name[$index]}\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
 
816
                       if ! diff $temp_dir_name/kernel.new /etc/sysconfig/kernel >/dev/null 2>&1; then
 
817
                           cp -fp $temp_dir_name/kernel.new /etc/sysconfig/kernel 2>/dev/null
 
818
                           rm -f $temp_dir_name/kernel.new 2>/dev/null
 
819
                           echo $"/etc/sysconfig/kernel: obsolete alias '$obsolete_module' changed to '${dest_module_name[$index]}'"
 
820
                       fi
 
821
                    fi
 
822
                done
 
823
            fi
 
824
 
 
825
            # Only add it if it can't be found already in config file
 
826
            if [ -n "${modules_conf_alias_type[$index]}" ] && \
 
827
               ! grep -qs "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}\b" $moduleconfig && \
 
828
               [ "${modules_conf_obsolete_only[$index]}" != "yes" ]; then
 
829
                if [ "$modconfig_files" == "/etc/modprobe.d/$package_name.conf" ] && \
 
830
                    [ ! -e /etc/modprobe.d/$package_name.conf ]; then
 
831
                    touch /etc/modprobe.d/$package_name.conf
 
832
                    echo $"created /etc/modprobe.d/$package_name.conf.">&2
 
833
                fi
 
834
                aliases=$(awk "/^alias ${modules_conf_alias_type[$index]}/ {print \$2}" $moduleconfig)
 
835
                if [ -n "$aliases" ]; then
 
836
                    alias_number=$(($(echo "$aliases" | sed "s/${modules_conf_alias_type[$index]}//" | sort -n | tail -n 1) + 1))
 
837
                else
 
838
                    alias_number=0
 
839
                fi
 
840
                echo -e "alias ${modules_conf_alias_type[$index]}${alias_number} ${dest_module_name[$index]}" >> $moduleconfig
 
841
                echo $"$moduleconfig: added alias reference for '${dest_module_name[$index]}'"
 
842
            fi
 
843
 
 
844
            index=$(($index+1))
 
845
        done
 
846
 
 
847
        # Add anything else
 
848
        index=0
 
849
        while [ $index -lt ${#modules_conf_array[@]} ]; do
 
850
            if [ -n "${modules_conf_array[$index]}" ] && \
 
851
            ! grep -q "${modules_conf_array[$index]}" "$moduleconfig"; then
 
852
            echo -e $"$moduleconfig: added '${modules_conf_array[$index]}'"
 
853
            echo -e "${modules_conf_array[$index]}" >> $moduleconfig
 
854
            fi
 
855
            index=$(($index+1))
 
856
        done
 
857
    done
 
858
 
 
859
    # Delete the temp dir
 
860
    rm -rf $temp_dir_name
 
861
}
 
862
 
 
863
 
 
864
function moduleconfig_remove ()
 
865
{
 
866
    # $1 = kernel version
 
867
 
 
868
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
869
    modconfig_files=""
 
870
    [ -e /etc/modprobe.d/dkms.conf ] && modconfig_files="/etc/modprobe.d/dkms.conf"
 
871
    [ -e /etc/modprobe.d/dkms ] && modconfig_files="/etc/modprobe.d/dkms"
 
872
    [ -e /etc/modules.conf ] && modconfig_files="$modconfig_files /etc/modules.conf"
 
873
    [ -e /etc/modprobe.conf ] && modconfig_files="$modconfig_files /etc/modprobe.conf"
 
874
    [ -e /etc/modprobe.d/$package_name.conf ] && modconfig_files="/etc/modprobe.d/$package_name.conf"
 
875
 
 
876
    for moduleconfig in $modconfig_files; do
 
877
        index=0
 
878
        while [ $index -lt ${#dest_module_name[@]} ]; do
 
879
 
 
880
            # Remove/Replace aliases (maybe)
 
881
            if [ -n "${modules_conf_alias_type[$index]}" ] && [ `find $install_tree/$1/ -name "${dest_module_name[$index]}.*" 2>/dev/null | wc -l | awk '{print $1}'` -eq 0 ]; then
 
882
 
 
883
                local conf_replacement=""
 
884
                for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
 
885
                    if [ `find $install_tree/$1/ -name "$obsolete_module.*" 2>/dev/null | wc -l | awk '{print $1}'` -gt 0 ] && [ -z "$conf_replacement" ]; then
 
886
                        conf_replacement=$obsolete_module
 
887
                    fi
 
888
                done
 
889
 
 
890
                if [ -n "$conf_replacement" ] && \
 
891
                    grep -q "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}$" $moduleconfig; then
 
892
                    sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) ${dest_module_name[$index]}$/\1 $conf_replacement/g" $moduleconfig > $temp_dir_name/moduleconfig.new
 
893
                    mv -f $temp_dir_name/moduleconfig.new $moduleconfig
 
894
                    echo $"$moduleconfig: alias for '${dest_module_name[$index]}' changed back to '$conf_replacement'"
 
895
                elif [ -z "$conf_replacement" ]; then
 
896
                    grep -v "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}" $moduleconfig > $temp_dir_name/moduleconfig.new
 
897
                    mv -f $temp_dir_name/moduleconfig.new $moduleconfig
 
898
                    echo $"$moduleconfig: removed alias for '${dest_module_name[$index]}'"
 
899
                    if [ "$modconfig_files" == "/etc/modprobe.d/$package_name.conf" ]; then
 
900
                        rm -f /etc/modprobe.d/$package_name.conf
 
901
                        echo $"$moduleconfig: deleted /etc/modprobe.d/$package_name.conf file"
 
902
                    fi
 
903
                fi
 
904
            fi
 
905
 
 
906
            index=$(($index+1))
 
907
        done
 
908
 
 
909
        # Remove static conf entries
 
910
        index=0
 
911
        while [ $index -lt ${#modules_conf_array[@]} ]; do
 
912
            if [ -n "${modules_conf_array[$index]}" ]; then
 
913
            grep -v "${modules_conf_array[$index]}" "$moduleconfig" > $temp_dir_name/moduleconfig.new
 
914
            echo $"$moduleconfig: removed '${modules_conf_array[$index]}'"
 
915
            mv -f $temp_dir_name/moduleconfig.new $moduleconfig
 
916
            fi
 
917
            index=$(($index+1))
 
918
        done
 
919
    done
 
920
 
 
921
    # Delete the temp dir
 
922
    rm -rf $temp_dir_name
 
923
}
 
924
 
 
925
# Does string word exist as a word in string list?
 
926
# returns 0 if word present, 1 if word not present
 
927
function is_word_in_list ()
 
928
{
 
929
    for l in $2; do
 
930
        [ "$1" = "${l}" ] && return 0
 
931
    done
 
932
    return 1
 
933
}
 
934
 
 
935
function etc_sysconfig_kernel_modify ()
 
936
{
 
937
    # Make a temp directory to store files
 
938
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
939
 
 
940
    if [ -e "/etc/sysconfig/kernel" ] && [ -n "$remake_initrd" ]; then
 
941
        # Make /etc/sysconfig/kernel changes as necessary
 
942
        if [ "$1" == "add" ]; then
 
943
            unset INITRD_MODULES
 
944
            eval `grep ^INITRD_MODULES= /etc/sysconfig/kernel`
 
945
            for module_name_after in "${dest_module_name[@]}"; do
 
946
                if ! is_word_in_list "${module_name_after}" "${INITRD_MODULES}"; then
 
947
                    sed -e "s/INITRD_MODULES=\"\(.*\)\"/INITRD_MODULES=\"\1 $module_name_after\"/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
 
948
                    mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
 
949
                fi
 
950
            done
 
951
        unset INITRD_MODULES
 
952
 
 
953
        # Remove /etc/sysconfig/kernel entries
 
954
        elif [ "$1" == "delete" ]; then
 
955
            for module_name_after in "${dest_module_name[@]}"; do
 
956
                sed -e "s/\(INITRD_MODULES.*\)$module_name_after\b\(.*\)/\1\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
 
957
                mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
 
958
            done
 
959
        fi
 
960
    fi
 
961
 
 
962
    # Delete the temp dir
 
963
    rm -rf $temp_dir_name
 
964
}
 
965
 
 
966
function add_module ()
 
967
{
 
968
    setup_kernels_arches "add"
 
969
 
 
970
    # Check that we have all the arguments
 
971
    if [ -z "$module" ] || [ -z "$module_version" ]; then
 
972
        echo $"" >&2
 
973
        echo $"Error! Invalid number of arguments passed." >&2
 
974
        echo $"Usage: add -m <module> -v <module-version>" >&2
 
975
        exit 1
 
976
    fi
 
977
 
 
978
    if [ -z "$conf" ]; then
 
979
        conf="$source_tree/$module-$module_version/dkms.conf"
 
980
    fi
 
981
 
 
982
    # Check that /usr/src/$module-$module_version exists
 
983
    if ! [ -d "$source_tree/$module-$module_version" ]; then
 
984
        echo $"" >&2
 
985
        echo $"Error! Could not find module source directory." >&2
 
986
        echo $"Directory: $source_tree/$module-$module_version does not exist." >&2
 
987
        exit 2
 
988
    fi
 
989
 
 
990
    # Do stuff for --rpm_safe_upgrade
 
991
    if [ -n "$rpm_safe_upgrade" ]; then
 
992
        local pppid=`sed -ne 's/PPid:[ \t]*//p' /proc/$PPID/status`
 
993
        local temp_dir_name=`mktemp $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.XXXXXX 2>/dev/null`
 
994
        echo "$module-$module_version" >> $temp_dir_name
 
995
        ps -o lstart --no-headers -p $pppid 2>/dev/null >> $temp_dir_name
 
996
    fi
 
997
 
 
998
    # Check that this module-version hasn't already been added
 
999
    if [ -d "$dkms_tree/$module/$module_version" ]; then
 
1000
        echo $"" >&2
 
1001
        echo $"Error! DKMS tree already contains: $module-$module_version" >&2
 
1002
        echo $"You cannot add the same module/version combo more than once." >&2
 
1003
        exit 3
 
1004
    fi
 
1005
 
 
1006
    # Check that the conf file exists or any other script specified
 
1007
    if ! [ -e "$conf" ]; then
 
1008
        echo $"" >&2
 
1009
        echo $"Error! Could not locate dkms.conf file." >&2
 
1010
        echo $"File: $conf does not exist." >&2
 
1011
        exit 4
 
1012
    fi
 
1013
 
 
1014
    # Check the conf file for sanity
 
1015
    read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
 
1016
    if [ "$?" -ne 0 ]; then
 
1017
        echo $"" >&2
 
1018
        echo $"Error! Bad conf file." >&2
 
1019
        echo $"File: $conf" >&2
 
1020
        echo $"does not represent a valid dkms.conf file." >&2
 
1021
        exit 8
 
1022
    fi
 
1023
 
 
1024
    # Create the necessary dkms tree structure
 
1025
    echo $""
 
1026
    echo $"Creating symlink $dkms_tree/$module/$module_version/source ->"
 
1027
    echo $"                 $source_tree/$module-$module_version"
 
1028
    mkdir -p "$dkms_tree/$module/$module_version/build"
 
1029
    ln -s "$source_tree/$module-$module_version" "$dkms_tree/$module/$module_version/source"
 
1030
 
 
1031
    # Run the post_add script
 
1032
    if [ -n "$post_add" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_add" | sed 's/ .*//'` ]; then
 
1033
        echo $""
 
1034
        echo $"Running the post_add script:"
 
1035
        $dkms_tree/$module/$module_version/source/$post_add
 
1036
    fi
 
1037
 
 
1038
    echo $""
 
1039
    echo $"DKMS: add Completed."
 
1040
}
 
1041
 
 
1042
function prepare_kernel()
 
1043
{
 
1044
    # $1 = kernel version to prepare
 
1045
    # $2 = arch to prepare
 
1046
 
 
1047
    set_kernel_source_dir "$1"
 
1048
 
 
1049
    # Check that kernel-source exists
 
1050
    if ! [ -e "$kernel_source_dir/include" ]; then
 
1051
        echo $"" >&2
 
1052
        echo $"Error! Your kernel headers for kernel $1 cannot be found at" >&2
 
1053
        echo $"/lib/modules/$1/build or /lib/modules/$1/source." >&2
 
1054
        echo -n $"You can use the --kernelsourcedir option to tell DKMS where it's located"
 
1055
        case "$running_distribution" in
 
1056
        Debian* | Ubuntu* )
 
1057
            echo $", or you could install the linux-headers-$1 package."
 
1058
            ;;
 
1059
        * )
 
1060
            echo $"."
 
1061
            ;;
 
1062
        esac
 
1063
        exit 1
 
1064
    fi
 
1065
 
 
1066
    if [ -n "$no_prepare_kernel" ]; then
 
1067
        return
 
1068
    fi
 
1069
 
 
1070
    if [[ (! ( $(VER $1) < $(VER 2.6.5) ) || (-d /etc/SuSEconfig)) && \
 
1071
       -d "$kernel_source_dir" && \
 
1072
       -z "$ksourcedir_fromcli" ]]; then
 
1073
        echo $""
 
1074
        echo $"Kernel preparation unnecessary for this kernel.  Skipping..."
 
1075
        no_clean_kernel="no-clean-kernel"
 
1076
        return 1
 
1077
    fi
 
1078
 
 
1079
    # Prepare kernel for module build
 
1080
    echo $""
 
1081
    echo $"Preparing kernel $1 for module build:"
 
1082
    echo $"(This is not compiling a kernel, just preparing kernel symbols)"
 
1083
    cd $kernel_source_dir
 
1084
    config_contents=`cat .config 2>/dev/null`
 
1085
    [ -n "$config_contents" ] && echo $"Storing current .config to be restored when complete"
 
1086
 
 
1087
    # Set kernel_config
 
1088
    if [ -e /etc/redhat-release ] || [ -e /etc/fedora-release ]; then
 
1089
        # Note this also applies to VMware 3.x
 
1090
        if [ -z "$kernel_config" ] && [ -d "$kernel_source_dir/configs" ]; then
 
1091
            local kernel_trunc=`echo $1 | sed 's/-.*//'`
 
1092
            for config_type in debug summit smp enterprise bigmem hugemem BOOT vmnix; do
 
1093
                [ `echo "$1" | grep "$config_type"` ] && kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2-$config_type.config"
 
1094
                [ ! -e "$kernel_config" ] && kernel_config=""
 
1095
            done
 
1096
            [ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2.config"
 
1097
            [ ! -e "$kernel_config" ] && kernel_config=""
 
1098
        fi
 
1099
    elif [ -e /etc/SuSE-release ] || [ -d /etc/SuSEconfig ]; then
 
1100
        if [ -z "$kernel_config" ] && [ -d "$kernel_source_dir/arch" ]; then
 
1101
            local kernel_trunc=`echo $1 | sed 's/-.*//'`
 
1102
            if [ "$2" == "i586" ] || [ "$2" == "i686" ]; then
 
1103
                config_arch="i386"
 
1104
            else
 
1105
                config_arch=$2
 
1106
            fi
 
1107
            for config_type in default smp bigsmp; do
 
1108
                [ `echo "$1" | grep "$config_type"` ] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.$config_type"
 
1109
                [ ! -e "$kernel_config" ] && kernel_config=""
 
1110
            done
 
1111
            [ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.default"
 
1112
            [ ! -e "$kernel_config" ] && kernel_config=""
 
1113
        fi
 
1114
    fi
 
1115
 
 
1116
    # Do preparation
 
1117
    if [ -e /boot/vmlinuz.version.h ]; then
 
1118
        echo $"Running UnitedLinux preparation routine"
 
1119
        local kernel_config="/boot/vmlinuz.config"
 
1120
        invoke_command "make mrproper" "make mrproper" background
 
1121
        [ -n "$config_contents" ] && echo "$config_contents" > .config
 
1122
        invoke_command "cp /boot/vmlinuz.version.h include/linux/version.h" "using /boot/vmlinux.version.h"
 
1123
        invoke_command "cp -f $kernel_config .config" "using $kernel_config"
 
1124
        invoke_command "make KERNELRELEASE=$1 cloneconfig" "make cloneconfig" background
 
1125
        invoke_command "make CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
 
1126
    elif grep -q rhconfig.h $kernel_source_dir/include/linux/{modversions,version}.h 2>/dev/null; then
 
1127
        echo $"Running Red Hat style preparation routine"
 
1128
        invoke_command "make clean" "make clean" background
 
1129
        [ -n "$config_contents" ] && echo "$config_contents" > .config
 
1130
 
 
1131
        if [ -n "$kernel_config" ]; then
 
1132
            echo $"using $kernel_config"
 
1133
            cp -f "$kernel_config" .config
 
1134
        elif [ -e .config ]; then
 
1135
            echo $"using $kernel_source_dir/.config"
 
1136
            echo $"(I hope this is the correct config for this kernel)"
 
1137
        else
 
1138
            echo $""
 
1139
            echo $"Warning! Cannot find a .config file to prepare your kernel with." >&2
 
1140
            echo $"Try using the --config option to specify where one can be found." >&2
 
1141
            echo $"Your build will likely fail because of this." >&2
 
1142
        fi
 
1143
 
 
1144
        # Hack to workaround broken tmp_include_depends for Red Hat
 
1145
        if grep -q "/usr/src/build" $kernel_source_dir/tmp_include_depends 2>/dev/null; then
 
1146
            sed 's/\/usr\/src\/build\/.*\/install//g' $kernel_source_dir/tmp_include_depends > $kernel_source_dir/tmp_include_depends.new
 
1147
            mv -f $kernel_source_dir/tmp_include_depends.new $kernel_source_dir/tmp_include_depends
 
1148
        fi
 
1149
 
 
1150
        invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
 
1151
        kerneldoth_contents=`cat /boot/kernel.h 2>/dev/null`
 
1152
        invoke_command "/usr/lib/dkms/mkkerneldoth --kernelver $1 --targetarch $2 --output /boot/kernel.h" "running mkkerneldoth" background
 
1153
    else
 
1154
        echo $"Running Generic preparation routine"
 
1155
        invoke_command "make mrproper" "make mrproper" background
 
1156
        [ -n "$config_contents" ] && echo "$config_contents" > .config
 
1157
 
 
1158
        if [ -n "$kernel_config" ]; then
 
1159
            echo $"using $kernel_config"
 
1160
            cp -f "$kernel_config" .config
 
1161
        elif [ -e .config ]; then
 
1162
            echo $"using $kernel_source_dir/.config"
 
1163
            echo $"(I hope this is the correct config for this kernel)"
 
1164
        else
 
1165
            echo $""
 
1166
            echo $"Warning! Cannot find a .config file to prepare your kernel with." >&2
 
1167
            echo $"Try using the --config option to specify where one can be found." >&2
 
1168
            echo $"Your build will likely fail because of this." >&2
 
1169
        fi
 
1170
 
 
1171
        invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
 
1172
        if [[ $(VER $1) < $(VER 2.5) ]]; then
 
1173
            invoke_command "make KERNELRELEASE=$1 dep" "make dep" background
 
1174
        else
 
1175
            invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
 
1176
        fi
 
1177
    fi
 
1178
    cd - >/dev/null
 
1179
}
 
1180
 
 
1181
function list_each_installed_module ()
 
1182
{
 
1183
    # $1 = module
 
1184
    # $2 = kernel version
 
1185
    # $3 = arch
 
1186
    local count=0
 
1187
    local real_dest_module_location
 
1188
    while [ "$count" -lt "${#built_module_name[@]}" ]; do
 
1189
        real_dest_module_location="$(find_actual_dest_module_location $1 $count $2 $3)"
 
1190
        echo "$install_tree/$2${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
 
1191
        count=$(($count + 1))
 
1192
    done
 
1193
}
 
1194
 
 
1195
function set_weak_modules()
 
1196
{
 
1197
    [ -n "${weak_modules}" ] && return
 
1198
    [ -x /sbin/weak-modules ] && weak_modules='/sbin/weak-modules'
 
1199
    [ -x /usr/lib/module-init-tools/weak-modules ] && weak_modules='/usr/lib/module-init-tools/weak-modules'
 
1200
}
 
1201
 
 
1202
function install_module()
 
1203
{
 
1204
    setup_kernels_arches "install"
 
1205
    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
 
1206
 
 
1207
    # Check that the right arguments were passed
 
1208
    if [ -z "$module" ] || [ -z "$module_version" ]; then
 
1209
        echo $"" >&2
 
1210
        echo $"Error! Invalid number of parameters passed." >&2
 
1211
        echo $"Usage: install -m <module> -v <module-version>" >&2
 
1212
        exit 1
 
1213
    fi
 
1214
 
 
1215
    # Check that $module-$module_version exists by checking the source symlink
 
1216
    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
 
1217
        echo $"" >&2
 
1218
        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
 
1219
        echo $"Build cannot continue without the proper tree." >&2
 
1220
        exit 2
 
1221
    fi
 
1222
 
 
1223
    # Make sure that kernel exists to install into
 
1224
    if ! [ -e "$install_tree/${kernelver_array[0]}" ]; then
 
1225
        echo $"" >&2
 
1226
        echo $"Error! The directory $install_tree/${kernelver_array[0]} doesn't exist." >&2
 
1227
        echo $"You cannot install a module onto a non-existant kernel." >&2
 
1228
        exit 6
 
1229
    fi
 
1230
 
 
1231
    # Read the conf file
 
1232
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
1233
    if [ "$?" -ne 0 ]; then
 
1234
        echo $"" >&2
 
1235
        echo $"Error! Bad conf file." >&2
 
1236
        echo $"Your dkms.conf is not valid." >&2
 
1237
        exit 3
 
1238
    fi
 
1239
 
 
1240
    # Make sure the $module_name_after exists
 
1241
    set_module_suffix "${kernelver_array[0]}"
 
1242
    for module_name_after in "${dest_module_name[@]}"; do
 
1243
        if ! [ -e "$base_dir/module/$module_name_after$module_suffix" ]; then
 
1244
            echo $"" >&2
 
1245
            echo $"Error! Could not locate $module_name_after$module_suffix for module $module in the DKMS tree." >&2
 
1246
            echo $"You must run a dkms build for kernel ${kernelver_array[0]} (${arch_array[0]}) first." >&2
 
1247
            exit 4
 
1248
        fi
 
1249
    done
 
1250
 
 
1251
    # Check that its not already installed (kernel symlink)
 
1252
    readlink "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}"
 
1253
    kernel_symlink="$read_link"
 
1254
    if [ "$kernel_symlink" == "$module_version/${kernelver_array[0]}/${arch_array[0]}" ]; then
 
1255
        echo $"" >&2
 
1256
        echo $"Error! This module/version combo is already installed" >&2
 
1257
        echo $"for kernel: ${kernelver_array[0]} (${arch_array[0]})" >&2
 
1258
        exit 5
 
1259
    fi
 
1260
 
 
1261
    # if upgrading using rpm_safe_upgrade, go ahead and force the install
 
1262
    # else we can wind up with the first half of an upgrade failing to install anything,
 
1263
    # while the second half of the upgrade, the removal, then succeeds, leaving us with
 
1264
    # nothing installed.
 
1265
    if [ -n "$rpm_safe_upgrade" ]; then
 
1266
        force="true"
 
1267
    fi
 
1268
 
 
1269
    # Save the original_module if one exists, none have been saved before, and this is the first module for this kernel
 
1270
    local lib_tree="$install_tree/${kernelver_array[0]}"
 
1271
    local count=0
 
1272
    while [ "$count" -lt ${#built_module_name[@]} ]; do
 
1273
        echo $""
 
1274
        echo $"${dest_module_name[$count]}$module_suffix:"
 
1275
        # Check this version against what is already in the kernel
 
1276
        if ! check_version_sanity "${kernelver_array[0]}" "${arch_array[0]}" "$obsolete_by" "${dest_module_name[$count]}"; then
 
1277
            count=$(($count + 1))
 
1278
            continue
 
1279
        fi
 
1280
 
 
1281
        if [ "$count" -eq 0 ]; then
 
1282
            # Run the pre_install script
 
1283
            if [ -n "$pre_install" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_install" | sed 's/ .*//'` ]; then
 
1284
                echo $""
 
1285
                echo $"Running the pre_install script:"
 
1286
                $dkms_tree/$module/$module_version/source/$pre_install
 
1287
                if [ "$?" -ne 0 -a -z "$force" ]; then
 
1288
                    echo $"pre_install failed, aborting install." >&2
 
1289
                    echo $"You may override by specifying --force." >&2
 
1290
                    exit 101
 
1291
                fi
 
1292
            fi
 
1293
        fi
 
1294
        local module_count=`find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f | wc -l | awk {'print $1'}`
 
1295
        echo $" - Original module"
 
1296
        if ! [ -L "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" ]; then
 
1297
            local archive_pref1="$lib_tree/extra/${dest_module_name[$count]}$module_suffix"
 
1298
            local archive_pref2="$lib_tree/updates/${dest_module_name[$count]}$module_suffix"
 
1299
            local archive_pref3="$lib_tree${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
 
1300
            local archive_pref4=""
 
1301
            [ "$module_count" -eq 1 ] && archive_pref4="`find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f`"
 
1302
            local original_module=""
 
1303
            local found_orginal=""
 
1304
            for original_module in $archive_pref1 $archive_pref2 $archive_pref3 $archive_pref4; do
 
1305
                if [ -f "$original_module" ]; then
 
1306
                    case "$running_distribution" in
 
1307
                        Debian* | Ubuntu* ) ;;
 
1308
                        *)
 
1309
                            echo $"   - Found $original_module"
 
1310
                            echo $"   - Storing in $dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/"
 
1311
                            echo $"   - Archiving for uninstallation purposes"
 
1312
                            mkdir -p "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}"
 
1313
                            mv -f "$original_module" "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/"
 
1314
                            ;;
 
1315
                    esac
 
1316
                    found_original="yes"
 
1317
                    break
 
1318
                fi
 
1319
            done
 
1320
            if [ -z "$found_original" ] && [ "$module_count" -gt 1 ]; then
 
1321
                echo $"   - Multiple original modules exist but DKMS does not know which to pick"
 
1322
                echo $"   - Due to the confusion, none will be considered during a later uninstall"
 
1323
            elif [ -z "$found_original" ]; then
 
1324
                echo $"   - No original module exists within this kernel"
 
1325
            fi
 
1326
        elif [ -L "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" ] && [ -e "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/${dest_module_name[$count]}$module_suffix" ]; then
 
1327
            echo $"   - An original module was already stored during a previous install"
 
1328
        else
 
1329
            echo $"   - This kernel never originally had a module by this name"
 
1330
        fi
 
1331
 
 
1332
        if [ "$module_count" -gt 1 ]; then
 
1333
            echo $" - Multiple same named modules!"
 
1334
            echo $"   - $module_count named ${dest_module_name[$count]}$module_suffix in $lib_tree/"
 
1335
            case "$running_distribution" in
 
1336
            Debian* | Ubuntu* ) ;;
 
1337
            *)
 
1338
                echo $"   - All instances of this module will now be stored for reference purposes ONLY"
 
1339
                echo $"   - Storing in $dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/"
 
1340
                ;;
 
1341
            esac
 
1342
            for module_dup in `find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f`; do
 
1343
                dup_tree=`echo $module_dup | sed "s#^$lib_tree##" | sed "s#${dest_module_name[$count]}$module_suffix##"`
 
1344
                case "$running_distribution" in
 
1345
                Debian* | Ubuntu* ) ;;
 
1346
                *)
 
1347
                   echo $"     - Stored $module_dup"
 
1348
                   mkdir -p "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/$dup_tree"
 
1349
                   mv -f $module_dup "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/$dup_tree"
 
1350
                   ;;
 
1351
                esac
 
1352
            done
 
1353
        fi
 
1354
 
 
1355
        # Copy module to its location
 
1356
        echo $" - Installation"
 
1357
        echo $"   - Installing to $install_tree/${kernelver_array[0]}${dest_module_location[$count]}/"
 
1358
        mkdir -p $install_tree/${kernelver_array[0]}${dest_module_location[$count]}
 
1359
        cp -f "$base_dir/module/${dest_module_name[$count]}$module_suffix" "$install_tree/${kernelver_array[0]}${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
 
1360
 
 
1361
        count=$(($count + 1))
 
1362
    done
 
1363
 
 
1364
    # Create the kernel-<kernelver> symlink to designate this version as active
 
1365
    rm -f "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" 2>/dev/null
 
1366
    ln -s "$module_version/${kernelver_array[0]}/${arch_array[0]}" "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" 2>/dev/null
 
1367
 
 
1368
    # add to kabi-tracking
 
1369
    set_weak_modules
 
1370
    if [ -n "${weak_modules}" ]; then
 
1371
        echo $"Adding any weak-modules"
 
1372
        list_each_installed_module "$module" "${kernelver_array[0]}" "${arch_array[0]}" | ${weak_modules} --add-modules
 
1373
    fi
 
1374
 
 
1375
    # Run the post_install script
 
1376
    if [ -n "$post_install" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_install" | sed 's/ .*//'` ]; then
 
1377
        echo $""
 
1378
        echo $"Running post_install:"
 
1379
        $dkms_tree/$module/$module_version/source/$post_install
 
1380
    fi
 
1381
 
 
1382
    # Make modules.conf changes as necessary
 
1383
    echo $""
 
1384
    moduleconfig_add "${kernelver_array[0]}"
 
1385
    etc_sysconfig_kernel_modify "add"
 
1386
 
 
1387
    invoke_command "do_depmod ${kernelver_array[0]}" "depmod" background
 
1388
    if [ "$?" -ne 0 ]; then
 
1389
        local unresolved_symbols="$(do_depmod ${kernelver_array[0]} 2>&1)"
 
1390
        local count=0
 
1391
        while [ "$count" -lt "${#built_module_name[@]}" ]; do
 
1392
            if echo "$unresolved_symbols" | grep -q "${dest_module_name[$count]}$module_suffix$"; then
 
1393
                echo $""
 
1394
                echo $"Problems with depmod detected.  Automatically uninstalling this module."
 
1395
                sleep 2
 
1396
                do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
 
1397
                echo $""
 
1398
                echo $"DKMS: Install Failed (depmod problems).  Module rolled back to built state."
 
1399
                exit 6
 
1400
            fi
 
1401
            count=$(($count + 1))
 
1402
        done
 
1403
    fi
 
1404
 
 
1405
    # Do remake_initrd things (save old initrd)
 
1406
    if [ -n "$remake_initrd" ]; then
 
1407
        remake_initrd "${kernelver_array[0]}" "${arch_array[0]}"
 
1408
        if [ "$?" -ne 0 ]; then
 
1409
            echo $"Problems with mkinitrd detected.  Automatically uninstalling this module."
 
1410
            sleep 2
 
1411
            do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
 
1412
            echo $""
 
1413
            echo $"DKMS: Install Failed (mkinitrd problems).  Module rolled back to built state."
 
1414
            exit 7
 
1415
        fi
 
1416
    fi
 
1417
 
 
1418
    echo $""
 
1419
    echo $"DKMS: install Completed."
 
1420
}
 
1421
 
 
1422
 
 
1423
function prepare_build()
 
1424
{
 
1425
    setup_kernels_arches "build"
 
1426
    set_kernel_source_dir "${kernelver_array[0]}"
 
1427
    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
 
1428
 
 
1429
    # Check that the right arguments were passed
 
1430
    if [ -z "$module" ] || [ -z "$module_version" ]; then
 
1431
        echo $"" >&2
 
1432
        echo $"Error! Invalid number of parameters passed." >&2
 
1433
        echo $"Usage: build -m <module> -v <module-version>" >&2
 
1434
        exit 1
 
1435
    fi
 
1436
 
 
1437
    # Check that source symlink works
 
1438
    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
 
1439
        echo $"" >&2
 
1440
        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
 
1441
        echo $"Build cannot continue without the proper tree." >&2
 
1442
        exit 2
 
1443
    fi
 
1444
 
 
1445
    # Check that the module has not already been built for this kernel
 
1446
    if [ -d "$base_dir" ]; then
 
1447
        echo $"" >&2
 
1448
        echo $"Error! This module/version has already been built on: ${kernelver_array[0]}" >&2
 
1449
        echo $"Directory: $base_dir" >&2
 
1450
        echo $"already exists.  Use the dkms remove function before trying to build again." >&2
 
1451
        exit 3
 
1452
    fi
 
1453
 
 
1454
    # Read the conf file
 
1455
    set_module_suffix "${kernelver_array[0]}"
 
1456
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
1457
    if [ "$?" -ne 0 ]; then
 
1458
        echo $"" >&2
 
1459
        echo $"Error! Bad conf file." >&2
 
1460
        echo $"Your dkms.conf is not valid." >&2
 
1461
        exit 4
 
1462
    fi
 
1463
 
 
1464
    # Error out if build_exclude is set
 
1465
    if [ -n "$build_exclude" ]; then
 
1466
        echo "" >&2
 
1467
        echo "Error!  The dkms.conf for this module includes a BUILD_EXCLUSIVE directive which" >&2
 
1468
        echo "does not match this kernel/arch.  This indicates that it should not be built." >&2
 
1469
        exit 9
 
1470
    fi
 
1471
 
 
1472
    # Error out if source_tree is basically empty (binary-only dkms tarball w/ --force check)
 
1473
    if [ `ls $dkms_tree/$module/$module_version/source | wc -l | awk {'print $1'}` -lt 2 ]; then
 
1474
        echo "" >&2
 
1475
        echo $"Error! The directory $dkms_tree/$module/$module_version/source/" >&2
 
1476
        echo $"does not appear to have module source located within it.  Build halted." >&2
 
1477
        exit 8
 
1478
    fi
 
1479
 
 
1480
    prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
 
1481
 
 
1482
    # Set up temporary build directory for build
 
1483
    rm -rf "$dkms_tree/$module/$module_version/build"
 
1484
    cp -rf "$dkms_tree/$module/$module_version/source/" "$dkms_tree/$module/$module_version/build"
 
1485
 
 
1486
    # Run the pre_build script
 
1487
    if [ -n "$pre_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_build" | sed 's/ .*//'` ]; then
 
1488
        echo $""
 
1489
        echo $"Running the pre_build script:"
 
1490
        $dkms_tree/$module/$module_version/source/$pre_build
 
1491
    fi
 
1492
 
 
1493
    cd "$dkms_tree/$module/$module_version/build"
 
1494
 
 
1495
    # Apply any patches
 
1496
    local index=0
 
1497
    while [ $index -lt ${#patch_array[@]} ]; do
 
1498
        if ! [ -e "$dkms_tree/$module/$module_version/build/patches/${patch_array[$index]}" ]; then
 
1499
            echo $"" >&2
 
1500
            echo $"Error!  Patch ${patch_array[$index]} as specified in dkms.conf cannot be" >&2
 
1501
            echo $"found in $dkms_tree/$module/$module_version/build/patches/." >&2
 
1502
            exit 5
 
1503
        fi
 
1504
        invoke_command "patch -p1 < ./patches/${patch_array[$index]}" "applying patch ${patch_array[$index]}"
 
1505
        if [ "$?" -ne 0 ]; then
 
1506
            echo $"" >&2
 
1507
            echo $"Error! Application of patch ${patch_array[$index]} failed." >&2
 
1508
            echo $"Check $dkms_tree/$module/$module_version/build/ for more information." >&2
 
1509
                report_build_problem
 
1510
            exit 6
 
1511
        fi
 
1512
        index=$(($index+1))
 
1513
    done
 
1514
}
 
1515
 
 
1516
function do_build()
 
1517
{
 
1518
    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
 
1519
    echo $""
 
1520
    echo $"Building module:"
 
1521
 
 
1522
    invoke_command "$clean" "cleaning build area" background
 
1523
    echo $"DKMS make.log for $module-$module_version for kernel ${kernelver_array[0]} (${arch_array[0]})" >> "$dkms_tree/$module/$module_version/build/make.log"
 
1524
    echo $"`date`" >> "$dkms_tree/$module/$module_version/build/make.log"
 
1525
    local the_make_command=`echo $make_command | sed "s/^make/make KERNELRELEASE=${kernelver_array[0]}/"`
 
1526
 
 
1527
    invoke_command "$the_make_command >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background
 
1528
 
 
1529
    # Make sure good return status
 
1530
    if [ "$?" -ne 0 ]; then
 
1531
        echo $"" >&2
 
1532
        echo $"Error! Bad return status for module build on kernel: ${kernelver_array[0]} (${arch_array[0]})" >&2
 
1533
        echo $"Consult the make.log in the build directory" >&2
 
1534
        echo $"$dkms_tree/$module/$module_version/build/ for more information." >&2
 
1535
        if grep -ic "gcc: Command not found" "$dkms_tree/$module/$module_version/build/make.log"; then
 
1536
            echo $"" >&2
 
1537
            echo $"DO YOU HAVE gcc INSTALLED???" >&2
 
1538
        fi
 
1539
        if grep -ic "make: command not found" "$dkms_tree/$module/$module_version/build/make.log"; then
 
1540
            echo $"" >&2
 
1541
            echo $"DO YOU HAVE make INSTALLED???" >&2
 
1542
        fi
 
1543
        report_build_problem
 
1544
        exit 10
 
1545
    fi
 
1546
 
 
1547
    # Make sure all the modules built successfully
 
1548
    local count=0
 
1549
    while [ "$count" -lt "${#built_module_name[@]}" ]; do
 
1550
        if ! [ -e "${built_module_location[$count]}${built_module_name[$count]}$module_suffix" ]; then
 
1551
            echo $"" >&2
 
1552
            echo $"Error!  Build of ${built_module_name[$count]}$module_suffix failed for: ${kernelver_array[0]} (${arch_array[0]})" >&2
 
1553
            echo $"Consult the make.log in the build directory" >&2
 
1554
            echo $"$dkms_tree/$module/$module_version/build/ for more information." >&2
 
1555
            report_build_problem
 
1556
            exit 7
 
1557
        fi
 
1558
        count=$(($count+1))
 
1559
    done
 
1560
    cd - >/dev/null
 
1561
 
 
1562
    # Build success, so create DKMS structure for a built module
 
1563
    mkdir -p "$base_dir/log"
 
1564
    [ -n "$kernel_config" ] && cp -f "$kernel_config" "$base_dir/log/"
 
1565
    mv -f "$dkms_tree/$module/$module_version/build/make.log" "$base_dir/log/make.log" 2>/dev/null
 
1566
 
 
1567
    # Save a copy of the new module
 
1568
    mkdir "$base_dir/module" >/dev/null
 
1569
    local count=0
 
1570
    while [ "$count" -lt "${#built_module_name[@]}" ]; do
 
1571
        [ "${strip[$count]}" != "no" ] && strip -g "$dkms_tree/$module/$module_version/build/${built_module_location[$count]}${built_module_name[$count]}$module_suffix"
 
1572
        cp -f "$dkms_tree/$module/$module_version/build/${built_module_location[$count]}${built_module_name[$count]}$module_suffix" "$base_dir/module/${dest_module_name[$count]}$module_suffix" >/dev/null
 
1573
        count=$(($count+1))
 
1574
    done
 
1575
 
 
1576
    # Run the post_build script
 
1577
    if [ -n "$post_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_build" | sed 's/ .*//'` ]; then
 
1578
        echo $""
 
1579
        echo $"Running the post_build script:"
 
1580
        $dkms_tree/$module/$module_version/source/$post_build
 
1581
    fi
 
1582
}
 
1583
 
 
1584
function clean_build()
 
1585
{
 
1586
    # Run the clean commands
 
1587
    cd "$dkms_tree/$module/$module_version/build"
 
1588
    invoke_command "$clean" "cleaning build area" background
 
1589
    cd - >/dev/null
 
1590
 
 
1591
    if [[ ! ( $(VER ${kernelver_array[0]}) < $(VER 2.6.6) ) && \
 
1592
       -d "$kernel_source_dir" && \
 
1593
       ! -h "$kernel_source_dir" && \
 
1594
       -z "$ksourcedir_fromcli" ]]; then
 
1595
        echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
 
1596
    elif [ -z "$no_clean_kernel" ]; then
 
1597
        cd "$kernel_source_dir"
 
1598
        [ -z "$kerneldoth_contents" ] && invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
 
1599
        [ -n "$config_contents" ] && echo "$config_contents" > .config
 
1600
        [ -n "$kerneldoth_contents" ] && echo "$kerneldoth_contents" > /boot/kernel.h
 
1601
        cd - >/dev/null
 
1602
    fi
 
1603
 
 
1604
    # Clean the build directory
 
1605
    rm -rf "$dkms_tree/$module/$module_version/build/*"
 
1606
}
 
1607
 
 
1608
function build_module()
 
1609
{
 
1610
    prepare_build
 
1611
    do_build
 
1612
    clean_build
 
1613
    echo $""
 
1614
    echo $"DKMS: build Completed."
 
1615
}
 
1616
 
 
1617
function possible_dest_module_locations()
 
1618
{
 
1619
    # $1 = count
 
1620
    # There are two places an installed module may really be:
 
1621
    # 1) "$install_tree/$kernelver/${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
 
1622
    # 2) "$install_tree/$kernelver/${DEST_MODULE_LOCATION[$count]}/${dest_module_name[$count]}$module_suffix"
 
1623
    # override_dest_module_location() is what controls whether or not they're the same.
 
1624
 
 
1625
    local location
 
1626
    location[0]="${dest_module_location[$count]}"
 
1627
    [ "${DEST_MODULE_LOCATION[$count]}" != "${dest_module_location[$count]}" ] && \
 
1628
    location[1]="${DEST_MODULE_LOCATION[$count]}"
 
1629
 
 
1630
    echo "${location[0]} ${location[1]}"
 
1631
}
 
1632
 
 
1633
function find_actual_dest_module_location()
 
1634
{
 
1635
    local module="$1"
 
1636
    local count="$2"
 
1637
    local kernelver="$3"
 
1638
    local arch="$4"
 
1639
    local locations="$(possible_dest_module_locations $count)"
 
1640
    local l
 
1641
    local dkms_owned
 
1642
    local installed
 
1643
    dkms_owned="${dkms_tree}/${module}/kernel-${kernelver}-${arch}/module/${dest_module_name[$count]}${module_suffix}"
 
1644
 
 
1645
    for l in $locations; do
 
1646
        installed="${install_tree}/${kernelver}${l}/${dest_module_name[${count}]}${module_suffix}"
 
1647
        if [ -f "${installed}" ] && diff "${dkms_owned}" "${installed}" > /dev/null 2>&1; then
 
1648
            echo "${l}"
 
1649
            return 0
 
1650
        fi
 
1651
    done
 
1652
 
 
1653
}
 
1654
 
 
1655
function do_uninstall()
 
1656
{
 
1657
    # $1 = kernel version
 
1658
    # $2 = arch
 
1659
 
 
1660
    echo $""
 
1661
    echo $"-------- Uninstall Beginning --------"
 
1662
    echo $"Module:  $module"
 
1663
    echo $"Version: $module_version"
 
1664
    echo $"Kernel:  $1 ($2)"
 
1665
    echo $"-------------------------------------"
 
1666
 
 
1667
    set_module_suffix "$1"
 
1668
 
 
1669
    # If kernel-<kernelver> symlink points to this module, check for original_module and put it back
 
1670
    local was_active=""
 
1671
    readlink "$dkms_tree/$module/kernel-$1-$2"
 
1672
    local kernel_symlink="$read_link"
 
1673
    local real_dest_module_location
 
1674
    if [ "$kernel_symlink" == "$module_version/$1/$2" ]; then
 
1675
        was_active="true"
 
1676
        echo $""
 
1677
        echo $"Status: Before uninstall, this module version was ACTIVE on this kernel."
 
1678
        # remove kabi-tracking if last instance removed
 
1679
        set_weak_modules
 
1680
        if [ -n "${weak_modules}" ] &&
 
1681
            [ `$0 status -m $module -v $module_version | grep -v "installed-weak" | grep -c "installed"` -eq 1 ]; then
 
1682
            echo $"Removing any linked weak-modules"
 
1683
            list_each_installed_module "$module" "$1" "$2" | ${weak_modules} --remove-modules
 
1684
        fi
 
1685
 
 
1686
        count=0
 
1687
        while [ "$count" -lt "${#built_module_name[@]}" ]; do
 
1688
            real_dest_module_location="$(find_actual_dest_module_location $module $count $1 $2)"
 
1689
            echo $""
 
1690
            echo $"${dest_module_name[$count]}$module_suffix:"
 
1691
            echo $" - Uninstallation"
 
1692
            echo $"   - Deleting from: $install_tree/$1${real_dest_module_location}/"
 
1693
            rm -f "$install_tree/$1${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
 
1694
            echo $" - Original module"
 
1695
            if [ -e "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" ]; then
 
1696
                case "$running_distribution" in
 
1697
                Debian* | Ubuntu* ) ;;
 
1698
                *)
 
1699
                    echo $"   - Archived original module found in the DKMS tree"
 
1700
                    echo $"   - Moving it to: $install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
 
1701
                    mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
 
1702
                    mv -f "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" \
 
1703
                        "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/" 2>/dev/null
 
1704
                    ;;
 
1705
                esac
 
1706
            else
 
1707
                echo $"   - No original module was found for this module on this kernel."
 
1708
                echo $"   - Use the dkms install command to reinstall any previous module version."
 
1709
 
 
1710
                # Remove modules_conf entries from /etc/modules.conf if remake_initrd is set or if this is last instance removed
 
1711
                if [ -n "$remake_initrd" ] || \
 
1712
                    [ `$0 status -m $module -v $module_version | \
 
1713
                    grep -c "installed"` -eq 1 ]; then
 
1714
                    echo $""
 
1715
                    moduleconfig_remove "$1"
 
1716
                fi
 
1717
            fi
 
1718
            count=$(($count+1))
 
1719
        done
 
1720
        rm -f "$dkms_tree/$module/kernel-$1-$2"
 
1721
    else
 
1722
        echo $""
 
1723
        echo $"Status: This module version was INACTIVE for this kernel."
 
1724
    fi
 
1725
 
 
1726
    # Run the post_remove script
 
1727
    if [ -n "$post_remove" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_remove" | sed 's/ .*//'` ]; then
 
1728
        echo $""
 
1729
        echo $"Running the post_remove script:"
 
1730
        $dkms_tree/$module/$module_version/source/$post_remove
 
1731
    fi
 
1732
 
 
1733
    # Run depmod because we changed /lib/modules
 
1734
    invoke_command "do_depmod $1" "depmod" background
 
1735
 
 
1736
    # Do remake_initrd things (remake initrd)
 
1737
    if [ -n "$remake_initrd" ] && [ -n "$was_active" ]; then
 
1738
        remake_initrd "$1" "$2"
 
1739
        if [ "$?" -ne 0 ]; then
 
1740
            echo $""
 
1741
            echo $"WARNING! WARNING! WARNING!"
 
1742
            echo $"There was a problem remaking your initrd.  You must manually remake it"
 
1743
            echo $"before booting into this kernel."
 
1744
            echo $""
 
1745
        fi
 
1746
    fi
 
1747
 
 
1748
    # Delete the original_module if nothing for this kernel is installed anymore
 
1749
    if [ -n "$was_active" ] && [ -d "$dkms_tree/$module/original_module/$1/$2" ] && ! [ -d "$dkms_tree/$module/original_module/$1/$2/collisions" ]; then
 
1750
        echo $""
 
1751
        echo $"Removing original_module from DKMS tree for kernel $1 ($2)"
 
1752
        rm -rf "$dkms_tree/$module/original_module/$1/$2" 2>/dev/null
 
1753
        [ -z "`find $dkms_tree/$module/original_module/$1/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/original_module/$1"
 
1754
    elif [ -n "$was_active" ] && [ -d "$dkms_tree/$module/original_module/$1/$2/collisions" ]; then
 
1755
        echo $""
 
1756
        echo $"Keeping directory $dkms_tree/$module/original_module/$1/$2/collisions/"
 
1757
        echo $"for your reference purposes.  Your kernel originally contained multiple"
 
1758
        echo $"same-named modules and this directory is now where these are located."
 
1759
    fi
 
1760
    [ -z "`find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/original_module"
 
1761
 
 
1762
    # Re-add entries to modules.conf if this module/version is still installed on another kernel
 
1763
    # But only do this if it was just ACTIVE on the kernel we just uninstalled from
 
1764
    [ -n "$was_active" ] && [ -n "$remake_initrd" ] && $0 status -m $module -v $module_version | grep -q "installed" && moduleconfig_add "$1"
 
1765
 
 
1766
    echo $""
 
1767
    echo $"DKMS: uninstall Completed."
 
1768
}
 
1769
 
 
1770
function uninstall_module ()
 
1771
{
 
1772
    setup_kernels_arches "uninstall"
 
1773
 
 
1774
    # Check that the right arguments were passed
 
1775
    if [ -z "$module" ] || [ -z "$module_version" ]; then
 
1776
        echo $"" >&2
 
1777
        echo $"Error! Invalid number of parameters passed." >&2
 
1778
        echo $"Usage: uninstall -m <module> -v <module-version>" >&2
 
1779
        echo $"   or: uninstall -m <module> -v <module-version> -k <kernel-version>" >&2
 
1780
        exit 1
 
1781
    fi
 
1782
 
 
1783
    # Check that $module is in the dkms tree
 
1784
    if ! [ -d "$dkms_tree/$module" ]; then
 
1785
        echo $"" >&2
 
1786
        echo $"Error! There are no instances of module: $module" >&2
 
1787
        echo $"located in the DKMS tree." >&2
 
1788
        exit 2
 
1789
    fi
 
1790
 
 
1791
    # Make sure that its installed in the first place
 
1792
    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
 
1793
        echo $"" >&2
 
1794
        echo $"Error! The module/version combo: $module-$module_version" >&2
 
1795
        echo $"is not located in the DKMS tree." >&2
 
1796
        exit 3
 
1797
    fi
 
1798
 
 
1799
    # Read the conf file
 
1800
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
1801
    if [ "$?" -ne 0 ]; then
 
1802
        echo $"" >&2
 
1803
        echo $"Error! Bad conf file." >&2
 
1804
        echo $"Your dkms.conf is not valid." >&2
 
1805
        exit 4
 
1806
    fi
 
1807
 
 
1808
    # Only do stuff if module/module version is currently installed
 
1809
    readlink "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}"
 
1810
    local kernel_symlink="$read_link"
 
1811
    if [ "$kernel_symlink" == "$module_version/${kernelver_array[0]}/${arch_array[0]}" ]; then
 
1812
        do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
 
1813
    else
 
1814
        echo $"" >&2
 
1815
        echo $"Error! The module $module $module_version is not currently installed." >&2
 
1816
        echo $"This module is not currently ACTIVE for kernel ${kernelver_array[0]} (${arch_array[0]})." >&2
 
1817
        exit 5
 
1818
    fi
 
1819
}
 
1820
 
 
1821
function remove_module ()
 
1822
{
 
1823
    # Check that the right arguments were passed (must be done before setup_kernels_arches)
 
1824
    if [ -z "$module" ] || [ -z "$module_version" ] || $([ -z "${kernelver_array[0]}" ] && [ -z "$all" ]); then
 
1825
        echo $"" >&2
 
1826
        echo $"Error! Invalid number of parameters passed." >&2
 
1827
        echo $"Usage: remove -m <module> -v <module-version> --all" >&2
 
1828
        echo $"   or: remove -m <module> -v <module-version> -k <kernel-version>" >&2
 
1829
        exit 1
 
1830
    fi
 
1831
 
 
1832
    setup_kernels_arches "remove"
 
1833
 
 
1834
    # Check that $module is in the dkms tree
 
1835
    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
 
1836
        echo $"" >&2
 
1837
        echo $"Error! There are no instances of module: $module" >&2
 
1838
        echo $"$module_version located in the DKMS tree." >&2
 
1839
        exit 3
 
1840
    fi
 
1841
 
 
1842
    local i=0
 
1843
    while [ $i -lt ${#kernelver_array[@]} ]; do
 
1844
 
 
1845
        # make sure its there first before removing
 
1846
        if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
 
1847
            echo $"" >&2
 
1848
            echo $"Error! There is no instance of $module $module_version" >&2
 
1849
            echo $"for kernel ${kernelver_array[$i]} (${arch_array[$i]}) located in the DKMS tree." >&2
 
1850
            exit 4
 
1851
        fi
 
1852
 
 
1853
        # Do --rpm_safe_upgrade check (exit out and don't do remove if inter-release RPM upgrade scenario occurs)
 
1854
        if [ -n "$rpm_safe_upgrade" ]; then
 
1855
            local pppid=`cat /proc/$PPID/status | grep PPid: | awk {'print $2'}`
 
1856
            local time_stamp=`ps -o lstart --no-headers -p $pppid 2>/dev/null`
 
1857
            for lock_file in `ls $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.* 2>/dev/null`; do
 
1858
                lock_head=`head -n 1 $lock_file 2>/dev/null`
 
1859
                lock_tail=`tail -n 1 $lock_file 2>/dev/null`
 
1860
                if [ "$lock_head" == "$module-$module_version" ] && [ "$lock_tail" == "$time_stamp" ] && [ -n "$time_stamp" ]; then
 
1861
                    echo $""
 
1862
                    echo $"DKMS: Remove cancelled because --rpm_safe_upgrade scenario detected."
 
1863
                    rm -f $lock_file
 
1864
                    exit 0
 
1865
                fi
 
1866
            done
 
1867
        fi
 
1868
 
 
1869
        # Read the conf file
 
1870
        read_conf "${kernelver_array[$i]}" "${arch_array[$i]}"
 
1871
        if [ "$?" -ne 0 ]; then
 
1872
            echo $"" >&2
 
1873
            echo $"Error! Bad conf file." >&2
 
1874
            echo $"File: $dkms_tree/$module/$module_version/source/dkms.conf does not represent" >&2
 
1875
            echo $"a valid dkms.conf file." >&2
 
1876
            exit 5
 
1877
        fi
 
1878
 
 
1879
        do_uninstall "${kernelver_array[$i]}" "${arch_array[$i]}"
 
1880
 
 
1881
        # Delete the $kernel_version/$arch_used part of the tree
 
1882
        rm -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}"
 
1883
        [ -z "`find $dkms_tree/$module/$module_version/${kernelver_array[$i]}/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}"
 
1884
 
 
1885
        i=$(($i + 1))
 
1886
    done
 
1887
 
 
1888
    # Delete the $module_version part of the tree if no other $module_version/$kernel_version dirs exist
 
1889
    if [ -z "$(find $dkms_tree/$module/$module_version/* -maxdepth 0 -type d 2>/dev/null | egrep -v "(build|tarball|driver_disk|rpm|deb|source)$")"  ]; then
 
1890
        echo $""
 
1891
        echo $"------------------------------"
 
1892
        echo $"Deleting module version: $module_version"
 
1893
        echo $"completely from the DKMS tree."
 
1894
        echo $"------------------------------"
 
1895
        rm -rf "$dkms_tree/$module/$module_version"
 
1896
        echo $"Done."
 
1897
    fi
 
1898
 
 
1899
    # Get rid of any remnant directories if necessary
 
1900
    if [ `ls "$dkms_tree/$module" | wc -w | awk '{print $1}'` -eq 0 ]; then
 
1901
        rm -rf "$dkms_tree/$module" 2>/dev/null
 
1902
 
 
1903
        # Its now safe to completely remove references in /etc/sysconfig/kernel for SuSE
 
1904
        etc_sysconfig_kernel_modify "delete"
 
1905
    fi
 
1906
}
 
1907
 
 
1908
function find_module_from_ko()
 
1909
{
 
1910
    local depth="$1"
 
1911
    local ko="$2"
 
1912
    local basename_ko=$(basename "${ko}")
 
1913
    local module
 
1914
    local kernellink
 
1915
 
 
1916
    for kernellink in $(find $dkms_tree -maxdepth $depth -mindepth $depth -name kernel-\* -type l); do
 
1917
        module=$(echo "$kernellink" | awk -F / '{print $(NF-1)}')
 
1918
        diff "$kernellink/module/${basename_ko}" "${ko}" >/dev/null 2>&1 && echo "$module" && break
 
1919
    done
 
1920
    echo ""
 
1921
}
 
1922
 
 
1923
# be careful.  string_array is global
 
1924
declare -a string_array
 
1925
function add_string_to_array_unique()
 
1926
{
 
1927
    # string="$1"
 
1928
    local count=0
 
1929
    local found=0
 
1930
    while [ "$count" -lt "${#string_array[@]}" ]; do
 
1931
        if [ "$1" == "${string_array[$count]}" ]; then
 
1932
            found=1
 
1933
            break
 
1934
        fi
 
1935
        count=$(($count + 1))
 
1936
    done
 
1937
    if [ "${found}" -eq 0 ]; then
 
1938
        string_array[${#string_array[@]}]="$1"
 
1939
    fi
 
1940
}
 
1941
 
 
1942
function print_string_array()
 
1943
{
 
1944
    local count=0
 
1945
    while [ "$count" -lt "${#string_array[@]}" ]; do
 
1946
        echo "${string_array[$count]}"
 
1947
        count=$(($count + 1))
 
1948
    done
 
1949
}
 
1950
 
 
1951
function do_status_weak ()
 
1952
{
 
1953
    # these are the requested mod/ver/kern/arch fields
 
1954
    local r_mod="$1"; shift
 
1955
    local r_ver="$1"; shift
 
1956
    local r_kern="$1"; shift
 
1957
    local r_arch="$1"; shift
 
1958
    local installedkern
 
1959
    local ko
 
1960
    local basename_ko
 
1961
    local installed_ko
 
1962
    local tree_ver
 
1963
    local tree_kern
 
1964
    local tree_arch
 
1965
    local f
 
1966
    local depth=1
 
1967
    [ -z "$r_mod" ] && depth=2
 
1968
    # recognize weak modules.  These are in $kern/weak-updates but are symlinks to another $kern/extra file.
 
1969
 
 
1970
    for installedkern in $(find "$install_tree" -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
 
1971
        for ko in $(find "$installedkern/weak-updates" -type l 2>/dev/null); do
 
1972
            installedkernver=$(basename $installedkern)
 
1973
            basename_ko=$(basename $ko)
 
1974
            readlink $ko
 
1975
            installed_ko="$read_link"
 
1976
            if [ ! -e "$installed_ko" ]; then
 
1977
                # dangling symlink, ouch, but is somebody else's problem so ignore it
 
1978
                continue
 
1979
            fi
 
1980
            # remember, installed_ko is probably a relative path, so $kernelversion isn't present in its link
 
1981
            # is $installed_ko in /var/lib/dkms as installed?  Find which module has it
 
1982
            for f in $(find $dkms_tree/$r_mod -maxdepth $depth -mindepth $depth -name kernel-\* -type l 2>/dev/null); do
 
1983
                if [ -z "$r_mod" ]; then
 
1984
                    mod=$(find_module_from_ko "$depth" "$ko")
 
1985
                else
 
1986
                    mod="$r_mod"
 
1987
                fi
 
1988
                readlink "$f"
 
1989
                tree_ver=$(echo "$read_link" | awk -F / '{print $1}')
 
1990
                tree_kern=$(echo "$read_link" | awk -F / '{print $2}')
 
1991
                tree_arch=$(echo "$read_link" | awk -F / '{print $3}')
 
1992
                if diff $dkms_tree/$mod/$tree_ver/$tree_kern/$tree_arch/module/$basename_ko  \
 
1993
                    $installed_ko >/dev/null 2>&1; then
 
1994
                    if [ "$r_mod" == "$mod" -o -z "$r_mod" ] && \
 
1995
                        [ "$r_ver" == "$tree_ver" -o -z "$r_ver" ] && \
 
1996
                        [ "$r_kern" == "$installedkernver" -o -z "$r_kern" ] && \
 
1997
                        [ "$r_arch" == "$tree_arch" -o -z "$r_arch" ]; then
 
1998
                        add_string_to_array_unique "$mod, $tree_ver, $installedkernver, $tree_arch: installed-weak from $tree_kern"
 
1999
                    fi
 
2000
                fi
 
2001
            done
 
2002
        done
 
2003
    done
 
2004
    print_string_array
 
2005
}
 
2006
 
 
2007
do_status ()
 
2008
{
 
2009
    local mod="$1"; shift
 
2010
    local ver="$1"; shift
 
2011
    local kern="$1"; shift
 
2012
    local arch="$1"; shift
 
2013
    local tree_depth="$1"; shift
 
2014
 
 
2015
    local next
 
2016
    local working_dir
 
2017
    [ $tree_depth -eq 0 ] && next="mod"  && working_dir="$dkms_tree"
 
2018
    [ $tree_depth -eq 1 ] && next="ver"  && working_dir="$dkms_tree/$mod"
 
2019
    [ $tree_depth -eq 2 ] && next="kern" && working_dir="$dkms_tree/$mod/$ver"
 
2020
    [ $tree_depth -eq 3 ] && next="arch" && working_dir="$dkms_tree/$mod/$ver/$kern"
 
2021
    [ $tree_depth -eq 4 ] && next="done" && working_dir="$dkms_tree/$mod/$ver/$kern/$arch"
 
2022
 
 
2023
    if [ -n "${!next}" ] && [ "$next" != "done" ]; then
 
2024
        do_status "$mod" "$ver" "$kern" "$arch" "$(($tree_depth + 1))"
 
2025
    elif [ "$next" != "done" ]; then
 
2026
        local keep_traversing="no"
 
2027
        for directory in `find "$working_dir" -type d -maxdepth 1 -mindepth 1 2>/dev/null`; do
 
2028
            local next_value=`echo $directory | sed "s#$working_dir/##"`
 
2029
            if ! echo "build original_module tarball driver_disk rpm" | grep -q "$next_value\b"; then
 
2030
                keep_traversing="yes"
 
2031
                [ "$next" == "mod" ]  && mod=$next_value
 
2032
                [ "$next" == "ver" ]  && ver=$next_value
 
2033
                [ "$next" == "kern" ] && kern=$next_value
 
2034
                [ "$next" == "arch" ] && arch=$next_value
 
2035
                do_status "$mod" "$ver" "$kern" "$arch" "$(($tree_depth + 1))"
 
2036
            fi
 
2037
        done
 
2038
    fi
 
2039
 
 
2040
    if [ "$keep_traversing" == "no" ] && [ $tree_depth -eq 2 ] && [ -z "$arch" ] || [ "$next" == "done" ]; then
 
2041
        local state="added" && stat_display="$mod, $ver:"
 
2042
        [ -d "$working_dir/module" ] && state="built" && stat_display="$mod, $ver, $kern, $arch:"
 
2043
        if [ -h "$dkms_tree/$mod/kernel-$kern-$arch" ]; then
 
2044
            readlink "$dkms_tree/$mod/kernel-$kern-$arch"
 
2045
            [ "$read_link" == "$ver/$kern/$arch" ] && state="installed"
 
2046
        fi
 
2047
 
 
2048
        if [ "$state" == "built" ] || [ "$state" == "installed" ]; then
 
2049
            set_module_suffix "$kern"
 
2050
            local extra_status=""
 
2051
            conf="$dkms_tree/$mod/$ver/source/dkms.conf"
 
2052
            read_conf "$kern" "$arch" "$conf"
 
2053
            [ -d "$dkms_tree/$mod/original_module/$kern/$arch" ] && extra_status="(original_module exists)"
 
2054
            local count=0
 
2055
            local real_dest_module_location
 
2056
            while [ "$count" -lt "${#dest_module_name[@]}" ]; do
 
2057
                tree_mod="$dkms_tree/$mod/$ver/$kern/$arch/module/${dest_module_name[$count]}$module_suffix"
 
2058
                if ! [ -e "$tree_mod" ]; then
 
2059
                    extra_status="$extra_status (WARNING! Missing some built modules!)"
 
2060
                elif [ "$state" == "installed" ]; then
 
2061
                    real_dest_module_location="$(find_actual_dest_module_location $mod $count $kern $arch)"
 
2062
                    if ! diff -q "$tree_mod" "$install_tree/$kern${real_dest_module_location}/${dest_module_name[$count]}$module_suffix" >/dev/null 2>&1; then
 
2063
                        extra_status="$extra_status (WARNING! Diff between built and installed module!)"
 
2064
                    fi
 
2065
                fi
 
2066
                count=$(($count+1))
 
2067
            done
 
2068
        fi
 
2069
 
 
2070
        [ -d "$working_dir" ] && echo "$stat_display $state $extra_status"
 
2071
    fi
 
2072
}
 
2073
 
 
2074
show_status ()
 
2075
{
 
2076
    setup_kernels_arches "status"
 
2077
 
 
2078
    local j=0
 
2079
    if [ ${#kernelver_array[@]} -eq 0 ]; then
 
2080
        do_status "$module" "$module_version" "${kernelver_array[0]}" "${arch_array[0]}" 0
 
2081
        do_status_weak "$module" "$module_version" "${kernelver_array[0]}" "${arch_array[0]}"
 
2082
    else
 
2083
        while [ $j -lt ${#kernelver_array[@]} ]; do
 
2084
            do_status "$module" "$module_version" "${kernelver_array[$j]}" "${arch_array[$j]}" 0
 
2085
            do_status_weak "$module" "$module_version" "${kernelver_array[$j]}" "${arch_array[$j]}"
 
2086
            j=$(($j + 1))
 
2087
        done
 
2088
    fi
 
2089
}
 
2090
 
 
2091
function create_temporary_trees ()
 
2092
{
 
2093
    if [ -n "$module" ] || [ -n "$module_version" ]; then
 
2094
        return
 
2095
    fi
 
2096
 
 
2097
    [ -r dkms.conf ] || return
 
2098
 
 
2099
    . dkms.conf
 
2100
    module="$PACKAGE_NAME"
 
2101
    module_version="$PACKAGE_VERSION"
 
2102
 
 
2103
    source_tree=`mktemp -d`
 
2104
    dkms_tree=`mktemp -d`
 
2105
 
 
2106
    local source_tree_dir="$source_tree/$PACKAGE_NAME-$PACKAGE_VERSION"
 
2107
    mkdir -p "$source_tree_dir"
 
2108
    cp -a * "$source_tree_dir" # intentionally skip .git or .hg
 
2109
    add_module
 
2110
    temporary_trees_del_command="rm -rf $source_tree $dkms_tree"
 
2111
}
 
2112
 
 
2113
function delete_temporary_trees ()
 
2114
{
 
2115
    $temporary_trees_del_command
 
2116
    if [ -n "$temporary_trees_del_command" ]; then
 
2117
        module=
 
2118
        module_version=
 
2119
        source_tree=
 
2120
        dkms_tree=
 
2121
        temporary_trees_del_command=
 
2122
    fi
 
2123
}
 
2124
 
 
2125
function in_temporary_trees ()
 
2126
{
 
2127
    [ -n "$temporary_trees_del_command" ]
 
2128
    return $?
 
2129
}
 
2130
 
 
2131
media_valid()
 
2132
{
 
2133
    if [ "$media" == "floppy" ] ||
 
2134
        [ "$media" == "iso"   ] ||
 
2135
        [ "$media" == "tar" ]; then
 
2136
        return 0
 
2137
    fi
 
2138
    return 1
 
2139
}
 
2140
 
 
2141
make_driver_disk ()
 
2142
{
 
2143
    setup_kernels_arches "mkdriverdisk"
 
2144
 
 
2145
    # Check that the right arguments were passed
 
2146
    if [ -z "$module" ] || [ -z "$module_version" ] || [ -z "$distro" ] || [ -z "${kernelver_array[0]}" ]; then
 
2147
        echo $"" >&2
 
2148
        echo $"Error! Invalid number of parameters passed." >&2
 
2149
        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver> [--media floppy|iso|tar]" >&2
 
2150
        exit 1
 
2151
    fi
 
2152
 
 
2153
    # default to floppy media
 
2154
    [ -z "$media" ] && media="floppy"
 
2155
    media_valid
 
2156
    if [ $? -eq 1 ]; then
 
2157
        echo $"" >&2
 
2158
        echo "$Error! Media $media is invalid." >&2
 
2159
        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver> [--media floppy|iso|tar]" >&2
 
2160
        exit 1
 
2161
    fi
 
2162
 
 
2163
    # Check that source symlink works
 
2164
    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
 
2165
        echo $"" >&2
 
2166
        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
 
2167
        echo $"Build cannot continue without the proper tree." >&2
 
2168
        exit 2
 
2169
    fi
 
2170
 
 
2171
    # Confirm that distro is supported
 
2172
    case "$distro" in
 
2173
    redhat | redhat[12] | suse | UnitedLinux | ubuntu)
 
2174
        ;;
 
2175
    *)
 
2176
        echo $"" >&2
 
2177
        echo $"Error! Invalid distro argument. Currently, the distros" >&2
 
2178
        echo $"supported are: redhat, redhat1, redhat2, suse, UnitedLinux" >&2
 
2179
        echo $"               ubuntu" >&2
 
2180
        exit 3
 
2181
        ;;
 
2182
    esac
 
2183
 
 
2184
    # Read the conf file
 
2185
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
2186
    if [ "$?" -ne 0 ]; then
 
2187
        echo $"" >&2
 
2188
        echo $"Error! Bad conf file." >&2
 
2189
        echo $"Your dkms.conf is not valid." >&2
 
2190
        exit 4
 
2191
    fi
 
2192
 
 
2193
    case "$distro" in
 
2194
    redhat*)
 
2195
        make_redhat_driver_disk
 
2196
        ;;
 
2197
    ubuntu)
 
2198
        make_ubuntu_driver_disk
 
2199
        ;;
 
2200
    *)
 
2201
        make_suse_driver_disk
 
2202
        ;;
 
2203
    esac
 
2204
}
 
2205
 
 
2206
 
 
2207
make_driver_disk_floppy()
 
2208
{
 
2209
    local image_name="$1"
 
2210
    local source_dir="$2"
 
2211
    local file
 
2212
    local fs='ext2'
 
2213
    case "$distro" in
 
2214
    redhat*)
 
2215
        fs='vfat'
 
2216
        ;;
 
2217
    esac
 
2218
 
 
2219
    rm -f "$image_name"
 
2220
    invoke_command "dd if=/dev/zero of=$image_name bs=$(($size/20))k count=20" "making a blank floppy image" background
 
2221
    if [ "$fs" == 'vfat' ]; then
 
2222
        invoke_command "mkdosfs $image_name" "mkdosfs" background
 
2223
    elif [ "$fs" == 'ext2' ]; then
 
2224
        invoke_command "mke2fs -F $image_name" "mke2fs" background
 
2225
    fi
 
2226
 
 
2227
    local mntdir=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2228
    if [ -z "$mntdir" ]; then
 
2229
        echo $""
 
2230
        echo $"Error: Could not create a temporary directory, failing."
 
2231
        return
 
2232
    fi
 
2233
    invoke_command "mount -o loop -t $fs $image_name $mntdir >/dev/null 2>&1" "loopback mounting disk image"
 
2234
    [ -d "$mntdir/lost+found" ] && rmdir "$mntdir/lost+found"
 
2235
    invoke_command "cp -r $source_dir/* $mntdir/" "  copying files to floppy disk image"
 
2236
    invoke_command "umount $mntdir" "unmounting disk image"
 
2237
    rm -rf $mntdir
 
2238
}
 
2239
 
 
2240
make_driver_disk_isotar()
 
2241
{
 
2242
    local type="$1"
 
2243
    local image_name="$2"
 
2244
    local source_dir="$3"
 
2245
    local file
 
2246
    if [ "$type" == "iso" ]; then
 
2247
        invoke_command "mkisofs -v -r -J -pad -V $module -o $image_name ." "mkisofs" background
 
2248
    elif [ "$type" == "tar" ]; then
 
2249
        invoke_command "tar cvf $image_name ." "tar" background
 
2250
    fi
 
2251
}
 
2252
 
 
2253
make_driver_disk_media()
 
2254
{
 
2255
    echo "Copying files $2"
 
2256
 
 
2257
    case "$media" in
 
2258
    floppy*)
 
2259
        make_driver_disk_floppy "$1" "$2"
 
2260
        ;;
 
2261
    iso*)
 
2262
        make_driver_disk_isotar "iso" "$1" "$2"
 
2263
        ;;
 
2264
    tar*)
 
2265
        make_driver_disk_isotar "tar" "$1" "$2"
 
2266
        ;;
 
2267
    esac
 
2268
}
 
2269
 
 
2270
driver_disk_suffix()
 
2271
{
 
2272
    local suffix
 
2273
    case "$media" in
 
2274
    floppy*)
 
2275
        suffix="img"
 
2276
        ;;
 
2277
    iso*)
 
2278
        suffix="iso"
 
2279
        ;;
 
2280
    tar*)
 
2281
        suffix="tar"
 
2282
        ;;
 
2283
    esac
 
2284
    echo $suffix
 
2285
}
 
2286
 
 
2287
make_redhat_driver_disk()
 
2288
{
 
2289
    # kludge to allow redhat1 driver disks with BOOT kernel modules (arch i386)
 
2290
    if [ "$distro" == "redhat1" ] && [ "$multi_arch" == "true" ]; then
 
2291
        local i=0
 
2292
        local redhat1_okay="true"
 
2293
        local other_arch=""
 
2294
        while [ $i -lt ${#kernelver_array[@]} ]; do
 
2295
            if [ "${arch_array[$i]}" != "i386" ] && [ "$other_arch" != "${arch_array[$i]}" ] && [ -n "$other_arch" ]; then
 
2296
                redhat1_okay="false"
 
2297
            elif [ "${arch_array[$i]}" != "i386" ] && [ "$other_arch" != "${arch_array[$i]}" ] && [ -z "$other_arch" ]; then
 
2298
                other_arch="${arch_array[$i]}"
 
2299
            fi
 
2300
            i=$(($i+1))
 
2301
        done
 
2302
        if [ "$redhat1_okay" == "false" ]; then
 
2303
            echo $"" >&2
 
2304
            echo $"Error! You have specified a Red Hat version 1 driver disk, but have also"  >&2
 
2305
            echo $"specified multiple architectures.  Version 1 does not support this." >&2
 
2306
            echo $"Use 'redhat2' instead (only OSes >= RHEL3, FC1 support version 2)." >&2
 
2307
            exit 3
 
2308
        fi
 
2309
    fi
 
2310
 
 
2311
    if [ "$distro" == "redhat2" ] || [ "$multi_arch" == "true" ] && [ -z "$redhat1_okay" ]; then
 
2312
        echo $"Creating Red Hat v2 driver disk (arch support)."
 
2313
        echo $""
 
2314
        local rhdd_filename="rhdd"
 
2315
    else
 
2316
        echo $"Creating Red Hat v1 driver disk."
 
2317
        echo $""
 
2318
        local rhdd_filename="rhdd-6.1"
 
2319
    fi
 
2320
 
 
2321
    cpioarchive_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2322
    if [ -z "$cpioarchive_dir_name" ]; then
 
2323
        echo $""
 
2324
        echo $"Error: Could not create a temporary directory, failing."
 
2325
        return
 
2326
    fi
 
2327
 
 
2328
    local i=0
 
2329
    while [ $i -lt ${#kernelver_array[@]} ]; do
 
2330
        set_module_suffix "${kernelver_array[$i]}"
 
2331
        local count=0
 
2332
 
 
2333
        local dd_prefix="${kernelver_array[$i]}"
 
2334
        [ "$distro" == "redhat2" ] && dd_prefix="${kernelver_array[$i]}/${arch_array[$i]}"
 
2335
        [ "$multi_arch" == "true" ] && [ -z "$redhat1_okay" ] && dd_prefix="${kernelver_array[$i]}/${arch_array[$i]}"
 
2336
 
 
2337
        while [ "$count" -lt "${#dest_module_name[@]}" ]; do
 
2338
            if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
 
2339
                echo $"" >&2
 
2340
                echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
 
2341
                echo $"Module/version must be in built state before making a driver disk." >&2
 
2342
                rm -rf $cpioarchive_dir_name
 
2343
                exit 5
 
2344
            fi
 
2345
            # FIXME: add check for KMP binary RPMs to include in the driver disk
 
2346
            if [ -z "$kernel_version_list" ]; then
 
2347
                kernel_version_list="kernel${kernelver_array[$i]}-${arch_array[$i]}"
 
2348
            else
 
2349
                kernel_version_list="$kernel_version_list-kernel${kernelver_array[$i]}-${arch_array[$i]}"
 
2350
            fi
 
2351
            mkdir -p $cpioarchive_dir_name/$dd_prefix
 
2352
            echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix..."
 
2353
            cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$cpioarchive_dir_name/$dd_prefix/"
 
2354
 
 
2355
            modules_cgz_list="$dd_prefix/${dest_module_name[$count]}$module_suffix\n${modules_cgz_list}"
 
2356
            count=$(($count+1))
 
2357
        done
 
2358
 
 
2359
        i=$(($i + 1))
 
2360
    done
 
2361
 
 
2362
    # Create directory and necessary files
 
2363
    driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2364
    if [ -z "$driver_disk_dir" ]; then
 
2365
        echo $""
 
2366
        echo $"Error: Could not create a temporary directory, failing."
 
2367
        return
 
2368
    fi
 
2369
 
 
2370
    # Copy files for the driver disk (or warn if not present)
 
2371
    local files_for_driverdisk="modinfo disk-info modules.dep pcitable modules.pcimap pci.ids"
 
2372
    # Fedora Core 5 and higher, RHEL5 and higher, strictly require: rhdd, modules.cgz, modinfo, modules.alias, modules.dep
 
2373
    # which is in effect ignoring disk-info, pcitable, modules.pcimap and pci.ids
 
2374
    # and adding modules.alias, which will be generated.
 
2375
 
 
2376
    local files_into_driverdisk="modules.cgz $rhdd_filename modules.alias"
 
2377
    for file in $files_for_driverdisk; do
 
2378
        if ! [ -e "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" ]; then
 
2379
            echo $"Warning! File: $file not found in $dkms_tree/$module/$module_version/source/redhat_driver_disk/" >&2
 
2380
        else
 
2381
            files_into_driverdisk="$file $files_into_driverdisk"
 
2382
            cp -f "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" "$driver_disk_dir/" 2>/dev/null
 
2383
        fi
 
2384
    done
 
2385
    echo "$module-$module_version driver disk" > "$driver_disk_dir/$rhdd_filename"
 
2386
 
 
2387
    # Make sure the kernel_version_list is not too long
 
2388
    if [ `echo $kernel_version_list | wc -m | awk {'print $1'}` -gt 200 ]; then
 
2389
        kernel_version_list="manykernels"
 
2390
    fi
 
2391
 
 
2392
    local suffix="$(driver_disk_suffix)"
 
2393
    local image_dir="$dkms_tree/$module/$module_version/driver_disk"
 
2394
    local image_name="$module-$module_version-$kernel_version_list-dd.$suffix"
 
2395
    echo $""
 
2396
    echo $"Creating driver disk on $media media:"
 
2397
    cd "$cpioarchive_dir_name"
 
2398
    invoke_command "echo -e '$modules_cgz_list' | cpio -oH crc 2>/dev/null | gzip -9 > ./modules.cgz" "compressing modules.cgz" background
 
2399
    cp -f ./modules.cgz "$driver_disk_dir/"
 
2400
 
 
2401
    # generate modules.alias file
 
2402
    # On 2.4 kernels and kernels with no aliases. this won't yield anything.
 
2403
    touch ./modules.alias
 
2404
    for f in $(echo -e ${modules_cgz_list}); do
 
2405
        module_wo_suffix=$(basename ${f} ${module_suffix})
 
2406
        tmp_alias="./modules.alias.${module_wo_suffix}"
 
2407
        f="./${f}"
 
2408
        depmod -n ${f} 2>/dev/null | grep ^alias > ${tmp_alias}
 
2409
        if [ -s ${tmp_alias} ]; then
 
2410
            cat ${tmp_alias} >> ./modules.alias
 
2411
        fi
 
2412
    done
 
2413
    [ -e ./modules.alias ] && cp -f ./modules.alias "$driver_disk_dir/"
 
2414
 
 
2415
    # FIXME: add rpms/ directory, copy in KMP RPMs, run createrepo --pretty
 
2416
 
 
2417
    cd - >/dev/null
 
2418
    rm -rf "$cpioarchive_dir_name"
 
2419
 
 
2420
    mkdir -p "$image_dir"
 
2421
    rm -f "$image_dir/$image_name"
 
2422
 
 
2423
    cd "$driver_disk_dir"
 
2424
    make_driver_disk_media "$image_dir/$image_name" "$driver_disk_dir"
 
2425
    cd - >/dev/null
 
2426
    rm -rf "$driver_disk_dir"
 
2427
 
 
2428
    echo $""
 
2429
    echo $"Disk image location: $image_dir/$image_name"
 
2430
    echo $""
 
2431
    echo $"DKMS: mkdriverdisk Completed."
 
2432
}
 
2433
 
 
2434
find_external_dependencies()
 
2435
{
 
2436
    local mod deps
 
2437
    local count=0
 
2438
    local i=0
 
2439
 
 
2440
    # find all module dependencies
 
2441
    while [ "$count" -lt "${#dest_module_name[@]}" ]; do
 
2442
        i=0
 
2443
        while [ "$i" -lt "${#kernelver_array[@]}" ]; do
 
2444
            set_module_suffix "${kernelver_array[$i]}"
 
2445
            mod="$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix"
 
2446
            deps=(${deps[@]} $(modinfo "$mod" | sed -n 's/,/ /g; s/^depends: *//p'))
 
2447
            i=$(($i+1))
 
2448
        done
 
2449
        count=$(($count+1))
 
2450
    done
 
2451
 
 
2452
    # prune internally satisfied dependencies
 
2453
    i=0
 
2454
    while [ "$i" -lt "${#deps[@]}" ]; do
 
2455
        for mod in ${dest_module_name[@]}; do
 
2456
            [ "${deps[i]}" == "$mod" ] && deps[i]=
 
2457
        done
 
2458
        i=$(($i+1))
 
2459
    done
 
2460
 
 
2461
    i=0
 
2462
    while [ "$i" -lt "${#deps[@]}" ]; do
 
2463
        echo "${deps[i]}"
 
2464
        i=$(($i+1))
 
2465
    done | sort -u
 
2466
}
 
2467
 
 
2468
make_suse_driver_disk()
 
2469
{
 
2470
    if [ -z "$release" ]; then
 
2471
        echo $"" >&2
 
2472
        echo $"Error! Invalid number of parameters passed for suse/UnitedLinux driver disk." >&2
 
2473
        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver>" >&2
 
2474
        echo $"                    -r <release-number>" >&2
 
2475
        exit 3
 
2476
    fi
 
2477
 
 
2478
    local driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2479
    if [ -z "$driver_disk_dir" ]; then
 
2480
        echo $""
 
2481
        echo $"Error: Could not create a temporary directory, failing."
 
2482
        return
 
2483
    fi
 
2484
    local suffix="$(driver_disk_suffix)"
 
2485
    local image_dir="$dkms_tree/$module/$module_version/driver_disk"
 
2486
    local image_name="$module-$module_version-$distro-$release-dd.$suffix"
 
2487
 
 
2488
    echo $""
 
2489
    echo $"Creating driver disk:"
 
2490
 
 
2491
    local deps="$(find_external_dependencies)"
 
2492
 
 
2493
    local offset=0
 
2494
    if [ -n "${deps[*]}" ]; then
 
2495
        # reserve a place for dependencies
 
2496
        local offset=1
 
2497
    fi
 
2498
 
 
2499
    local count=0
 
2500
    while [ "$count" -lt "${#dest_module_name[@]}" ]; do
 
2501
 
 
2502
        local i=0
 
2503
        local topdir=`printf "%02d" $(($count+1+offset))`
 
2504
        while [ "$i" -lt "${#kernelver_array[@]}" ]; do
 
2505
            set_module_suffix "${kernelver_array[$i]}"
 
2506
 
 
2507
            if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
 
2508
                echo $"" >&2
 
2509
                echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
 
2510
                echo $"Module/version must be in built state before making a driver disk." >&2
 
2511
                rm -rf $temp_dir_name
 
2512
                exit 5
 
2513
            fi
 
2514
                        # FIXME: add check for KMP binary RPMs to include in the driver disk
 
2515
            suse_arch=${arch_array[$i]}
 
2516
            case $suse_arch in
 
2517
            i?86)
 
2518
                    suse_arch=i386
 
2519
                    ;;
 
2520
            esac
 
2521
 
 
2522
            echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/modules/${dest_module_name[$count]}$module_suffix..."
 
2523
            mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver_array[$i]}${dest_module_location[$count]}"
 
2524
            cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver_array[$i]}${dest_module_location[$count]}/"
 
2525
 
 
2526
            case ${kernelver_array[$i]} in
 
2527
                *-default)
 
2528
                    mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
 
2529
                    cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
 
2530
                    ;;
 
2531
            esac
 
2532
 
 
2533
            # create directory for dependency information
 
2534
            [ -n "${deps[*]}" ] && mkdir -p "$driver_disk_dir/01/linux/$distro/$suse_arch-$release/modules"
 
2535
 
 
2536
            i=$(($i+1))
 
2537
        done
 
2538
 
 
2539
        # ---
 
2540
        for arch_release in `find $driver_disk_dir/$topdir -maxdepth 1 -mindepth 1 -type d | sed "s#$driver_disk_dir\/$topdir\/##"`; do
 
2541
            cd "$driver_disk_dir/$topdir/$arch_release/install/"
 
2542
            invoke_command "tar cvzf update.tar.gz lib/" "making update.tar.gz for $arch_release" background
 
2543
            cd - >/dev/null
 
2544
 
 
2545
            mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install"
 
2546
            mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/modules"
 
2547
 
 
2548
            echo $"  copying update.tar.gz for $arch_release to disk image..."
 
2549
            cp -f "$driver_disk_dir/$topdir/$arch_release/install/update.tar.gz" "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/"
 
2550
 
 
2551
            i=0
 
2552
            postkernels=
 
2553
            archtest=`echo ${arch_release} | sed 's/-.*//'`
 
2554
            while [ "$i" -lt "${#kernelver_array[@]}" ]; do
 
2555
                if [ "${arch_array[$i]}" = "${archtest}" ]; then
 
2556
                    postkernels="${postkernels} ${kernelver_array[$i]}"
 
2557
                fi
 
2558
                i=$(($i+1))
 
2559
            done
 
2560
 
 
2561
            if [ -n "${postkernels}" ]; then
 
2562
                dstfile="$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/update.post"
 
2563
                echo $"  creating update.post for $arch_release..."
 
2564
                (cat << EOF
 
2565
#!/bin/sh
 
2566
 
 
2567
EOF
 
2568
                 echo "kernlist=\"${postkernels}\""
 
2569
                 echo
 
2570
                 echo 'for kernel in ${kernlist}; do'
 
2571
                 echo ' if [ -e /boot/System.map-${kernel} ]; then'
 
2572
                 echo '         depmod -a -F /boot/System.map-${kernel} ${kernel}'
 
2573
                 echo ' fi'
 
2574
                 echo 'done'
 
2575
                ) > ${dstfile}
 
2576
                chmod a+x ${dstfile}
 
2577
            fi
 
2578
 
 
2579
            if [ -d "$driver_disk_dir/$topdir/$arch_release/modules/" ]; then
 
2580
                echo $"  copying kernel modules for installation kernel to disk image..."
 
2581
                cp -f $driver_disk_dir/$topdir/$arch_release/modules/* $driver_disk_dir/$topdir/linux/$distro/$arch_release/modules/ 2>/dev/null
 
2582
            else
 
2583
                echo $"  Warning! No kernel modules found for -default kernel."
 
2584
            fi
 
2585
 
 
2586
            rm -fr "$driver_disk_dir/$topdir/$arch_release"
 
2587
        done
 
2588
 
 
2589
        # ---
 
2590
        count=$(($count+1))
 
2591
    done
 
2592
 
 
2593
    local dir
 
2594
    if [ -n "${deps[*]}" ]; then
 
2595
        for dir in "$driver_disk_dir/01/linux/$distro/"*"/modules"; do
 
2596
            for dep in ${deps[@]}; do
 
2597
                echo $dep >> "$dir/module.order"
 
2598
            done
 
2599
        done
 
2600
    fi
 
2601
 
 
2602
    # FIXME: add suse-equivalent rpms/ directory, copy in KMP RPMs, run createrepo --pretty
 
2603
 
 
2604
    mkdir -p "$image_dir"
 
2605
    rm -f "$image_dir/$image_name"
 
2606
    cd "$driver_disk_dir"
 
2607
    make_driver_disk_media "$image_dir/$image_name" "$driver_disk_dir"
 
2608
    cd - >/dev/null
 
2609
    rm -rf "$driver_disk_dir"
 
2610
 
 
2611
    echo $""
 
2612
    echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
 
2613
    echo $""
 
2614
    echo $"DKMS: mkdriverdisk Completed."
 
2615
}
 
2616
 
 
2617
make_ubuntu_driver_disk()
 
2618
{
 
2619
    local suffix="$(driver_disk_suffix)"
 
2620
    local image_dir="$dkms_tree/$module/$module_version/driver_disk"
 
2621
    local image_name="$module-$module_version-$distro-dd.$suffix"
 
2622
 
 
2623
    local tempdir=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2624
    if [ -z "$tempdir" ]; then
 
2625
        echo $""
 
2626
        echo $"Error: Could not create a temporary directory, failing."
 
2627
        return
 
2628
    fi
 
2629
 
 
2630
   # Check that the dh_make command is present
 
2631
   if ! which dpkg-deb >/dev/null 2>&1 ; then
 
2632
        echo $"" >&2
 
2633
        echo $"Error! dpkg-deb not present." >&2
 
2634
        echo $"Install the dpkg-dev package." >&2
 
2635
        exit 1
 
2636
   fi
 
2637
 
 
2638
   local i=0
 
2639
   while [ $i -lt ${#kernelver_array[@]} ]; do
 
2640
      set_module_suffix "${kernelver_array[$i]}"
 
2641
      # Driver disks only recognize i386 as package arch
 
2642
      local arch=$(echo ${arch_array[$i]} | sed -e 's/i.86/i386/')
 
2643
      local kvers=$(echo ${kernelver_array[$i]} | sed -e 's/[-_].*//')
 
2644
       # ubuntu-drivers/<kver>/*_<debarch>.deb
 
2645
      local dd_prefix="ubuntu-drivers/$kvers"
 
2646
      local dd_suffix="_${arch}.deb"
 
2647
      local count=0
 
2648
      while [ "$count" -lt "${#dest_module_name[@]}" ]; do
 
2649
        if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
 
2650
            echo $"" >&2
 
2651
            echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
 
2652
            echo $"Module/version must be in built state before making a driver disk." >&2
 
2653
            rm -rf "$tempdir"
 
2654
            exit 5
 
2655
         fi
 
2656
 
 
2657
         mkdir -p "$tempdir/$dd_prefix"
 
2658
         echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix..."
 
2659
 
 
2660
         local deb_dir="$tempdir/$dd_prefix/debian"
 
2661
         local deb_lib_dir="$deb_dir/lib/modules/${kernelver_array[$i]}/updates/dkms"
 
2662
         mkdir -p "$deb_lib_dir"
 
2663
         cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$deb_lib_dir"
 
2664
         count=$(($count+1))
 
2665
       done
 
2666
 
 
2667
       pushd "$deb_dir" > /dev/null 2>&1
 
2668
       mkdir DEBIAN
 
2669
       cat > DEBIAN/control <<EOF
 
2670
Package: ${module}-modules-${kernelver_array[$i]}
 
2671
Version: ${module_version}-1
 
2672
Section: misc
 
2673
Priority: optional
 
2674
Architecture: $arch
 
2675
Depends:
 
2676
Maintainer: DKMS <dkms-devel@dell.com>
 
2677
Description: DKMS packaged binary driver update
 
2678
 DKMS automagically generated debian package for
 
2679
 driver update disks, used with Ubuntu installation
 
2680
 programs (such as Ubiquity).
 
2681
EOF
 
2682
 
 
2683
       # Generate the DEBIAN/preinst file.
 
2684
       # This is tricky as we need some parts evaluated now
 
2685
       # and some parts evaluated at runtime
 
2686
       echo '#!/bin/bash' > DEBIAN/preinst
 
2687
       echo -n '[ "$(uname -r)" == ' >> DEBIAN/preinst
 
2688
       echo -n "\"${kernelver_array[$i]}\"" >> DEBIAN/preinst
 
2689
       echo  ' ] || exit 1' >> DEBIAN/preinst
 
2690
       echo 'exit 0' >> DEBIAN/preinst
 
2691
 
 
2692
       chmod 0775 DEBIAN/preinst
 
2693
       cd "$tempdir/$dd_prefix"
 
2694
       dpkg-deb --build debian
 
2695
       mv debian.deb "${module}_${module_version}-${kernelver_array[$i]}${dd_suffix}"
 
2696
       rm -rf debian
 
2697
       popd > /dev/null 2>&1
 
2698
       i=$(($i+1))
 
2699
   done
 
2700
 
 
2701
   echo "Copying source..."
 
2702
   mkdir -p "$tempdir/ubuntu"
 
2703
   cp -ar "$source_tree/$module-$module_version" "$tempdir/ubuntu/"
 
2704
 
 
2705
   mkdir -p "$image_dir"
 
2706
   rm -f "$image_dir/$image_name"
 
2707
   cd "$tempdir"
 
2708
   make_driver_disk_media "$image_dir/$image_name" "$tempdir"
 
2709
   cd - >/dev/null
 
2710
   rm -rf "$tempdir"
 
2711
   echo $""
 
2712
   echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
 
2713
   echo $""
 
2714
   echo $"DKMS: mkdriverdisk Completed."
 
2715
}
 
2716
 
 
2717
make_tarball()
 
2718
{
 
2719
    setup_kernels_arches "mktarball"
 
2720
 
 
2721
    make_common_test "mktarball"
 
2722
 
 
2723
    # Check for dkms_dbversion
 
2724
    if ! [ -e "$dkms_tree/dkms_dbversion" ]; then
 
2725
        echo $"" >&2
 
2726
        echo $"Could not find the file $dkms_tree/dkms_dbversion." >&2
 
2727
        echo $"Creating w/ default contents." >&2
 
2728
        echo "2.0.0" > $dkms_tree/dkms_dbversion
 
2729
    fi
 
2730
 
 
2731
    # Error out if archive_location is set and contains a "/" in it
 
2732
    case "$archive_location" in
 
2733
        */*)
 
2734
        echo $"" >&2
 
2735
        echo $"Error!  The name you have specified for your tarball contains a '/'." >&2
 
2736
        echo $"You may only specify a simple filename with no preceding path."
 
2737
        exit 7
 
2738
        ;;
 
2739
    esac
 
2740
 
 
2741
    # Error out if binaries-only is set and source-only is set
 
2742
    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
 
2743
        echo $"" >&2
 
2744
        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
 
2745
        echo $"You cannot do this." >&2
 
2746
        exit 8
 
2747
    fi
 
2748
 
 
2749
    # Read the conf file
 
2750
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
2751
    if [ "$?" -ne 0 ]; then
 
2752
        echo $"" >&2
 
2753
        echo $"Error! Bad conf file." >&2
 
2754
        echo $"Your dkms.conf is not valid." >&2
 
2755
        exit 5
 
2756
    fi
 
2757
 
 
2758
    temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2759
    mkdir -p $temp_dir_name/dkms_main_tree
 
2760
 
 
2761
    if [ -n "$source_only" ]; then
 
2762
    kernel_version_list="source-only"
 
2763
    else
 
2764
    local i=0
 
2765
    while [ $i -lt ${#kernelver_array[@]} ]; do
 
2766
 
 
2767
        if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
 
2768
            echo $"" >&2
 
2769
            echo $"Error! No modules built for ${kernelver_array[$i]} (${arch_array[$i]})." >&2
 
2770
            echo $"Modules must already be in the built state before using mktarball." >&2
 
2771
            rm -rf "$temp_dir_name" 2>/dev/null
 
2772
            exit 6
 
2773
        fi
 
2774
 
 
2775
        set_module_suffix "${kernelver_array[$i]}"
 
2776
 
 
2777
        echo "Marking modules for ${kernelver_array[$i]} (${arch_array[$i]}) for archiving..."
 
2778
        if [ -z "$kernel_version_list" ]; then
 
2779
            kernel_version_list="kernel${kernelver_array[$i]}-${arch_array[$i]}"
 
2780
        else
 
2781
            kernel_version_list="${kernel_version_list}-kernel${kernelver_array[$i]}-${arch_array[$i]}"
 
2782
        fi
 
2783
        mkdir -p "$temp_dir_name/dkms_main_tree/${kernelver_array[$i]}/${arch_array[$i]}"
 
2784
        cp -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" "$temp_dir_name/dkms_main_tree/${kernelver_array[$i]}"
 
2785
 
 
2786
        i=$(($i + 1))
 
2787
    done
 
2788
    fi
 
2789
 
 
2790
    # Store the dkms_dbversion in the tarball
 
2791
    cp -f "$dkms_tree/dkms_dbversion" "$temp_dir_name/dkms_main_tree/"
 
2792
 
 
2793
    # Copy the source_tree or make special binaries-only structure
 
2794
    if [ -z "$binaries_only" ]; then
 
2795
        echo $""
 
2796
        echo $"Marking $dkms_tree/$module/$module_version/source for archiving..."
 
2797
        mkdir -p $temp_dir_name/dkms_source_tree
 
2798
        cp -rf $dkms_tree/$module/$module_version/source/* $temp_dir_name/dkms_source_tree
 
2799
    else
 
2800
        echo $""
 
2801
        echo $"Creating special tarball structure to accomodate only binaries."
 
2802
        mkdir $temp_dir_name/dkms_binaries_only
 
2803
        echo "$module" > $temp_dir_name/dkms_binaries_only/PACKAGE_NAME
 
2804
        echo "$module_version" > $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION
 
2805
        [ -z "$conf" ] && conf="$dkms_tree/$module/$module_version/source/dkms.conf"
 
2806
        cp -f $conf $temp_dir_name/dkms_binaries_only/ 2>/dev/null
 
2807
    fi
 
2808
 
 
2809
    # Make the tarball
 
2810
    cd $temp_dir_name
 
2811
    if [ `echo $kernel_version_list | wc -m | awk {'print $1'}` -gt 200 ]; then
 
2812
        kernel_version_list="manykernels"
 
2813
    fi
 
2814
    local tarball_name="$module-$module_version-$kernel_version_list.dkms.tar.gz"
 
2815
    [ -n "$archive_location" ] && tarball_name="$archive_location"
 
2816
    tar -czf $temp_dir_name/$tarball_name ./* 2>/dev/null
 
2817
    cd - >/dev/null
 
2818
    if [ "$?" -eq 0 ]; then
 
2819
        echo $""
 
2820
        mkdir -p $dkms_tree/$module/$module_version/tarball 2>/dev/null
 
2821
        mv -f $temp_dir_name/$tarball_name $dkms_tree/$module/$module_version/tarball/
 
2822
        echo $""
 
2823
        echo $"Tarball location: $dkms_tree/$module/$module_version/tarball/$tarball_name"
 
2824
        echo $""
 
2825
        echo $"DKMS: mktarball Completed."
 
2826
        rm -rf $temp_dir_name
 
2827
    else
 
2828
        echo $"" >&2
 
2829
        echo $"Error! Failed to make tarball." >&2
 
2830
        rm -rf $temp_dir_name
 
2831
        exit 6
 
2832
    fi
 
2833
}
 
2834
 
 
2835
load_tarball()
 
2836
{
 
2837
    setup_kernels_arches "mktarball"
 
2838
 
 
2839
    # Error out of --archive was not set with the tarball location
 
2840
    if [ -z "$archive_location" ]; then
 
2841
        echo $"" >&2
 
2842
        echo $"Error! Invalid number of parameters passed." >&2
 
2843
        echo $"Usage: ldtarball --archive=<tarball-location>" >&2
 
2844
        exit 1
 
2845
    fi
 
2846
 
 
2847
    # Error out if $archive_location does not exist
 
2848
    if ! [ -e "$archive_location" ]; then
 
2849
        echo $"" >&2
 
2850
        echo $"Error! Cannot locate $archive_location." >&2
 
2851
        echo $"File does not exist." >&2
 
2852
        exit 2
 
2853
    fi
 
2854
 
 
2855
    # Figure out what kind of archive it is (tar.gz, tar, tar.bz, etc)
 
2856
    local tar_options=""
 
2857
    if `gzip -t $archive_location 2>/dev/null`; then
 
2858
        tar_options="${tar_options}z"
 
2859
    fi
 
2860
    if `bzip2 -t $archive_location 2>/dev/null`; then
 
2861
        tar_options="${tar_options}j"
 
2862
    fi
 
2863
 
 
2864
    # Untar it into $tmp_location
 
2865
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
2866
    tar -${tar_options}xf $archive_location -C $temp_dir_name
 
2867
 
 
2868
    # Check that dkms_dbversion is not a future version
 
2869
    db_from_tarball="`cat $temp_dir_name/dkms_main_tree/dkms_dbversion 2>/dev/null`"
 
2870
    db_from_dkms="`cat $dkms_tree/dkms_dbversion 2>/dev/null`"
 
2871
    if [ -n "$db_from_tarball" ] && [ -n "$db_from_dkms" ]; then
 
2872
        if [[ $(VER "$db_from_tarball") > $(VER "$db_from_dkms") ]]; then
 
2873
            echo $"" >&2
 
2874
            echo $"Error! The tarball you are trying to load indicates it is database version" >&2
 
2875
            echo $"$db_from_tarball.  This version of DKMS only supports $db_from_dkms or lower.">&2
 
2876
            rm -rf $temp_dir_name
 
2877
            exit 9
 
2878
        fi
 
2879
    fi
 
2880
 
 
2881
    # Make sure its a sane tarball
 
2882
    PACKAGE_NAME=""
 
2883
    PACKAGE_VERSION=""
 
2884
    local is_from_mktarball=""
 
2885
    local is_binaries_only=""
 
2886
    local is_not_arch_aware=""
 
2887
    if ! [ -d "$temp_dir_name/dkms_main_tree" ]; then
 
2888
        conf=`find $temp_dir_name/ -name dkms.conf 2>/dev/null | head -n 1`
 
2889
        if [ -z "$conf" ]; then
 
2890
            echo $"" >&2
 
2891
            echo $"Error! Tarball does not appear to be a correctly formed" >&2
 
2892
            echo $"DKMS archive. No dkms.conf found within it." >&2
 
2893
            rm -rf $temp_dir_name
 
2894
            exit 3
 
2895
        fi
 
2896
        read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
 
2897
        if [ "$?" -ne 0 ]; then
 
2898
            echo $"" >&2
 
2899
            echo $"Error! Bad conf file." >&2
 
2900
            echo $"File: $conf does not represent a valid dkms.conf file" >&2
 
2901
            rm -rf $temp_dir_name
 
2902
            exit 4
 
2903
        fi
 
2904
        tarball_source_tree_name=`echo $conf | sed "s#$temp_dir_name\/##" | sed 's/dkms.conf//' | sed 's/\/$//'`
 
2905
    elif ! [ -d "$temp_dir_name/dkms_source_tree" ] && [ -d "$temp_dir_name/dkms_binaries_only" ]; then
 
2906
        PACKAGE_NAME=`cat $temp_dir_name/dkms_binaries_only/PACKAGE_NAME 2>/dev/null`
 
2907
        PACKAGE_VERSION=`cat $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION 2>/dev/null`
 
2908
        if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
 
2909
            echo $"" >&2
 
2910
            echo $"Error! Tarball does not appear to be a correctly formed" >&2
 
2911
            echo $"DKMS archive." >&2
 
2912
            rm -rf $temp_dir_name
 
2913
            exit 5
 
2914
        fi
 
2915
        if [ "`$0 status -m $PACKAGE_NAME -v $PACKAGE_VERSION 2>/dev/null`" == "" ]; then
 
2916
            if [ -e "$temp_dir_name/dkms_binaries_only/dkms.conf" ]; then
 
2917
            echo $""
 
2918
            echo $"Binaries-only DKMS tarball to be loaded for $PACKAGE_NAME-$PACKAGE_VERSION"
 
2919
            echo $"even though source for this module is not added to the DKMS tree.  "
 
2920
                    echo $"<<<<WARNING>>>>"
 
2921
            echo $"This will allow you to install the pre-built binaries contained within this"
 
2922
            echo $"tarball, but will prevent you from building new modules for other kernels."
 
2923
            echo $""
 
2924
            . $temp_dir_name/dkms_binaries_only/dkms.conf 2>/dev/null
 
2925
            else
 
2926
            echo $"" >&2
 
2927
            echo $"Binaries-only DKMS tarball does not seem to contain a dkms.conf file for" >&2
 
2928
            echo $"this module.  Unable to load this tarball into the DKMS tree." >&2
 
2929
            exit 7
 
2930
            fi
 
2931
        fi
 
2932
        is_from_mktarball="true"
 
2933
        is_binaries_only="true"
 
2934
    elif [ -d "$temp_dir_name/dkms_source_tree" ]; then
 
2935
        . $temp_dir_name/dkms_source_tree/dkms.conf 2>/dev/null
 
2936
        if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
 
2937
            echo $"" >&2
 
2938
            echo $"Error! Tarball does not appear to be a correctly formed" >&2
 
2939
            echo $"DKMS archive." >&2
 
2940
            rm -rf $temp_dir_name
 
2941
            exit 8
 
2942
        fi
 
2943
        is_from_mktarball="true"
 
2944
        tarball_source_tree_name="dkms_source_tree"
 
2945
    else
 
2946
        echo $"" >&2
 
2947
        echo $"Error! Tarball does not appear to be a correctly formed" >&2
 
2948
        echo $"DKMS archive." >&2
 
2949
        rm -rf $temp_dir_name
 
2950
        exit 8
 
2951
    fi
 
2952
 
 
2953
    # Is tarball from before DKMS 2.0 (prior to arch support)
 
2954
    if [ "$is_from_mktarball" == "true" ] && ! [ -e "$temp_dir_name/dkms_main_tree/dkms_dbversion" ]; then
 
2955
        is_not_arch_aware="true"
 
2956
        echo $"" >&2
 
2957
        echo $"Warning!  This tarball was created with dkms < 2.0 and contains" >&2
 
2958
        echo $"no arch info. DKMS will assume the arch: ${arch_array[0]}" >&2
 
2959
    fi
 
2960
 
 
2961
    # Make sure we got what we needed from the tarball
 
2962
    module="$PACKAGE_NAME"
 
2963
    module_version="$PACKAGE_VERSION"
 
2964
 
 
2965
    echo $""
 
2966
    echo $"Loading tarball for module: $module / version: $module_version"
 
2967
    echo $""
 
2968
 
 
2969
    # Load the source from the tarball or build it's structure (for binaries only)
 
2970
    if [ -z "$is_binaries_only" ]; then
 
2971
        if [ "`$0 status -m $module -v $module_version 2>/dev/null`" != "" ] && [ -z "$force" ]; then
 
2972
            echo $"Warning! Source for $module-$module_version already exists.  Skipping..." >&2
 
2973
        else
 
2974
            echo $"Loading $source_tree/$module-$module_version..."
 
2975
            rm -rf $source_tree/$module-$module_version
 
2976
            mkdir -p $source_tree/$module-$module_version
 
2977
            cp -rf $temp_dir_name/$tarball_source_tree_name/* $source_tree/$module-$module_version
 
2978
        fi
 
2979
 
 
2980
        mkdir -p $dkms_tree/$module/$module_version
 
2981
    else
 
2982
        echo $"Creating $dkms_tree/$module/$module_version/source"
 
2983
        mkdir -p $dkms_tree/$module/$module_version/source
 
2984
        echo $"Copying dkms.conf to $dkms_tree/$module/$module_version/source..."
 
2985
        cp -rf $temp_dir_name/dkms_binaries_only/dkms.conf $dkms_tree/$module/$module_version/source
 
2986
    fi
 
2987
 
 
2988
    # Load kernel directories
 
2989
    [ -n "$is_not_arch_aware" ] && dirs_to_load=`find $temp_dir_name/dkms_main_tree -type d -maxdepth 1 -mindepth 1 2>/dev/null`
 
2990
    [ -z "$is_not_arch_aware" ] && dirs_to_load=`find $temp_dir_name/dkms_main_tree -type d -maxdepth 2 -mindepth 2 2>/dev/null`
 
2991
    for directory in $dirs_to_load; do
 
2992
        dirs_to_parse=`echo $directory | sed "s#.*dkms_main_tree/##"`
 
2993
        kernel_to_load=`echo $dirs_to_parse | sed "s#/.*##"`
 
2994
        # arch_to_load="${arch_array[0]##*/}"
 
2995
        [ `echo $dirs_to_parse | grep -c "/"` -gt 0 ] && arch_to_load=`echo $dirs_to_parse | sed "s#.*/##"` || arch_to_load="${arch_array[0]}"
 
2996
 
 
2997
        dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_to_load/$arch_to_load"
 
2998
 
 
2999
 
 
3000
        dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_to_load/$arch_to_load"
 
3001
        if [ -d "$dkms_dir_location" ] && [ -z "$force" ]; then
 
3002
            echo $"Warning! $dkms_dir_location already exists.  Skipping..." >&2
 
3003
        else
 
3004
            echo $"Loading $dkms_dir_location..."
 
3005
            rm -rf $dkms_dir_location
 
3006
            mkdir -p $dkms_dir_location
 
3007
            cp -rf $directory/* $dkms_dir_location/
 
3008
        fi
 
3009
    done
 
3010
 
 
3011
    # Create source symlink (if there isn't a real directory there)
 
3012
    if [ ! -h "$dkms_tree/$module/$module_version/source" ] && \
 
3013
       [ ! -d "$dkms_tree/$module/$module_version/source" ] || [ ! -z "$force" ]; then
 
3014
        echo $"Creating $dkms_tree/$module/$module_version/source symlink..."
 
3015
        rm -f "$dkms_tree/$module/$module_version/source"
 
3016
        ln -s "$source_tree/$module-$module_version" "$dkms_tree/$module/$module_version/source"
 
3017
    fi
 
3018
 
 
3019
    # Clean up /tmp
 
3020
    rm -rf $temp_dir_name
 
3021
 
 
3022
    echo $""
 
3023
    echo $"DKMS: ldtarball Completed."
 
3024
}
 
3025
 
 
3026
run_match ()
 
3027
{
 
3028
    setup_kernels_arches "match"
 
3029
    set_kernel_source_dir "${kernelver_array[0]}"
 
3030
 
 
3031
    # Error if $template_kernel is unset
 
3032
    if [ -z "$template_kernel" ]; then
 
3033
        echo $"" >&2
 
3034
        echo $"Error! Invalid number of parameters passed." >&2
 
3035
        echo $"Usage: match --templatekernel=<kernel-version> -k <kernel-version>" >&2
 
3036
        echo $"   or: match --templatekernel=<kernel-version> -k <kernel-version> -m <module>" >&2
 
3037
        exit 1
 
3038
    fi
 
3039
 
 
3040
    # Error out if $template_kernel = $kernel_version
 
3041
    if [ "$template_kernel" == "${kernelver_array[0]}" ]; then
 
3042
        echo $"" >&2
 
3043
        echo $"Error! The templatekernel and the specified kernel version are the same." >&2
 
3044
        exit 2
 
3045
    fi
 
3046
 
 
3047
    # Read in the status of template_kernel
 
3048
    local template_kernel_status=`$0 status -k $template_kernel -a ${arch_array[0]} | grep ": installed"`
 
3049
 
 
3050
    # If $module is set, grep the status only for that module
 
3051
    if [ -n "$module" ]; then
 
3052
 
 
3053
        # Make sure that its installed in the first place
 
3054
        if ! [ -d "$dkms_tree/$module/" ]; then
 
3055
            echo $"" >&2
 
3056
            echo $"Error! The module: $module is not located in the DKMS tree." >&2
 
3057
            exit 3
 
3058
        fi
 
3059
 
 
3060
        template_kernel_status=`echo "$template_kernel_status" | grep "^$module,"`
 
3061
    fi
 
3062
 
 
3063
    echo $""
 
3064
    echo $"Matching modules in kernel: ${kernelver_array[0]} (${arch_array[0]})"
 
3065
    echo $"to the configuration of kernel: $template_kernel (${arch_array[0]})"
 
3066
 
 
3067
    # Prepare the kernel just once but only if there is actual work to do
 
3068
    if [ -z "$template_kernel_status" ]; then
 
3069
        echo $""
 
3070
        echo $"There is nothing to be done for this match."
 
3071
    else
 
3072
        prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
 
3073
 
 
3074
        # Iterate over the kernel_status and match kernel to the template_kernel
 
3075
        while read template_line; do
 
3076
            template_module=`echo "$template_line" | awk {'print $1'} | sed 's/,$//'`
 
3077
            template_version=`echo "$template_line" | awk {'print $2'} | sed 's/,$//'`
 
3078
 
 
3079
            # Print out a match header
 
3080
            echo $""
 
3081
            echo $"---- Match Beginning ----"
 
3082
            echo $"Module:  $template_module"
 
3083
            echo $"Version: $template_version"
 
3084
            echo $"-------------------------"
 
3085
 
 
3086
            # Figure out what to do from here
 
3087
            if $0 status -m "$template_module" -v "$template_version" -k "${kernelver_array[0]}" -a "${arch_array[0]}" 2>/dev/null | grep -q ": installed"; then
 
3088
                echo $""
 
3089
                echo $"This module/version combo is already installed.  Nothing to be done."
 
3090
            elif $0 status -m "$template_module" -v "$template_version" -k "${kernelver_array[0]}" -a "${arch_array[0]}" 2>/dev/null | grep -q ": built"; then
 
3091
                echo $""
 
3092
                echo $"This module/version combo is built.  Installing it:"
 
3093
                module="$template_module"
 
3094
                module_version="$template_version"
 
3095
                install_module
 
3096
            else
 
3097
                echo $""
 
3098
                echo $"Building & Installing this module/version:"
 
3099
                module="$template_module"
 
3100
                module_version="$template_version"
 
3101
                build_module
 
3102
                install_module
 
3103
            fi
 
3104
        done < <(echo "$template_kernel_status")
 
3105
 
 
3106
        # Clean up the kernel tree
 
3107
        if [[ ! ( $(VER ${kernelver_array[0]}) < $(VER 2.6.6) ) && \
 
3108
            -d "$kernel_source_dir" && \
 
3109
            ! -h "$kernel_source_dir" && \
 
3110
            -z "$ksourcedir_fromcli" ]]; then
 
3111
            echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
 
3112
        elif [ -z "$no_clean_kernel" ]; then
 
3113
            cd "$kernel_source_dir"
 
3114
            [ -z "$kerneldoth_contents" ] && invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
 
3115
            [ -n "$config_contents" ] && echo "$config_contents" > .config
 
3116
            [ -n "$kerneldoth_contents" ] && echo "$kerneldoth_contents" > /boot/kernel.h
 
3117
            cd - >/dev/null
 
3118
        fi
 
3119
    fi
 
3120
 
 
3121
    # Done
 
3122
    echo $""
 
3123
    echo $"DKMS: match Completed."
 
3124
}
 
3125
 
 
3126
make_rpm()
 
3127
{
 
3128
    setup_kernels_arches "mkrpm"
 
3129
 
 
3130
    make_common_test "mkrpm"
 
3131
 
 
3132
    # Check that the rpmbuild command is present
 
3133
    if ! which rpmbuild >/dev/null 2>&1 ; then
 
3134
        echo $"" >&2
 
3135
        echo $"Error! rpmbuild not present." >&2
 
3136
        echo $"Install the rpm-build package." >&2
 
3137
        exit 1
 
3138
    fi
 
3139
 
 
3140
    # Read the conf file
 
3141
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
3142
    if [ "$?" -ne 0 ]; then
 
3143
        echo $"" >&2
 
3144
        echo $"Error! Bad conf file." >&2
 
3145
        echo $"Your dkms.conf is not valid." >&2
 
3146
        exit 4
 
3147
    fi
 
3148
 
 
3149
    local rpm_basedir="$dkms_tree/$module/$module_version/rpm"
 
3150
 
 
3151
    echo $""
 
3152
    if [ -e "$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec" ]; then
 
3153
        echo $"Using $dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec"
 
3154
        SPECFILE="$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec"
 
3155
    elif [ -e "/etc/dkms/template-dkms-mkrpm.spec" ]; then
 
3156
        echo $"Using /etc/dkms/template-dkms-mkrpm.spec"
 
3157
        SPECFILE="/etc/dkms/template-dkms-mkrpm.spec"
 
3158
    else
 
3159
        echo $"" >&2
 
3160
        echo $"Cannot find /etc/dkms/template-dkms-mkrpm.spec which is needed by" >&2
 
3161
        echo $"DKMS in order use mkrpm." >&2
 
3162
        exit 5
 
3163
    fi
 
3164
 
 
3165
    # Error out if binaries-only is set and source-only is set
 
3166
    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
 
3167
        echo $"" >&2
 
3168
        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
 
3169
        echo $"You cannot do this." >&2
 
3170
        exit 8
 
3171
    fi
 
3172
 
 
3173
    # Run a dkms mktarball for use in the rpm
 
3174
    local mktarball_line
 
3175
    if [ ! -n "$source_only" ] || [ -n "$binaries_only" ]; then
 
3176
        mktarball_line="--binaries-only"
 
3177
        local i=0
 
3178
        echo $""
 
3179
        while [ $i -lt ${#kernelver_array[@]} ]; do
 
3180
            if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
 
3181
            echo $"" >&2
 
3182
            echo $"You do not seem to have $module $module_version built for" >&2
 
3183
            echo $"${kernelver_array[$i]} (${arch_array[$i]}).  All modules must be in" >&2
 
3184
            echo $"the built state before you can use mkrpm." >&2
 
3185
            exit 5
 
3186
            fi
 
3187
            echo $"Marking ${kernelver_array[$i]} (${arch_array[$i]}) for RPM..."
 
3188
            mktarball_line="-k ${kernelver_array[$i]} -a ${arch_array[$i]} $mktarball_line"
 
3189
            i=$(($i + 1))
 
3190
        done
 
3191
    else
 
3192
        mktarball_line="none"
 
3193
    fi
 
3194
 
 
3195
    local RC=0
 
3196
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
3197
    trap 'rm -rf $temp_dir_name' EXIT HUP TERM
 
3198
    mkdir -p ${temp_dir_name}/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
 
3199
    cp ${SPECFILE} ${temp_dir_name}/SPECS/dkms_mkrpm.spec
 
3200
 
 
3201
    #if using legacy mode, install common postinst
 
3202
    if [ "$legacy_postinst" != "0" ]; then
 
3203
        invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '${temp_dir_name}/SOURCES'" "copying legacy postinstall template"
 
3204
    fi
 
3205
 
 
3206
    #Copy in the source tree
 
3207
    if [ ! -n "$binaries_only" ]; then
 
3208
        invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '${temp_dir_name}/SOURCES/$module-$module_version'" "Copying source tree"
 
3209
    fi
 
3210
 
 
3211
    invoke_command "LC_ALL=C rpmbuild --define \"_topdir ${temp_dir_name}\" --define \"version $module_version\" --define \"module_name $module\" --define \"kernel_versions ${kernelver_array[*]}\" --define \"mktarball_line $mktarball_line\" --define \"__find_provides  /usr/lib/dkms/find-provides\" --define \"_use_internal_dependency_generator 0\" -ba ${temp_dir_name}/SPECS/dkms_mkrpm.spec > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
 
3212
    if [ "$?" -eq 0 ]; then
 
3213
        mkdir -p ${rpm_basedir}
 
3214
        cp -a ${temp_dir_name}/SRPMS/* ${temp_dir_name}/RPMS/*/* ${rpm_basedir}/
 
3215
        echo $""
 
3216
        cat ${temp_dir_name}/rpmbuild.log | grep ^Wrote | sed -e "s:${temp_dir_name}/:${rpm_basedir}/:" -e 's:SRPMS/::' -e 's:RPMS/.*/::'
 
3217
        echo $""
 
3218
        echo $"DKMS: mkrpm Completed."
 
3219
    else
 
3220
        echo $"" >&2
 
3221
        echo $"Error! There was a problem creating your rpm." >&2
 
3222
        cat ${temp_dir_name}/rpmbuild.log >&2
 
3223
        RC=7
 
3224
    fi
 
3225
    rm -rf $temp_dir_name
 
3226
    trap > /dev/null 2>&1
 
3227
    [ ${RC} -ne 0 ] && exit ${RC}
 
3228
}
 
3229
 
 
3230
function preproc_file()
 
3231
{
 
3232
    local date_str="$(date -R)"
 
3233
    echo "modifying $1..."
 
3234
    sed -e "s/DEBIAN_PACKAGE/$debian_package/g" \
 
3235
        -e "s/MODULE_NAME/$module/g" \
 
3236
        -e "s/MODULE_VERSION/$module_version/g" \
 
3237
        -e "s/DATE_STAMP/$date_str/" "$1" > "$1.dkms-pp"
 
3238
    mv "$1.dkms-pp" "$1"
 
3239
}
 
3240
 
 
3241
function make_debian_test_depends()
 
3242
{
 
3243
    INSTALL_PACKAGES=""
 
3244
    # Check that the fakeroot command is present
 
3245
    if ! which fakeroot >/dev/null 2>&1 ; then
 
3246
        INSTALL_PACKAGES="fakeroot $INSTALL_PACKAGES"
 
3247
    fi
 
3248
 
 
3249
    # Check that the dh_make command is present
 
3250
    if ! which dpkg-buildpackage >/dev/null 2>&1 ; then
 
3251
        INSTALL_PACKAGES="dpkg-dev $INSTALL_PACKAGES"
 
3252
    fi
 
3253
    echo "$INSTALL_PACKAGES"
 
3254
}
 
3255
 
 
3256
function make_debian()
 
3257
{
 
3258
    create_type="$1"
 
3259
 
 
3260
    create_temporary_trees
 
3261
    trap "delete_temporary_trees" EXIT HUP TERM
 
3262
 
 
3263
    make_common_test "mk${create_type}"
 
3264
 
 
3265
    debian_package=$(echo $module | sed s/_/-/g)
 
3266
 
 
3267
    SYNAPTIC=""
 
3268
    #Synaptic availablity
 
3269
    if [ -x /usr/sbin/synaptic ]; then
 
3270
        SYNAPTIC="TRUE"
 
3271
    fi
 
3272
 
 
3273
    #test who we are
 
3274
    ROOT=""
 
3275
    if [ "$USER" != "root" ]; then
 
3276
        if [ -x /usr/sbin/su-to-root ]; then
 
3277
            ROOT="/usr/sbin/su-to-root -c"
 
3278
        elif [ -x /usr/bin/gksudo ] && [ ! -z "$DISPLAY" ]; then
 
3279
            ROOT="/usr/bin/gksudo --description 'DKMS Debian package builder' "
 
3280
        elif [ -x /usr/bin/kdesu ] && [ ! -z "$DISPLAY" ]; then
 
3281
            ROOT="/usr/bin/kdesu"
 
3282
        elif [ -x /usr/bin/sudo ]; then
 
3283
            ROOT="/usr/bin/sudo"
 
3284
        fi
 
3285
    fi
 
3286
 
 
3287
    # Read the conf file
 
3288
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
3289
    if [ "$?" -ne 0 ]; then
 
3290
        echo $"" >&2
 
3291
        echo $"Error! Bad conf file." >&2
 
3292
        echo $"Your dkms.conf is not valid." >&2
 
3293
        exit 4
 
3294
    fi
 
3295
 
 
3296
    #test if we are missing dependencies that are needed during package build
 
3297
    INSTALL_PACKAGES="`make_debian_test_depends`"
 
3298
    if [ ! -z "$INSTALL_PACKAGES" ]; then
 
3299
        if [ -z "$ROOT" ]; then
 
3300
            echo $"" >&2
 
3301
            echo $"Error! Missing $INSTALL_PACKAGES" >&2
 
3302
            echo $"and unable to install.  Please ask an admin to install for you." >&2
 
3303
            exit 4
 
3304
        fi
 
3305
        if [ ! -z "$SYNAPTIC" ] && [ ! -z "$DISPLAY" ]; then
 
3306
            local TEMPFILE=`/bin/tempfile`
 
3307
            echo $INSTALL_PACKAGES | sed 's/|/\ install\/g' > $TEMPFILE
 
3308
            $ROOT "sh -c '/usr/sbin/synaptic --set-selections --non-interactive --hide-main-window < $TEMPFILE'"
 
3309
            trap "rm -f $TEMPFILE; delete_temporary_trees" EXIT HUP TERM
 
3310
        else
 
3311
            $ROOT apt-get -y install $INSTALL_PACKAGES
 
3312
        fi
 
3313
 
 
3314
        INSTALL_PACKAGES="`make_debian_test_depends`"
 
3315
        #Retest packages
 
3316
        if [ ! -z "$INSTALL_PACKAGES" ]; then
 
3317
            echo $"" >&2
 
3318
            echo $"Error! Missing $INSTALL_PACKAGES" >&2
 
3319
            echo $"and unable to install.  Please ask an admin to install for you." >&2
 
3320
            exit 4
 
3321
        fi
 
3322
    fi
 
3323
 
 
3324
    #skeleton to load templates from
 
3325
    local system_mk="$dkms_tree/$module/$module_version/source/$module-dkms-mk${create_type}"
 
3326
    local local_mk="/etc/dkms/template-dkms-mk${create_type}"
 
3327
    if [ -e "${system_mk}" ]; then
 
3328
        echo $"Using ${system_mk}"
 
3329
        DEBDIR=${system_mk}
 
3330
    elif [ -e "${local_mk}" ]; then
 
3331
        echo $"Using ${local_mk}"
 
3332
        DEBDIR=${local_mk}
 
3333
    else
 
3334
        echo $"" >&2
 
3335
        echo $"Cannot find ${local_mk} which is needed by" >&2
 
3336
        echo $"DKMS in order to use mk${create_type}." >&2
 
3337
        exit 5
 
3338
    fi
 
3339
 
 
3340
    #prepare build directory and copy template
 
3341
    local temp_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
 
3342
    trap "rm -rf $temp_dir; delete_temporary_trees" EXIT HUP TERM
 
3343
    local temp_dir_debian="$temp_dir/$debian_package-dkms-$module_version"
 
3344
    invoke_command "cp -ar '$DEBDIR/' '$temp_dir_debian'" "copying template"
 
3345
    pushd "$temp_dir_debian" > /dev/null 2>&1
 
3346
    for file in debian/*; do
 
3347
        preproc_file "$file"
 
3348
        chmod 755 "$file"
 
3349
    done
 
3350
    popd > /dev/null 2>&1
 
3351
 
 
3352
    #if using legacy mode, install common postinst
 
3353
    if [ "$legacy_postinst" != "0" ]; then
 
3354
        invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '$temp_dir_debian'" "copying legacy postinstall template"
 
3355
    fi
 
3356
 
 
3357
    #Copy in the source tree
 
3358
    if [ ! -n "$binaries_only" ]; then
 
3359
        invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '$temp_dir_debian/$module-$module_version'" "Copying source tree"
 
3360
    fi
 
3361
 
 
3362
    #Only if we are shipping binary modules, make a .tgz for the deb
 
3363
    local archive_location="$module-$module_version.dkms.tar.gz"
 
3364
    if [ ! -n "$source_only" ]; then
 
3365
        binaries_only="binaries-only"
 
3366
        invoke_command "make_tarball" "Gathering binaries"
 
3367
        if [ -f $dkms_tree/$module/$module_version/tarball/$archive_location ]; then
 
3368
            invoke_command "cp '$dkms_tree/$module/$module_version/tarball/$archive_location' '$temp_dir_debian'" "Copying DKMS tarball into DKMS tree"
 
3369
        else
 
3370
            echo $"" >&2
 
3371
            echo $"Error! Unable to find created tarball." >&2
 
3372
            exit 12
 
3373
        fi
 
3374
    fi
 
3375
 
 
3376
    #calculate destination directory
 
3377
    deb_basedir=$dkms_tree/$module/$module_version/${create_type}
 
3378
    mkdir -p ${deb_basedir} >/dev/null 2>&1
 
3379
 
 
3380
    #create deb
 
3381
    pushd "$temp_dir_debian" > /dev/null 2>&1
 
3382
    case "$create_type" in
 
3383
        dsc)
 
3384
            invoke_command "dpkg-buildpackage -S -us -uc 1>/dev/null" "Building source package"
 
3385
            if [ "$?" -eq 0 ]; then
 
3386
                echo $""
 
3387
                echo $"DKMS: mk${create_type} Completed."
 
3388
            else
 
3389
                echo $"" >&2
 
3390
                echo $"Error! There was a problem creating your ${create_type}." >&2
 
3391
                exit 7
 
3392
            fi
 
3393
            invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}.dsc' '$temp_dir/${debian_package}-dkms_${module_version}.tar.gz' '$deb_basedir'" "Moving built files to $deb_basedir"
 
3394
            ;;
 
3395
        deb)
 
3396
            invoke_command "dpkg-buildpackage -rfakeroot -d -b -us -uc 1>/dev/null" "Building binary package"
 
3397
            if [ "$?" -eq 0 ]; then
 
3398
                echo $""
 
3399
                echo $"DKMS: mk${create_type} Completed."
 
3400
            else
 
3401
                echo $"" >&2
 
3402
                echo $"Error! There was a problem creating your ${create_type}." >&2
 
3403
                exit 7
 
3404
            fi
 
3405
 
 
3406
            invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_all.deb' '$deb_basedir'" "Moving built files to $deb_basedir"
 
3407
            ;;
 
3408
    esac
 
3409
    popd > /dev/null 2>&1
 
3410
 
 
3411
    if in_temporary_trees; then
 
3412
        echo "Copying built files to "`pwd`"/.." >&2
 
3413
        cp "$dkms_tree/$module/$module_version/deb/"* ..
 
3414
    fi
 
3415
 
 
3416
    #cleanup
 
3417
    invoke_command "rm $temp_dir -fr" "Cleaning up temporary files"
 
3418
    delete_temporary_trees
 
3419
 
 
3420
    #done
 
3421
    if [ "$?" -ne 0 ]; then
 
3422
        echo $"" >&2
 
3423
        echo $"Error! There was a problem cleaning up temporary files." >&2
 
3424
        exit 7
 
3425
    fi
 
3426
}
 
3427
 
 
3428
function make_common_test()
 
3429
{
 
3430
    local create_type=$1
 
3431
    # Error if $module_version is set but $module is not
 
3432
    if [ -z "$module" ] || [ -z "$module_version" ]; then
 
3433
        echo $"" >&2
 
3434
        echo $"Error! Invalid number of parameters passed." >&2
 
3435
        echo $"Usage: $create_type -m <module> -v <module-version>" >&2
 
3436
        exit 1
 
3437
    fi
 
3438
 
 
3439
    # Check that source symlink works
 
3440
    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
 
3441
        echo $"" >&2
 
3442
        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
 
3443
        echo $"Build cannot continue without the proper tree." >&2
 
3444
        exit 2
 
3445
    fi
 
3446
 
 
3447
    # Make sure that its installed in the first place
 
3448
    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
 
3449
        echo $"" >&2
 
3450
        echo $"Error! The module/version combo: $module-$module_version" >&2
 
3451
        echo $"is not located in the DKMS tree." >&2
 
3452
        exit 3
 
3453
    fi
 
3454
 
 
3455
    # Error out if archive_location is set and contains a "/" in it
 
3456
    case "$archive_location" in
 
3457
        */*)
 
3458
        echo $"" >&2
 
3459
        echo $"Error!  The name you have specified for your archive contains a '/'." >&2
 
3460
        echo $"You may only specify a simple filename with no preceding path."
 
3461
        exit 7
 
3462
        ;;
 
3463
    esac
 
3464
 
 
3465
    # Error out if binaries-only is set and source-only is set
 
3466
    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
 
3467
        echo $"" >&2
 
3468
        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
 
3469
        echo $"You cannot do this." >&2
 
3470
        exit 8
 
3471
    fi
 
3472
}
 
3473
 
 
3474
function make_kmp_srpm()
 
3475
{
 
3476
    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
 
3477
    trap 'rm -rf $temp_dir_name' EXIT HUP TERM
 
3478
    mkdir -p $temp_dir_name/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
 
3479
    pushd "$dkms_tree/$module/$module_version" > /dev/null 2>&1
 
3480
    # want to change name of the top-level of the tarball
 
3481
    # from build to $module-$module_version
 
3482
    cp -lr build ${module}-${module_version}
 
3483
    tar cvjf $temp_dir_name/SOURCES/${module}-${module_version}.tar.bz2 ${module}-${module_version} > /dev/null 2>&1
 
3484
    rm -rf ${module}-${module_version}
 
3485
    popd > /dev/null 2>&1
 
3486
    pushd "$temp_dir_name" > /dev/null 2>&1
 
3487
    invoke_command "rpmbuild --define \"_topdir ${temp_dir_name}\" --target=${arch_array[0]} -bs ${SPECFILE} > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
 
3488
    grep ^Wrote $temp_dir_name/rpmbuild.log > /dev/null 2>&1
 
3489
    local RC="$?"
 
3490
    if [ "${RC}" -eq 0 ]; then
 
3491
        local kmp_basedir="$dkms_tree/$module/$module_version/rpm"
 
3492
        mkdir -p $kmp_basedir
 
3493
        RPMS=`LANG=C cp -va ${temp_dir_name}/SRPMS/* $kmp_basedir | awk '{print $NF}'`
 
3494
    else
 
3495
        echo $"rpmbuild error log:"
 
3496
        cat $temp_dir_name/rpmbuild.log
 
3497
    fi
 
3498
    popd > /dev/null 2>&1
 
3499
    rm -rf $temp_dir_name
 
3500
    trap > /dev/null 2>&1
 
3501
    return ${RC}
 
3502
}
 
3503
 
 
3504
function report_build_problem()
 
3505
{
 
3506
    #If apport is on the system, files a build problem
 
3507
    if [ -x /usr/share/apport/apport ] && which python>/dev/null; then
 
3508
        python /usr/share/apport/package-hooks/dkms.py -m $module -v $module_version
 
3509
    fi
 
3510
}
 
3511
 
 
3512
 
 
3513
function make_kmp()
 
3514
{
 
3515
    setup_kernels_arches "mkkmp"
 
3516
 
 
3517
    make_common_test "mkkmp"
 
3518
 
 
3519
    # Read the conf file
 
3520
    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
 
3521
    if [ "$?" -ne 0 ]; then
 
3522
        echo $"" >&2
 
3523
        echo $"Error! Bad conf file." >&2
 
3524
        echo $"Your dkms.conf is not valid." >&2
 
3525
        exit 4
 
3526
    fi
 
3527
 
 
3528
    echo $""
 
3529
    if [ -n "$specfile" -a -e "$dkms_tree/$module/$module_version/source/$specfile" ]; then
 
3530
        echo $"Using $dkms_tree/$module/$module_version/source/$specfile"
 
3531
        SPECFILE="$dkms_tree/$module/$module_version/source/$specfile"
 
3532
    elif [ -e "$dkms_tree/$module/$module_version/source/$module-kmp.spec" ]; then
 
3533
        echo $"Using $dkms_tree/$module/$module_version/source/$module-kmp.spec"
 
3534
        SPECFILE="$dkms_tree/$module/$module_version/source/$module-kmp.spec"
 
3535
    else
 
3536
        echo $"" >&2
 
3537
        echo $"Cannot find a suitable spec file which is needed by" >&2
 
3538
        echo $"DKMS in order use mkkmp.  Please specify --spec=specfile." >&2
 
3539
        exit 5
 
3540
    fi
 
3541
 
 
3542
    prepare_build
 
3543
    make_kmp_srpm
 
3544
    RC=$?
 
3545
    clean_build
 
3546
 
 
3547
    if [ "$RC" -eq 0 ]; then
 
3548
        echo $""
 
3549
        echo $"KMP SRPM location: $RPMS"
 
3550
        echo $""
 
3551
        echo $"DKMS: mkkmp Completed."
 
3552
    else
 
3553
        echo $"" >&2
 
3554
        echo $"Error! There was a problem creating your KMP source rpm." >&2
 
3555
        exit 7
 
3556
    fi
 
3557
    # FIXME: hand SRPM to mock or build system to build
 
3558
}
 
3559
 
 
3560
#############################
 
3561
####                     ####
 
3562
#### Program Starts Here ####
 
3563
####                     ####
 
3564
#############################
 
3565
 
 
3566
# Set Path
 
3567
case ":$PATH:" in
 
3568
:/usr/sbin:)
 
3569
    ;;
 
3570
*)
 
3571
    PATH="$PATH:/usr/sbin"
 
3572
    ;;
 
3573
esac
 
3574
case ":$PATH:" in
 
3575
:/sbin:)
 
3576
    ;;
 
3577
*)
 
3578
    PATH="$PATH:/sbin"
 
3579
    ;;
 
3580
esac
 
3581
PATH="$PATH:/usr/lib/dkms"
 
3582
 
 
3583
# Ensure files and directories we create are readable to anyone,
 
3584
# since we aim to build as a non-root user
 
3585
umask 022
 
3586
 
 
3587
# Unset environment variables that may interfere with the build
 
3588
unset CC CXX CFLAGS CXXFLAGS LDFLAGS
 
3589
 
 
3590
# Set important variables
 
3591
current_kernel=`uname -r`
 
3592
dkms_tree="/var/lib/dkms"
 
3593
source_tree="/usr/src"
 
3594
install_tree="/lib/modules"
 
3595
tmp_location="/tmp"
 
3596
verbose=""
 
3597
dkms_frameworkconf="/etc/dkms/framework.conf"
 
3598
 
 
3599
# these can come from the environment or the config file
 
3600
[ -z "${ADDON_MODULES_DIR}" -a -e /etc/sysconfig/module-init-tools ] && . /etc/sysconfig/module-init-tools
 
3601
addon_modules_dir="${ADDON_MODULES_DIR}"
 
3602
[ -z "${addon_modules_dir}" ] && running_distribution="$(distro_version)"
 
3603
weak_modules="${WEAK_MODULES_BIN}"
 
3604
 
 
3605
# Source in /etc/dkms_framework.conf
 
3606
. $dkms_frameworkconf 2>/dev/null
 
3607
 
 
3608
# Clear out command line argument variables
 
3609
module=""
 
3610
module_version=""
 
3611
template_kernel=""
 
3612
distro=""
 
3613
media=""
 
3614
release=""
 
3615
conf=""
 
3616
kernel_config=""
 
3617
archive_location=""
 
3618
kernel_source_dir=""
 
3619
ksourcedir_fromcli=""
 
3620
action=""
 
3621
force=""
 
3622
no_prepare_kernel=""
 
3623
no_clean_kernel=""
 
3624
binaries_only=""
 
3625
source_only=""
 
3626
all=""
 
3627
module_suffix=""
 
3628
rpm_safe_upgrade=""
 
3629
size="1440";
 
3630
specfile=""
 
3631
legacy_postinst="1"
 
3632
unset directive_array
 
3633
unset kernelver_array
 
3634
unset arch_array
 
3635
 
 
3636
# Parse command line arguments
 
3637
while [ $# -gt 0 ]; do
 
3638
    case $1 in
 
3639
    --dkmsframework*)
 
3640
        if echo $1 | grep '=' >/dev/null ; then
 
3641
            dkms_frameworkconf=`echo $1 | sed 's/^.*=//'`
 
3642
        else
 
3643
            dkms_frameworkconf="$2"
 
3644
            shift
 
3645
        fi
 
3646
        #immediately load this config
 
3647
        . $dkms_frameworkconf 2> /dev/null
 
3648
        ;;
 
3649
    --module*|-m)
 
3650
        if echo $1 | grep '=' >/dev/null ; then
 
3651
            module=`echo $1 | sed 's/^.*=//'`
 
3652
        else
 
3653
            module="$2"
 
3654
            shift
 
3655
        fi
 
3656
        ;;
 
3657
    -v)
 
3658
        if echo $1 | grep '=' >/dev/null ; then
 
3659
            module_version=`echo $1 | sed 's/^.*=//'`
 
3660
        else
 
3661
            module_version="$2"
 
3662
            shift
 
3663
        fi
 
3664
        ;;
 
3665
    --kernelver*|-k)
 
3666
        if echo $1 | grep '=' >/dev/null ; then
 
3667
            kernelver_array[${#kernelver_array[@]}]=`echo $1 | sed 's/^.*=//'`
 
3668
        else
 
3669
            kernelver_array[${#kernelver_array[@]}]="$2"
 
3670
            shift
 
3671
        fi
 
3672
        ;;
 
3673
    --distro*|-d)
 
3674
        if echo $1 | grep '=' >/dev/null ; then
 
3675
            distro=`echo $1 | sed 's/^.*=//'`
 
3676
        else
 
3677
            distro="$2"
 
3678
            shift
 
3679
        fi
 
3680
        ;;
 
3681
    --media*)
 
3682
        if echo $1 | grep '=' >/dev/null ; then
 
3683
            media=`echo $1 | sed 's/^.*=//'`
 
3684
        else
 
3685
            media="$2"
 
3686
            shift
 
3687
        fi
 
3688
        ;;
 
3689
    --release*|-r)
 
3690
        if echo $1 | grep '=' >/dev/null ; then
 
3691
            release=`echo $1 | sed 's/^.*=//'`
 
3692
        else
 
3693
            release="$2"
 
3694
            shift
 
3695
        fi
 
3696
        ;;
 
3697
    --templatekernel*)
 
3698
        if echo $1 | grep '=' >/dev/null ; then
 
3699
            template_kernel=`echo $1 | sed 's/^.*=//'`
 
3700
        else
 
3701
            template_kernel="$2"
 
3702
            shift
 
3703
        fi
 
3704
        ;;
 
3705
    -c)
 
3706
        if echo $1 | grep '=' >/dev/null ; then
 
3707
            conf=`echo $1 | sed 's/^.*=//'`
 
3708
        else
 
3709
            conf="$2"
 
3710
            shift
 
3711
        fi
 
3712
        ;;
 
3713
    --quiet|-q)
 
3714
        exec >/dev/null 2>&1
 
3715
        ;;
 
3716
    --version|-V)
 
3717
        echo $"dkms: 2.1.1.2"
 
3718
        exit 0
 
3719
        ;;
 
3720
    --no-prepare-kernel)
 
3721
        no_prepare_kernel="no-prepare-kernel"
 
3722
        ;;
 
3723
    --no-clean-kernel)
 
3724
        no_clean_kernel="no-clean-kernel"
 
3725
        ;;
 
3726
    --binaries-only)
 
3727
        binaries_only="binaries-only"
 
3728
        ;;
 
3729
    --source-only)
 
3730
        source_only="source-only"
 
3731
        ;;
 
3732
    --force)
 
3733
        force="true"
 
3734
        ;;
 
3735
    --all)
 
3736
        all="true"
 
3737
        ;;
 
3738
    --verbose)
 
3739
        verbose="true"
 
3740
        ;;
 
3741
    --rpm_safe_upgrade)
 
3742
        rpm_safe_upgrade="true"
 
3743
        ;;
 
3744
    --dkmstree*)
 
3745
        if echo $1 | grep '=' >/dev/null ; then
 
3746
            dkms_tree=`echo $1 | sed 's/^.*=//'`
 
3747
        else
 
3748
            dkms_tree="$2"
 
3749
            shift
 
3750
        fi
 
3751
        ;;
 
3752
    --sourcetree*)
 
3753
        if echo $1 | grep '=' >/dev/null ; then
 
3754
            source_tree=`echo $1 | sed 's/^.*=//'`
 
3755
        else
 
3756
            source_tree="$2"
 
3757
            shift
 
3758
        fi
 
3759
        ;;
 
3760
    --installtree*)
 
3761
        if echo $1 | grep '=' >/dev/null ; then
 
3762
            install_tree=`echo $1 | sed 's/^.*=//'`
 
3763
        else
 
3764
            install_tree="$2"
 
3765
            shift
 
3766
        fi
 
3767
        ;;
 
3768
    --config*)
 
3769
        if echo $1 | grep '=' >/dev/null ; then
 
3770
            kernel_config=`echo $1 | sed 's/^.*=//'`
 
3771
        else
 
3772
            kernel_config="$2"
 
3773
            shift
 
3774
        fi
 
3775
        ;;
 
3776
    --archive*)
 
3777
        if echo $1 | grep '=' >/dev/null ; then
 
3778
            archive_location=`echo $1 | sed 's/^.*=//'`
 
3779
        else
 
3780
            archive_location="$2"
 
3781
            shift
 
3782
        fi
 
3783
        ;;
 
3784
    --legacy-postinst*)
 
3785
        if echo $1 | grep "=" >/dev/null ; then
 
3786
            legacy_postinst=`echo $1 | sed 's/^.*=//'`
 
3787
        else
 
3788
            legacy_postinst="$2"
 
3789
            shift
 
3790
        fi
 
3791
        ;;
 
3792
    --arch*|-a)
 
3793
        if echo $1 | grep '=' >/dev/null ; then
 
3794
            arch_array[${#arch_array[@]}]=`echo $1 | sed 's/^.*=//'`
 
3795
        else
 
3796
            arch_array[${#arch_array[@]}]="$2"
 
3797
            shift
 
3798
        fi
 
3799
        ;;
 
3800
    --size*)
 
3801
        if echo $1 | grep '=' >/dev/null ; then
 
3802
            size=`echo $1 | sed 's/^.*=//'`
 
3803
        else
 
3804
            size="$2"
 
3805
            shift
 
3806
        fi
 
3807
        ;;
 
3808
    --kernelsourcedir*)
 
3809
        if echo $1 | grep '=' >/dev/null ; then
 
3810
            kernel_source_dir=`echo $1 | sed 's/^.*=//'`
 
3811
        else
 
3812
            kernel_source_dir="$2"
 
3813
            shift
 
3814
        fi
 
3815
        ksourcedir_fromcli="true"
 
3816
        ;;
 
3817
    --directive*)
 
3818
        if echo $1 | grep '=' >/dev/null ; then
 
3819
            directive_array[${#directive_array[@]}]=`echo $1 | sed 's/[^=]\+=//'`
 
3820
        else
 
3821
            directive_array[${#directive_array[@]}]="$2"
 
3822
            shift
 
3823
        fi
 
3824
        ;;
 
3825
    --spec*)
 
3826
        if echo $1 | grep '=' >/dev/null ; then
 
3827
            specfile=`echo $1 | sed 's/^.*=//'`
 
3828
        else
 
3829
            specfile="$2"
 
3830
            shift
 
3831
        fi
 
3832
        ;;
 
3833
    -*|--*)
 
3834
        echo $"" >&2
 
3835
        echo $"Error!  Unknown option: $1" >&2
 
3836
        show_usage
 
3837
        exit 2
 
3838
        ;;
 
3839
    *)
 
3840
        action="$action $1"
 
3841
        ;;
 
3842
    esac
 
3843
    shift
 
3844
done
 
3845
 
 
3846
# Run the specified action
 
3847
for action_to_run in $action; do
 
3848
    case "$action_to_run" in
 
3849
    add)
 
3850
        add_module
 
3851
        ;;
 
3852
    remove)
 
3853
        # Make sure they're root
 
3854
        if [ `id -u` -ne 0 ]; then
 
3855
        echo $"You must be root to use this command." >&2
 
3856
        exit 1
 
3857
        fi
 
3858
        remove_module
 
3859
        ;;
 
3860
    build)
 
3861
        build_module
 
3862
        ;;
 
3863
    install)
 
3864
            # Make sure they're root
 
3865
        if [ `id -u` -ne 0 ]; then
 
3866
        echo $"You must be root to use this command." >&2
 
3867
        exit 1
 
3868
        fi
 
3869
        install_module
 
3870
        ;;
 
3871
    match)
 
3872
        # Make sure they're root
 
3873
        if [ `id -u` -ne 0 ]; then
 
3874
        echo $"You must be root to use this command." >&2
 
3875
        exit 1
 
3876
        fi
 
3877
        run_match
 
3878
        ;;
 
3879
    uninstall)
 
3880
        # Make sure they're root
 
3881
        if [ `id -u` -ne 0 ]; then
 
3882
        echo $"You must be root to use this command." >&2
 
3883
        exit 1
 
3884
        fi
 
3885
        uninstall_module
 
3886
        ;;
 
3887
    mkdriverdisk)
 
3888
        # Make sure they're root
 
3889
        if [ `id -u` -ne 0 ]; then
 
3890
        echo $"You must be root to use this command." >&2
 
3891
        exit 1
 
3892
        fi
 
3893
        make_driver_disk
 
3894
        ;;
 
3895
    mktarball)
 
3896
        make_tarball
 
3897
        ;;
 
3898
    mkrpm)
 
3899
        make_rpm
 
3900
        ;;
 
3901
    mkdeb)
 
3902
        make_debian "deb"
 
3903
        ;;
 
3904
    mkdsc)
 
3905
        make_debian "dsc"
 
3906
        ;;
 
3907
    mkkmp)
 
3908
        make_kmp
 
3909
        ;;
 
3910
    ldtarball)
 
3911
        # Make sure they're root if we're using --force
 
3912
        if [ `id -u` -ne 0 ] && [ "$force" == "true" ]; then
 
3913
        echo $"You must be root to use this command with the --force option." >&2
 
3914
        exit 1
 
3915
        fi
 
3916
        load_tarball
 
3917
        ;;
 
3918
    status)
 
3919
        show_status
 
3920
        ;;
 
3921
    "")
 
3922
        echo "" >&2
 
3923
        echo $"Error! No action was specified.">&2
 
3924
        show_usage
 
3925
        ;;
 
3926
    *)
 
3927
        echo "" >&2
 
3928
        echo $"Error! Unknown action specified: $action_to_run" >&2
 
3929
        show_usage
 
3930
        ;;
 
3931
    esac
 
3932
done