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
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.
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.
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
22
function invoke_command ()
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
37
[ $exitval -gt 0 ] && echo -en "(bad exit status: $exitval)"
43
function show_usage ()
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]"
59
# $1 = the symlink to read
63
while [ -L "$read_link" ]; do
64
read_link=`ls -l $read_link | sed 's/.*-> //'`
71
# $1 = kernel version string
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.
77
echo $1 | sed -e 's:\([^0-9]\)\([0-9]\):\1 \2:g' \
78
-e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
80
-e 's: \([0-9]\) : 00\1 :g' \
81
-e 's: \([0-9][0-9]\) : 0\1 :g' \
85
function set_module_suffix ()
87
# $1 = the kernel to base the module_suffix on
89
[ -z "$kernel_test" ] && kernel_test=`uname -r`
91
if [[ $(VER $kernel_test) < $(VER 2.5) ]]; then
98
function set_kernel_source_dir ()
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"
106
function setup_kernels_arches ()
108
# Error if # of arches doesn't match # of kernels
109
if [ ${#kernelver_array[@]} -ne ${#arch_array[@]} ] && [ ${#arch_array[@]} -gt 1 ]; then
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
116
# Check that kernel version and all aren't both set simultaneously
117
if [ -n "${kernelver_array[0]}" ] && [ -n "$all" ]; then
119
echo $"Error! You cannot specify a kernel version and also specify" >&2
120
echo $"--all on the command line." >&2
124
# Check that arch and all aren't both set simultaneously
125
if [ -n "${arch_array[0]}" ] && [ -n "$all" ]; then
127
echo $"Error! You cannot specify an arch and also specify" >&2
128
echo $"--all on the command line." >&2
132
# Check that the actions supports multiple kernels
134
add | build | install | match | uninstall | mkkmp )
135
if [ ${#kernelver_array[@]} -gt 1 ]; then
137
echo $"Error! The action $1 does not support multiple kernel version" >&2
138
echo $"parameters on the command line." >&2
141
if [ -n "$all" ]; then
143
echo $"Error! The action $1 does not support the --all" >&2
144
echo $"parameter." >&2
150
# If all is set, use dkms status to fill the arrays
151
if [ -n "$all" ] && [ "$1" != "status" ]; then
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/:$//'`
159
done < <($0 status -m "$module" -v "$module_version" 2>/dev/null | \
160
egrep "built|installed" | egrep -v 'installed-weak')
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"
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]}
187
# Set global multi_arch
190
while [ $i -lt ${#arch_array[@]} ]; do
191
[ "${arch_array[0]}" != "${arch_array[$i]}" ] && multi_arch="true"
198
# $1 = kernel version
199
/sbin/depmod -au "$1" -F "/boot/System.map-$1"
202
function remake_initrd()
204
# $1 = kernel version
208
local mkinitrd='mkinitrd'
211
# Support initramfs distributions (Debian/Ubuntu).
212
if [ -x "/usr/sbin/update-initramfs" ]; then
213
mkinitrd='update-initramfs'
216
$mkinitrd --version >/dev/null 2>&1
217
if [ "$?" -eq 0 ]; then
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
227
elif [ -e /etc/SuSE-release ] || [ -d /etc/SuSEconfig ]; then
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
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
246
elif [ -e /etc/debian_version ]; then
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
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
264
echo $"Calling $mkinitrd (bad exit status 9 may occur)"
265
invoke_command "$mkinitrd" "$mkinitrd" background
272
function distro_version_rpm()
274
local whatprovides_redhat
275
local whatprovides_suse
276
local whatprovides_sles
277
local whatprovides_ovm
282
if ! which rpm > /dev/null 2>&1 ; then
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 ;;
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
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')
313
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
314
# format is 3, 4, ...
318
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
319
# format is 3, 4, ...
323
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_ovm})
328
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
330
VER=$(echo "${VER}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
334
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
338
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_sles})
342
VER=$(rpm -q --qf "%{version}\n" ${whatprovides_suse})
352
function distro_version()
354
# What distribution are we running?
356
local LSB_DESCRIPTION
358
local DISTRIB_RELEASE
362
# try the LSB-provided strings first
363
if [ -r /etc/lsb-release ]; then
366
elif type lsb_release >/dev/null 2>&1; then
367
DISTRIB_ID=$(lsb_release -i -s)
368
DISTRIB_RELEASE=$(lsb_release -r -s)
372
case "${DISTRIB_ID}" in
373
Fedora) dist=fc${DISTRIB_RELEASE} ;;
374
RedHatEnterprise*) # OEL also reports as such
376
VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
381
VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
386
VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
390
LSB_DESCRIPTION="$(lsb_release -d -s)"
391
if echo "${LSB_DESCRIPTION}" | grep Enterprise > /dev/null 2>&1; then
392
dist=sles${DISTRIB_RELEASE}
394
dist=suse${DISTRIB_RELEASE}
398
if [ -n "${LSB_RELEASE}" -a -n "${DISTRIB_ID}" -a -n "${DISTRIB_RELEASE}" ]; then
399
dist="${DISTRIB_ID}${DISTRIB_RELEASE}"
404
if [ "${dist}" == "unknown" ]; then
405
dist=$(distro_version_rpm)
410
function override_dest_module_location()
412
local orig_location="$1"
413
[ -n "${addon_modules_dir}" ] && echo "/${addon_modules_dir}" && return
415
case "$running_distribution" in
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 ;;
430
echo "$orig_location"
433
function read_conf ()
435
# $1 kernel version (required)
437
# $3 dkms.conf location (optional)
442
# Find which conf file to check
445
elif [ -n "$conf" ]; then
446
read_conf_file="$conf"
448
read_conf_file="$dkms_tree/$module/$module_version/source/dkms.conf"
464
BUILD_EXCLUSIVE_KERNEL=""
465
BUILD_EXCLUSIVE_ARCH=""
473
unset modules_conf_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
494
# Set variables supported in dkms.conf files (eg. $kernelver)
497
set_kernel_source_dir "$1"
499
# Source in the dkms.conf
500
. $read_conf_file 2>/dev/null
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\""
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\""
522
package_name="$PACKAGE_NAME"
523
package_version="$PACKAGE_VERSION"
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"
532
# Set module naming/location arrays
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
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
545
modules_conf_obsolete_only[$index]="yes"
548
case "${STRIP[$index]}" in
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]}/"
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
571
# FAIL if built_module_name ends in .o or .ko
572
case "${built_module_name[$index]}" in
574
echo $"dkms.conf: Error! 'BUILT_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
579
# FAIL if dest_module_name ends in .o or .ko
580
case "${dest_module_name[$index]}" in
582
echo $"dkms.conf: Error! 'DEST_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
587
# Override location for specific kernels
588
dest_module_location[$index]="$(override_dest_module_location ${dest_module_location[$index]})"
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
595
# Fail if bad DEST_MODULE_LOCATION
596
case "${DEST_MODULE_LOCATION[$index]}" in
601
echo $"dkms.conf: Error! Directive 'DEST_MODULE_LOCATION' does not begin with">&2
602
echo $"'/kernel', '/updates', or '/extra' in record #$index.">&2
610
# Get the correct make command
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]}"
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"
627
if [ -z "$clean" ]; then
628
clean="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build clean"
631
if [ -z "$make_command" ]; then
632
make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
634
if [ -z "$clean" ]; then
635
clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
639
# Set modules_conf_array
641
while [ "$index" -lt ${#MODULES_CONF[@]} ]; do
642
[ -n "${MODULES_CONF[$index]}" ] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
646
# Set patch_array (including kernel specific patches)
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]}"
661
[ `echo "$REMAKE_INITRD" | grep -ic "^y"` -gt 0 ] && remake_initrd="yes"
664
if [ -n "$BUILD_EXCLUSIVE_KERNEL" ]; then
665
echo $1 | egrep -q "$BUILD_EXCLUSIVE_KERNEL" || build_exclude="yes"
667
if [ -n "$BUILD_EXCLUSIVE_ARCH" ]; then
668
echo $2 | egrep -q "$BUILD_EXCLUSIVE_ARCH" || build_exclude="yes"
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
677
# Fail if no PACKAGE_NAME
678
if [ -z "$package_name" ]; then
679
echo $"dkms.conf: Error! No 'PACKAGE_NAME' directive specified.">&2
683
# Fail if no PACKAGE_VERSION
684
if [ -z "$package_version" ]; then
685
echo $"dkms.conf: Error! No 'PACKAGE_VERSION' directive specified.">&2
690
[ -z "$clean" ] && clean="make clean"
696
function check_version_sanity ()
698
# $1 = kernel_version
700
# $3 = obs by kernel version
701
# $4 = dest_module_name
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'}`
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'}`
727
if [ -n "$kernels_ver_checksum" -a -n "$dkms_ver_checksum" -a \
728
"$kernels_ver_checksum" == "$dkms_ver_checksum" -a -z "$force" ]; then
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
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
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
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`
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
759
elif [[ ( $(VER $my_local) > $(VER $obs_local) ) ]]; then
760
#they were obsoleted in an earlier ABI bump of the kernel
762
elif [[ ( $(VER $my_local) = $(VER $obs_local) ) ]]; then
763
#they were obsoleted in this ABI bump of the kernel
766
elif [[ ( $(VER $my_upstream) > $(VER $obs_upstream) ) && -z "$force" ]]; then
767
#they were obsoleted in an earlier kernel release
772
if [ "$obsolete" == 1 ]; then
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
785
function moduleconfig_add ()
787
# $1 = kernel version
789
local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
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"
797
if [ -z "$modconfig_files" ]; then
798
modconfig_files="/etc/modprobe.d/$package_name.conf"
802
for moduleconfig in $modconfig_files; do
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]}'"
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]}'"
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
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))
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]}'"
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
859
# Delete the temp dir
860
rm -rf $temp_dir_name
864
function moduleconfig_remove ()
866
# $1 = kernel version
868
local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
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"
876
for moduleconfig in $modconfig_files; do
878
while [ $index -lt ${#dest_module_name[@]} ]; do
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
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
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"
909
# Remove static conf entries
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
921
# Delete the temp dir
922
rm -rf $temp_dir_name
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 ()
930
[ "$1" = "${l}" ] && return 0
935
function etc_sysconfig_kernel_modify ()
937
# Make a temp directory to store files
938
local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
940
if [ -e "/etc/sysconfig/kernel" ] && [ -n "$remake_initrd" ]; then
941
# Make /etc/sysconfig/kernel changes as necessary
942
if [ "$1" == "add" ]; then
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
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
962
# Delete the temp dir
963
rm -rf $temp_dir_name
966
function add_module ()
968
setup_kernels_arches "add"
970
# Check that we have all the arguments
971
if [ -z "$module" ] || [ -z "$module_version" ]; then
973
echo $"Error! Invalid number of arguments passed." >&2
974
echo $"Usage: add -m <module> -v <module-version>" >&2
978
if [ -z "$conf" ]; then
979
conf="$source_tree/$module-$module_version/dkms.conf"
982
# Check that /usr/src/$module-$module_version exists
983
if ! [ -d "$source_tree/$module-$module_version" ]; then
985
echo $"Error! Could not find module source directory." >&2
986
echo $"Directory: $source_tree/$module-$module_version does not exist." >&2
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
998
# Check that this module-version hasn't already been added
999
if [ -d "$dkms_tree/$module/$module_version" ]; then
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
1006
# Check that the conf file exists or any other script specified
1007
if ! [ -e "$conf" ]; then
1009
echo $"Error! Could not locate dkms.conf file." >&2
1010
echo $"File: $conf does not exist." >&2
1014
# Check the conf file for sanity
1015
read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
1016
if [ "$?" -ne 0 ]; then
1018
echo $"Error! Bad conf file." >&2
1019
echo $"File: $conf" >&2
1020
echo $"does not represent a valid dkms.conf file." >&2
1024
# Create the necessary dkms tree structure
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"
1031
# Run the post_add script
1032
if [ -n "$post_add" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_add" | sed 's/ .*//'` ]; then
1034
echo $"Running the post_add script:"
1035
$dkms_tree/$module/$module_version/source/$post_add
1039
echo $"DKMS: add Completed."
1042
function prepare_kernel()
1044
# $1 = kernel version to prepare
1045
# $2 = arch to prepare
1047
set_kernel_source_dir "$1"
1049
# Check that kernel-source exists
1050
if ! [ -e "$kernel_source_dir/include" ]; then
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
1057
echo $", or you could install the linux-headers-$1 package."
1066
if [ -n "$no_prepare_kernel" ]; then
1070
if [[ (! ( $(VER $1) < $(VER 2.6.5) ) || (-d /etc/SuSEconfig)) && \
1071
-d "$kernel_source_dir" && \
1072
-z "$ksourcedir_fromcli" ]]; then
1074
echo $"Kernel preparation unnecessary for this kernel. Skipping..."
1075
no_clean_kernel="no-clean-kernel"
1079
# Prepare kernel for module build
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"
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=""
1096
[ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2.config"
1097
[ ! -e "$kernel_config" ] && kernel_config=""
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
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=""
1111
[ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.default"
1112
[ ! -e "$kernel_config" ] && kernel_config=""
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
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)"
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
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
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
1154
echo $"Running Generic preparation routine"
1155
invoke_command "make mrproper" "make mrproper" background
1156
[ -n "$config_contents" ] && echo "$config_contents" > .config
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)"
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
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
1175
invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
1181
function list_each_installed_module ()
1184
# $2 = kernel version
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))
1195
function set_weak_modules()
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'
1202
function install_module()
1204
setup_kernels_arches "install"
1205
local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
1207
# Check that the right arguments were passed
1208
if [ -z "$module" ] || [ -z "$module_version" ]; then
1210
echo $"Error! Invalid number of parameters passed." >&2
1211
echo $"Usage: install -m <module> -v <module-version>" >&2
1215
# Check that $module-$module_version exists by checking the source symlink
1216
if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
1218
echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
1219
echo $"Build cannot continue without the proper tree." >&2
1223
# Make sure that kernel exists to install into
1224
if ! [ -e "$install_tree/${kernelver_array[0]}" ]; then
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
1231
# Read the conf file
1232
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
1233
if [ "$?" -ne 0 ]; then
1235
echo $"Error! Bad conf file." >&2
1236
echo $"Your dkms.conf is not valid." >&2
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
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
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
1256
echo $"Error! This module/version combo is already installed" >&2
1257
echo $"for kernel: ${kernelver_array[0]} (${arch_array[0]})" >&2
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
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]}"
1272
while [ "$count" -lt ${#built_module_name[@]} ]; do
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))
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
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
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* ) ;;
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]}/"
1316
found_original="yes"
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"
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"
1329
echo $" - This kernel never originally had a module by this name"
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* ) ;;
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/"
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* ) ;;
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"
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"
1361
count=$(($count + 1))
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
1368
# add to kabi-tracking
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
1375
# Run the post_install script
1376
if [ -n "$post_install" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_install" | sed 's/ .*//'` ]; then
1378
echo $"Running post_install:"
1379
$dkms_tree/$module/$module_version/source/$post_install
1382
# Make modules.conf changes as necessary
1384
moduleconfig_add "${kernelver_array[0]}"
1385
etc_sysconfig_kernel_modify "add"
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)"
1391
while [ "$count" -lt "${#built_module_name[@]}" ]; do
1392
if echo "$unresolved_symbols" | grep -q "${dest_module_name[$count]}$module_suffix$"; then
1394
echo $"Problems with depmod detected. Automatically uninstalling this module."
1396
do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
1398
echo $"DKMS: Install Failed (depmod problems). Module rolled back to built state."
1401
count=$(($count + 1))
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."
1411
do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
1413
echo $"DKMS: Install Failed (mkinitrd problems). Module rolled back to built state."
1419
echo $"DKMS: install Completed."
1423
function prepare_build()
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]}"
1429
# Check that the right arguments were passed
1430
if [ -z "$module" ] || [ -z "$module_version" ]; then
1432
echo $"Error! Invalid number of parameters passed." >&2
1433
echo $"Usage: build -m <module> -v <module-version>" >&2
1437
# Check that source symlink works
1438
if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
1440
echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
1441
echo $"Build cannot continue without the proper tree." >&2
1445
# Check that the module has not already been built for this kernel
1446
if [ -d "$base_dir" ]; then
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
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
1459
echo $"Error! Bad conf file." >&2
1460
echo $"Your dkms.conf is not valid." >&2
1464
# Error out if build_exclude is set
1465
if [ -n "$build_exclude" ]; then
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
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
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
1480
prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
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"
1486
# Run the pre_build script
1487
if [ -n "$pre_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_build" | sed 's/ .*//'` ]; then
1489
echo $"Running the pre_build script:"
1490
$dkms_tree/$module/$module_version/source/$pre_build
1493
cd "$dkms_tree/$module/$module_version/build"
1497
while [ $index -lt ${#patch_array[@]} ]; do
1498
if ! [ -e "$dkms_tree/$module/$module_version/build/patches/${patch_array[$index]}" ]; then
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
1504
invoke_command "patch -p1 < ./patches/${patch_array[$index]}" "applying patch ${patch_array[$index]}"
1505
if [ "$?" -ne 0 ]; then
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
1518
local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
1520
echo $"Building module:"
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]}/"`
1527
invoke_command "$the_make_command >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background
1529
# Make sure good return status
1530
if [ "$?" -ne 0 ]; then
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
1537
echo $"DO YOU HAVE gcc INSTALLED???" >&2
1539
if grep -ic "make: command not found" "$dkms_tree/$module/$module_version/build/make.log"; then
1541
echo $"DO YOU HAVE make INSTALLED???" >&2
1543
report_build_problem
1547
# Make sure all the modules built successfully
1549
while [ "$count" -lt "${#built_module_name[@]}" ]; do
1550
if ! [ -e "${built_module_location[$count]}${built_module_name[$count]}$module_suffix" ]; then
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
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
1567
# Save a copy of the new module
1568
mkdir "$base_dir/module" >/dev/null
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
1576
# Run the post_build script
1577
if [ -n "$post_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_build" | sed 's/ .*//'` ]; then
1579
echo $"Running the post_build script:"
1580
$dkms_tree/$module/$module_version/source/$post_build
1584
function clean_build()
1586
# Run the clean commands
1587
cd "$dkms_tree/$module/$module_version/build"
1588
invoke_command "$clean" "cleaning build area" background
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
1604
# Clean the build directory
1605
rm -rf "$dkms_tree/$module/$module_version/build/*"
1608
function build_module()
1614
echo $"DKMS: build Completed."
1617
function possible_dest_module_locations()
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.
1626
location[0]="${dest_module_location[$count]}"
1627
[ "${DEST_MODULE_LOCATION[$count]}" != "${dest_module_location[$count]}" ] && \
1628
location[1]="${DEST_MODULE_LOCATION[$count]}"
1630
echo "${location[0]} ${location[1]}"
1633
function find_actual_dest_module_location()
1637
local kernelver="$3"
1639
local locations="$(possible_dest_module_locations $count)"
1643
dkms_owned="${dkms_tree}/${module}/kernel-${kernelver}-${arch}/module/${dest_module_name[$count]}${module_suffix}"
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
1655
function do_uninstall()
1657
# $1 = kernel version
1661
echo $"-------- Uninstall Beginning --------"
1662
echo $"Module: $module"
1663
echo $"Version: $module_version"
1664
echo $"Kernel: $1 ($2)"
1665
echo $"-------------------------------------"
1667
set_module_suffix "$1"
1669
# If kernel-<kernelver> symlink points to this module, check for original_module and put it back
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
1677
echo $"Status: Before uninstall, this module version was ACTIVE on this kernel."
1678
# remove kabi-tracking if last instance removed
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
1687
while [ "$count" -lt "${#built_module_name[@]}" ]; do
1688
real_dest_module_location="$(find_actual_dest_module_location $module $count $1 $2)"
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* ) ;;
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
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."
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
1715
moduleconfig_remove "$1"
1720
rm -f "$dkms_tree/$module/kernel-$1-$2"
1723
echo $"Status: This module version was INACTIVE for this kernel."
1726
# Run the post_remove script
1727
if [ -n "$post_remove" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_remove" | sed 's/ .*//'` ]; then
1729
echo $"Running the post_remove script:"
1730
$dkms_tree/$module/$module_version/source/$post_remove
1733
# Run depmod because we changed /lib/modules
1734
invoke_command "do_depmod $1" "depmod" background
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
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."
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
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
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."
1760
[ -z "`find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/original_module"
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"
1767
echo $"DKMS: uninstall Completed."
1770
function uninstall_module ()
1772
setup_kernels_arches "uninstall"
1774
# Check that the right arguments were passed
1775
if [ -z "$module" ] || [ -z "$module_version" ]; then
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
1783
# Check that $module is in the dkms tree
1784
if ! [ -d "$dkms_tree/$module" ]; then
1786
echo $"Error! There are no instances of module: $module" >&2
1787
echo $"located in the DKMS tree." >&2
1791
# Make sure that its installed in the first place
1792
if ! [ -d "$dkms_tree/$module/$module_version" ]; then
1794
echo $"Error! The module/version combo: $module-$module_version" >&2
1795
echo $"is not located in the DKMS tree." >&2
1799
# Read the conf file
1800
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
1801
if [ "$?" -ne 0 ]; then
1803
echo $"Error! Bad conf file." >&2
1804
echo $"Your dkms.conf is not valid." >&2
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]}"
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
1821
function remove_module ()
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
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
1832
setup_kernels_arches "remove"
1834
# Check that $module is in the dkms tree
1835
if ! [ -d "$dkms_tree/$module/$module_version" ]; then
1837
echo $"Error! There are no instances of module: $module" >&2
1838
echo $"$module_version located in the DKMS tree." >&2
1843
while [ $i -lt ${#kernelver_array[@]} ]; do
1845
# make sure its there first before removing
1846
if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
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
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
1862
echo $"DKMS: Remove cancelled because --rpm_safe_upgrade scenario detected."
1869
# Read the conf file
1870
read_conf "${kernelver_array[$i]}" "${arch_array[$i]}"
1871
if [ "$?" -ne 0 ]; then
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
1879
do_uninstall "${kernelver_array[$i]}" "${arch_array[$i]}"
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]}"
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
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"
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
1903
# Its now safe to completely remove references in /etc/sysconfig/kernel for SuSE
1904
etc_sysconfig_kernel_modify "delete"
1908
function find_module_from_ko()
1912
local basename_ko=$(basename "${ko}")
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
1923
# be careful. string_array is global
1924
declare -a string_array
1925
function add_string_to_array_unique()
1930
while [ "$count" -lt "${#string_array[@]}" ]; do
1931
if [ "$1" == "${string_array[$count]}" ]; then
1935
count=$(($count + 1))
1937
if [ "${found}" -eq 0 ]; then
1938
string_array[${#string_array[@]}]="$1"
1942
function print_string_array()
1945
while [ "$count" -lt "${#string_array[@]}" ]; do
1946
echo "${string_array[$count]}"
1947
count=$(($count + 1))
1951
function do_status_weak ()
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
1967
[ -z "$r_mod" ] && depth=2
1968
# recognize weak modules. These are in $kern/weak-updates but are symlinks to another $kern/extra file.
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)
1975
installed_ko="$read_link"
1976
if [ ! -e "$installed_ko" ]; then
1977
# dangling symlink, ouch, but is somebody else's problem so ignore it
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")
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"
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
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"
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))"
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"
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)"
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!)"
2070
[ -d "$working_dir" ] && echo "$stat_display $state $extra_status"
2076
setup_kernels_arches "status"
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]}"
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]}"
2091
function create_temporary_trees ()
2093
if [ -n "$module" ] || [ -n "$module_version" ]; then
2097
[ -r dkms.conf ] || return
2100
module="$PACKAGE_NAME"
2101
module_version="$PACKAGE_VERSION"
2103
source_tree=`mktemp -d`
2104
dkms_tree=`mktemp -d`
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
2110
temporary_trees_del_command="rm -rf $source_tree $dkms_tree"
2113
function delete_temporary_trees ()
2115
$temporary_trees_del_command
2116
if [ -n "$temporary_trees_del_command" ]; then
2121
temporary_trees_del_command=
2125
function in_temporary_trees ()
2127
[ -n "$temporary_trees_del_command" ]
2133
if [ "$media" == "floppy" ] ||
2134
[ "$media" == "iso" ] ||
2135
[ "$media" == "tar" ]; then
2143
setup_kernels_arches "mkdriverdisk"
2145
# Check that the right arguments were passed
2146
if [ -z "$module" ] || [ -z "$module_version" ] || [ -z "$distro" ] || [ -z "${kernelver_array[0]}" ]; then
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
2153
# default to floppy media
2154
[ -z "$media" ] && media="floppy"
2156
if [ $? -eq 1 ]; then
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
2163
# Check that source symlink works
2164
if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
2166
echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
2167
echo $"Build cannot continue without the proper tree." >&2
2171
# Confirm that distro is supported
2173
redhat | redhat[12] | suse | UnitedLinux | ubuntu)
2177
echo $"Error! Invalid distro argument. Currently, the distros" >&2
2178
echo $"supported are: redhat, redhat1, redhat2, suse, UnitedLinux" >&2
2184
# Read the conf file
2185
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
2186
if [ "$?" -ne 0 ]; then
2188
echo $"Error! Bad conf file." >&2
2189
echo $"Your dkms.conf is not valid." >&2
2195
make_redhat_driver_disk
2198
make_ubuntu_driver_disk
2201
make_suse_driver_disk
2207
make_driver_disk_floppy()
2209
local image_name="$1"
2210
local source_dir="$2"
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
2227
local mntdir=`mktemp -d $tmp_location/dkms.XXXXXX`
2228
if [ -z "$mntdir" ]; then
2230
echo $"Error: Could not create a temporary directory, failing."
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"
2240
make_driver_disk_isotar()
2243
local image_name="$2"
2244
local source_dir="$3"
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
2253
make_driver_disk_media()
2255
echo "Copying files $2"
2259
make_driver_disk_floppy "$1" "$2"
2262
make_driver_disk_isotar "iso" "$1" "$2"
2265
make_driver_disk_isotar "tar" "$1" "$2"
2270
driver_disk_suffix()
2287
make_redhat_driver_disk()
2289
# kludge to allow redhat1 driver disks with BOOT kernel modules (arch i386)
2290
if [ "$distro" == "redhat1" ] && [ "$multi_arch" == "true" ]; then
2292
local redhat1_okay="true"
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]}"
2302
if [ "$redhat1_okay" == "false" ]; then
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
2311
if [ "$distro" == "redhat2" ] || [ "$multi_arch" == "true" ] && [ -z "$redhat1_okay" ]; then
2312
echo $"Creating Red Hat v2 driver disk (arch support)."
2314
local rhdd_filename="rhdd"
2316
echo $"Creating Red Hat v1 driver disk."
2318
local rhdd_filename="rhdd-6.1"
2321
cpioarchive_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
2322
if [ -z "$cpioarchive_dir_name" ]; then
2324
echo $"Error: Could not create a temporary directory, failing."
2329
while [ $i -lt ${#kernelver_array[@]} ]; do
2330
set_module_suffix "${kernelver_array[$i]}"
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]}"
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
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
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]}"
2349
kernel_version_list="$kernel_version_list-kernel${kernelver_array[$i]}-${arch_array[$i]}"
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/"
2355
modules_cgz_list="$dd_prefix/${dest_module_name[$count]}$module_suffix\n${modules_cgz_list}"
2362
# Create directory and necessary files
2363
driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
2364
if [ -z "$driver_disk_dir" ]; then
2366
echo $"Error: Could not create a temporary directory, failing."
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.
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
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
2385
echo "$module-$module_version driver disk" > "$driver_disk_dir/$rhdd_filename"
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"
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"
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/"
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}"
2408
depmod -n ${f} 2>/dev/null | grep ^alias > ${tmp_alias}
2409
if [ -s ${tmp_alias} ]; then
2410
cat ${tmp_alias} >> ./modules.alias
2413
[ -e ./modules.alias ] && cp -f ./modules.alias "$driver_disk_dir/"
2415
# FIXME: add rpms/ directory, copy in KMP RPMs, run createrepo --pretty
2418
rm -rf "$cpioarchive_dir_name"
2420
mkdir -p "$image_dir"
2421
rm -f "$image_dir/$image_name"
2423
cd "$driver_disk_dir"
2424
make_driver_disk_media "$image_dir/$image_name" "$driver_disk_dir"
2426
rm -rf "$driver_disk_dir"
2429
echo $"Disk image location: $image_dir/$image_name"
2431
echo $"DKMS: mkdriverdisk Completed."
2434
find_external_dependencies()
2440
# find all module dependencies
2441
while [ "$count" -lt "${#dest_module_name[@]}" ]; do
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'))
2452
# prune internally satisfied dependencies
2454
while [ "$i" -lt "${#deps[@]}" ]; do
2455
for mod in ${dest_module_name[@]}; do
2456
[ "${deps[i]}" == "$mod" ] && deps[i]=
2462
while [ "$i" -lt "${#deps[@]}" ]; do
2468
make_suse_driver_disk()
2470
if [ -z "$release" ]; then
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
2478
local driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
2479
if [ -z "$driver_disk_dir" ]; then
2481
echo $"Error: Could not create a temporary directory, failing."
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"
2489
echo $"Creating driver disk:"
2491
local deps="$(find_external_dependencies)"
2494
if [ -n "${deps[*]}" ]; then
2495
# reserve a place for dependencies
2500
while [ "$count" -lt "${#dest_module_name[@]}" ]; do
2503
local topdir=`printf "%02d" $(($count+1+offset))`
2504
while [ "$i" -lt "${#kernelver_array[@]}" ]; do
2505
set_module_suffix "${kernelver_array[$i]}"
2507
if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
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
2514
# FIXME: add check for KMP binary RPMs to include in the driver disk
2515
suse_arch=${arch_array[$i]}
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]}/"
2526
case ${kernelver_array[$i]} in
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/"
2533
# create directory for dependency information
2534
[ -n "${deps[*]}" ] && mkdir -p "$driver_disk_dir/01/linux/$distro/$suse_arch-$release/modules"
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
2545
mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install"
2546
mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/modules"
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/"
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]}"
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..."
2568
echo "kernlist=\"${postkernels}\""
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}'
2576
chmod a+x ${dstfile}
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
2583
echo $" Warning! No kernel modules found for -default kernel."
2586
rm -fr "$driver_disk_dir/$topdir/$arch_release"
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"
2602
# FIXME: add suse-equivalent rpms/ directory, copy in KMP RPMs, run createrepo --pretty
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"
2609
rm -rf "$driver_disk_dir"
2612
echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
2614
echo $"DKMS: mkdriverdisk Completed."
2617
make_ubuntu_driver_disk()
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"
2623
local tempdir=`mktemp -d $tmp_location/dkms.XXXXXX`
2624
if [ -z "$tempdir" ]; then
2626
echo $"Error: Could not create a temporary directory, failing."
2630
# Check that the dh_make command is present
2631
if ! which dpkg-deb >/dev/null 2>&1 ; then
2633
echo $"Error! dpkg-deb not present." >&2
2634
echo $"Install the dpkg-dev package." >&2
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"
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
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
2657
mkdir -p "$tempdir/$dd_prefix"
2658
echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix..."
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"
2667
pushd "$deb_dir" > /dev/null 2>&1
2669
cat > DEBIAN/control <<EOF
2670
Package: ${module}-modules-${kernelver_array[$i]}
2671
Version: ${module_version}-1
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).
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
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}"
2697
popd > /dev/null 2>&1
2701
echo "Copying source..."
2702
mkdir -p "$tempdir/ubuntu"
2703
cp -ar "$source_tree/$module-$module_version" "$tempdir/ubuntu/"
2705
mkdir -p "$image_dir"
2706
rm -f "$image_dir/$image_name"
2708
make_driver_disk_media "$image_dir/$image_name" "$tempdir"
2712
echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
2714
echo $"DKMS: mkdriverdisk Completed."
2719
setup_kernels_arches "mktarball"
2721
make_common_test "mktarball"
2723
# Check for dkms_dbversion
2724
if ! [ -e "$dkms_tree/dkms_dbversion" ]; then
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
2731
# Error out if archive_location is set and contains a "/" in it
2732
case "$archive_location" in
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."
2741
# Error out if binaries-only is set and source-only is set
2742
if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
2744
echo $"Error! You have specified both --binaries-only and --source-only." >&2
2745
echo $"You cannot do this." >&2
2749
# Read the conf file
2750
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
2751
if [ "$?" -ne 0 ]; then
2753
echo $"Error! Bad conf file." >&2
2754
echo $"Your dkms.conf is not valid." >&2
2758
temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
2759
mkdir -p $temp_dir_name/dkms_main_tree
2761
if [ -n "$source_only" ]; then
2762
kernel_version_list="source-only"
2765
while [ $i -lt ${#kernelver_array[@]} ]; do
2767
if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
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
2775
set_module_suffix "${kernelver_array[$i]}"
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]}"
2781
kernel_version_list="${kernel_version_list}-kernel${kernelver_array[$i]}-${arch_array[$i]}"
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]}"
2790
# Store the dkms_dbversion in the tarball
2791
cp -f "$dkms_tree/dkms_dbversion" "$temp_dir_name/dkms_main_tree/"
2793
# Copy the source_tree or make special binaries-only structure
2794
if [ -z "$binaries_only" ]; then
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
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
2811
if [ `echo $kernel_version_list | wc -m | awk {'print $1'}` -gt 200 ]; then
2812
kernel_version_list="manykernels"
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
2818
if [ "$?" -eq 0 ]; then
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/
2823
echo $"Tarball location: $dkms_tree/$module/$module_version/tarball/$tarball_name"
2825
echo $"DKMS: mktarball Completed."
2826
rm -rf $temp_dir_name
2829
echo $"Error! Failed to make tarball." >&2
2830
rm -rf $temp_dir_name
2837
setup_kernels_arches "mktarball"
2839
# Error out of --archive was not set with the tarball location
2840
if [ -z "$archive_location" ]; then
2842
echo $"Error! Invalid number of parameters passed." >&2
2843
echo $"Usage: ldtarball --archive=<tarball-location>" >&2
2847
# Error out if $archive_location does not exist
2848
if ! [ -e "$archive_location" ]; then
2850
echo $"Error! Cannot locate $archive_location." >&2
2851
echo $"File does not exist." >&2
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"
2860
if `bzip2 -t $archive_location 2>/dev/null`; then
2861
tar_options="${tar_options}j"
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
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
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
2881
# Make sure its a sane tarball
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
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
2896
read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
2897
if [ "$?" -ne 0 ]; then
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
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
2910
echo $"Error! Tarball does not appear to be a correctly formed" >&2
2911
echo $"DKMS archive." >&2
2912
rm -rf $temp_dir_name
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
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."
2924
. $temp_dir_name/dkms_binaries_only/dkms.conf 2>/dev/null
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
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
2938
echo $"Error! Tarball does not appear to be a correctly formed" >&2
2939
echo $"DKMS archive." >&2
2940
rm -rf $temp_dir_name
2943
is_from_mktarball="true"
2944
tarball_source_tree_name="dkms_source_tree"
2947
echo $"Error! Tarball does not appear to be a correctly formed" >&2
2948
echo $"DKMS archive." >&2
2949
rm -rf $temp_dir_name
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"
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
2961
# Make sure we got what we needed from the tarball
2962
module="$PACKAGE_NAME"
2963
module_version="$PACKAGE_VERSION"
2966
echo $"Loading tarball for module: $module / version: $module_version"
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
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
2980
mkdir -p $dkms_tree/$module/$module_version
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
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]}"
2997
dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_to_load/$arch_to_load"
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
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/
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"
3020
rm -rf $temp_dir_name
3023
echo $"DKMS: ldtarball Completed."
3028
setup_kernels_arches "match"
3029
set_kernel_source_dir "${kernelver_array[0]}"
3031
# Error if $template_kernel is unset
3032
if [ -z "$template_kernel" ]; then
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
3040
# Error out if $template_kernel = $kernel_version
3041
if [ "$template_kernel" == "${kernelver_array[0]}" ]; then
3043
echo $"Error! The templatekernel and the specified kernel version are the same." >&2
3047
# Read in the status of template_kernel
3048
local template_kernel_status=`$0 status -k $template_kernel -a ${arch_array[0]} | grep ": installed"`
3050
# If $module is set, grep the status only for that module
3051
if [ -n "$module" ]; then
3053
# Make sure that its installed in the first place
3054
if ! [ -d "$dkms_tree/$module/" ]; then
3056
echo $"Error! The module: $module is not located in the DKMS tree." >&2
3060
template_kernel_status=`echo "$template_kernel_status" | grep "^$module,"`
3064
echo $"Matching modules in kernel: ${kernelver_array[0]} (${arch_array[0]})"
3065
echo $"to the configuration of kernel: $template_kernel (${arch_array[0]})"
3067
# Prepare the kernel just once but only if there is actual work to do
3068
if [ -z "$template_kernel_status" ]; then
3070
echo $"There is nothing to be done for this match."
3072
prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
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/,$//'`
3079
# Print out a match header
3081
echo $"---- Match Beginning ----"
3082
echo $"Module: $template_module"
3083
echo $"Version: $template_version"
3084
echo $"-------------------------"
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
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
3092
echo $"This module/version combo is built. Installing it:"
3093
module="$template_module"
3094
module_version="$template_version"
3098
echo $"Building & Installing this module/version:"
3099
module="$template_module"
3100
module_version="$template_version"
3104
done < <(echo "$template_kernel_status")
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
3123
echo $"DKMS: match Completed."
3128
setup_kernels_arches "mkrpm"
3130
make_common_test "mkrpm"
3132
# Check that the rpmbuild command is present
3133
if ! which rpmbuild >/dev/null 2>&1 ; then
3135
echo $"Error! rpmbuild not present." >&2
3136
echo $"Install the rpm-build package." >&2
3140
# Read the conf file
3141
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
3142
if [ "$?" -ne 0 ]; then
3144
echo $"Error! Bad conf file." >&2
3145
echo $"Your dkms.conf is not valid." >&2
3149
local rpm_basedir="$dkms_tree/$module/$module_version/rpm"
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"
3160
echo $"Cannot find /etc/dkms/template-dkms-mkrpm.spec which is needed by" >&2
3161
echo $"DKMS in order use mkrpm." >&2
3165
# Error out if binaries-only is set and source-only is set
3166
if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
3168
echo $"Error! You have specified both --binaries-only and --source-only." >&2
3169
echo $"You cannot do this." >&2
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"
3179
while [ $i -lt ${#kernelver_array[@]} ]; do
3180
if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
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
3187
echo $"Marking ${kernelver_array[$i]} (${arch_array[$i]}) for RPM..."
3188
mktarball_line="-k ${kernelver_array[$i]} -a ${arch_array[$i]} $mktarball_line"
3192
mktarball_line="none"
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
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"
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"
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}/
3216
cat ${temp_dir_name}/rpmbuild.log | grep ^Wrote | sed -e "s:${temp_dir_name}/:${rpm_basedir}/:" -e 's:SRPMS/::' -e 's:RPMS/.*/::'
3218
echo $"DKMS: mkrpm Completed."
3221
echo $"Error! There was a problem creating your rpm." >&2
3222
cat ${temp_dir_name}/rpmbuild.log >&2
3225
rm -rf $temp_dir_name
3226
trap > /dev/null 2>&1
3227
[ ${RC} -ne 0 ] && exit ${RC}
3230
function preproc_file()
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"
3241
function make_debian_test_depends()
3244
# Check that the fakeroot command is present
3245
if ! which fakeroot >/dev/null 2>&1 ; then
3246
INSTALL_PACKAGES="fakeroot $INSTALL_PACKAGES"
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"
3253
echo "$INSTALL_PACKAGES"
3256
function make_debian()
3260
create_temporary_trees
3261
trap "delete_temporary_trees" EXIT HUP TERM
3263
make_common_test "mk${create_type}"
3265
debian_package=$(echo $module | sed s/_/-/g)
3268
#Synaptic availablity
3269
if [ -x /usr/sbin/synaptic ]; then
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"
3287
# Read the conf file
3288
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
3289
if [ "$?" -ne 0 ]; then
3291
echo $"Error! Bad conf file." >&2
3292
echo $"Your dkms.conf is not valid." >&2
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
3301
echo $"Error! Missing $INSTALL_PACKAGES" >&2
3302
echo $"and unable to install. Please ask an admin to install for you." >&2
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
3311
$ROOT apt-get -y install $INSTALL_PACKAGES
3314
INSTALL_PACKAGES="`make_debian_test_depends`"
3316
if [ ! -z "$INSTALL_PACKAGES" ]; then
3318
echo $"Error! Missing $INSTALL_PACKAGES" >&2
3319
echo $"and unable to install. Please ask an admin to install for you." >&2
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}"
3330
elif [ -e "${local_mk}" ]; then
3331
echo $"Using ${local_mk}"
3335
echo $"Cannot find ${local_mk} which is needed by" >&2
3336
echo $"DKMS in order to use mk${create_type}." >&2
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"
3350
popd > /dev/null 2>&1
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"
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"
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"
3371
echo $"Error! Unable to find created tarball." >&2
3376
#calculate destination directory
3377
deb_basedir=$dkms_tree/$module/$module_version/${create_type}
3378
mkdir -p ${deb_basedir} >/dev/null 2>&1
3381
pushd "$temp_dir_debian" > /dev/null 2>&1
3382
case "$create_type" in
3384
invoke_command "dpkg-buildpackage -S -us -uc 1>/dev/null" "Building source package"
3385
if [ "$?" -eq 0 ]; then
3387
echo $"DKMS: mk${create_type} Completed."
3390
echo $"Error! There was a problem creating your ${create_type}." >&2
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"
3396
invoke_command "dpkg-buildpackage -rfakeroot -d -b -us -uc 1>/dev/null" "Building binary package"
3397
if [ "$?" -eq 0 ]; then
3399
echo $"DKMS: mk${create_type} Completed."
3402
echo $"Error! There was a problem creating your ${create_type}." >&2
3406
invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_all.deb' '$deb_basedir'" "Moving built files to $deb_basedir"
3409
popd > /dev/null 2>&1
3411
if in_temporary_trees; then
3412
echo "Copying built files to "`pwd`"/.." >&2
3413
cp "$dkms_tree/$module/$module_version/deb/"* ..
3417
invoke_command "rm $temp_dir -fr" "Cleaning up temporary files"
3418
delete_temporary_trees
3421
if [ "$?" -ne 0 ]; then
3423
echo $"Error! There was a problem cleaning up temporary files." >&2
3428
function make_common_test()
3430
local create_type=$1
3431
# Error if $module_version is set but $module is not
3432
if [ -z "$module" ] || [ -z "$module_version" ]; then
3434
echo $"Error! Invalid number of parameters passed." >&2
3435
echo $"Usage: $create_type -m <module> -v <module-version>" >&2
3439
# Check that source symlink works
3440
if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
3442
echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
3443
echo $"Build cannot continue without the proper tree." >&2
3447
# Make sure that its installed in the first place
3448
if ! [ -d "$dkms_tree/$module/$module_version" ]; then
3450
echo $"Error! The module/version combo: $module-$module_version" >&2
3451
echo $"is not located in the DKMS tree." >&2
3455
# Error out if archive_location is set and contains a "/" in it
3456
case "$archive_location" in
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."
3465
# Error out if binaries-only is set and source-only is set
3466
if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
3468
echo $"Error! You have specified both --binaries-only and --source-only." >&2
3469
echo $"You cannot do this." >&2
3474
function make_kmp_srpm()
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
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}'`
3495
echo $"rpmbuild error log:"
3496
cat $temp_dir_name/rpmbuild.log
3498
popd > /dev/null 2>&1
3499
rm -rf $temp_dir_name
3500
trap > /dev/null 2>&1
3504
function report_build_problem()
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
3515
setup_kernels_arches "mkkmp"
3517
make_common_test "mkkmp"
3519
# Read the conf file
3520
read_conf "${kernelver_array[0]}" "${arch_array[0]}"
3521
if [ "$?" -ne 0 ]; then
3523
echo $"Error! Bad conf file." >&2
3524
echo $"Your dkms.conf is not valid." >&2
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"
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
3547
if [ "$RC" -eq 0 ]; then
3549
echo $"KMP SRPM location: $RPMS"
3551
echo $"DKMS: mkkmp Completed."
3554
echo $"Error! There was a problem creating your KMP source rpm." >&2
3557
# FIXME: hand SRPM to mock or build system to build
3560
#############################
3562
#### Program Starts Here ####
3564
#############################
3571
PATH="$PATH:/usr/sbin"
3581
PATH="$PATH:/usr/lib/dkms"
3583
# Ensure files and directories we create are readable to anyone,
3584
# since we aim to build as a non-root user
3587
# Unset environment variables that may interfere with the build
3588
unset CC CXX CFLAGS CXXFLAGS LDFLAGS
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"
3597
dkms_frameworkconf="/etc/dkms/framework.conf"
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}"
3605
# Source in /etc/dkms_framework.conf
3606
. $dkms_frameworkconf 2>/dev/null
3608
# Clear out command line argument variables
3618
kernel_source_dir=""
3619
ksourcedir_fromcli=""
3622
no_prepare_kernel=""
3632
unset directive_array
3633
unset kernelver_array
3636
# Parse command line arguments
3637
while [ $# -gt 0 ]; do
3640
if echo $1 | grep '=' >/dev/null ; then
3641
dkms_frameworkconf=`echo $1 | sed 's/^.*=//'`
3643
dkms_frameworkconf="$2"
3646
#immediately load this config
3647
. $dkms_frameworkconf 2> /dev/null
3650
if echo $1 | grep '=' >/dev/null ; then
3651
module=`echo $1 | sed 's/^.*=//'`
3658
if echo $1 | grep '=' >/dev/null ; then
3659
module_version=`echo $1 | sed 's/^.*=//'`
3666
if echo $1 | grep '=' >/dev/null ; then
3667
kernelver_array[${#kernelver_array[@]}]=`echo $1 | sed 's/^.*=//'`
3669
kernelver_array[${#kernelver_array[@]}]="$2"
3674
if echo $1 | grep '=' >/dev/null ; then
3675
distro=`echo $1 | sed 's/^.*=//'`
3682
if echo $1 | grep '=' >/dev/null ; then
3683
media=`echo $1 | sed 's/^.*=//'`
3690
if echo $1 | grep '=' >/dev/null ; then
3691
release=`echo $1 | sed 's/^.*=//'`
3698
if echo $1 | grep '=' >/dev/null ; then
3699
template_kernel=`echo $1 | sed 's/^.*=//'`
3701
template_kernel="$2"
3706
if echo $1 | grep '=' >/dev/null ; then
3707
conf=`echo $1 | sed 's/^.*=//'`
3714
exec >/dev/null 2>&1
3717
echo $"dkms: 2.1.1.2"
3720
--no-prepare-kernel)
3721
no_prepare_kernel="no-prepare-kernel"
3724
no_clean_kernel="no-clean-kernel"
3727
binaries_only="binaries-only"
3730
source_only="source-only"
3742
rpm_safe_upgrade="true"
3745
if echo $1 | grep '=' >/dev/null ; then
3746
dkms_tree=`echo $1 | sed 's/^.*=//'`
3753
if echo $1 | grep '=' >/dev/null ; then
3754
source_tree=`echo $1 | sed 's/^.*=//'`
3761
if echo $1 | grep '=' >/dev/null ; then
3762
install_tree=`echo $1 | sed 's/^.*=//'`
3769
if echo $1 | grep '=' >/dev/null ; then
3770
kernel_config=`echo $1 | sed 's/^.*=//'`
3777
if echo $1 | grep '=' >/dev/null ; then
3778
archive_location=`echo $1 | sed 's/^.*=//'`
3780
archive_location="$2"
3785
if echo $1 | grep "=" >/dev/null ; then
3786
legacy_postinst=`echo $1 | sed 's/^.*=//'`
3788
legacy_postinst="$2"
3793
if echo $1 | grep '=' >/dev/null ; then
3794
arch_array[${#arch_array[@]}]=`echo $1 | sed 's/^.*=//'`
3796
arch_array[${#arch_array[@]}]="$2"
3801
if echo $1 | grep '=' >/dev/null ; then
3802
size=`echo $1 | sed 's/^.*=//'`
3809
if echo $1 | grep '=' >/dev/null ; then
3810
kernel_source_dir=`echo $1 | sed 's/^.*=//'`
3812
kernel_source_dir="$2"
3815
ksourcedir_fromcli="true"
3818
if echo $1 | grep '=' >/dev/null ; then
3819
directive_array[${#directive_array[@]}]=`echo $1 | sed 's/[^=]\+=//'`
3821
directive_array[${#directive_array[@]}]="$2"
3826
if echo $1 | grep '=' >/dev/null ; then
3827
specfile=`echo $1 | sed 's/^.*=//'`
3835
echo $"Error! Unknown option: $1" >&2
3846
# Run the specified action
3847
for action_to_run in $action; do
3848
case "$action_to_run" in
3853
# Make sure they're root
3854
if [ `id -u` -ne 0 ]; then
3855
echo $"You must be root to use this command." >&2
3864
# Make sure they're root
3865
if [ `id -u` -ne 0 ]; then
3866
echo $"You must be root to use this command." >&2
3872
# Make sure they're root
3873
if [ `id -u` -ne 0 ]; then
3874
echo $"You must be root to use this command." >&2
3880
# Make sure they're root
3881
if [ `id -u` -ne 0 ]; then
3882
echo $"You must be root to use this command." >&2
3888
# Make sure they're root
3889
if [ `id -u` -ne 0 ]; then
3890
echo $"You must be root to use this command." >&2
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
3923
echo $"Error! No action was specified.">&2
3928
echo $"Error! Unknown action specified: $action_to_run" >&2