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
23
# All of the variables we will accept from dkms.conf.
24
# Does not include directives
25
readonly dkms_conf_variables="CLEAN REMAKE_INITRD remake_initrd PACKAGE_NAME
26
PACKAGE_VERSION POST_ADD POST_INSTALL POST_REMOVE PRE_BUILD
27
PRE_INSTALL BUILD_EXCLUSIVE_KERNEL BUILD_EXCLUSIVE_ARCH
28
build_exclude OBSOLETE_BY MAKE MAKE_MATCH MODULES_CONF
29
modules_conf_array PATCH PATCH_MATCH patch_array BUILT_MODULE_NAME
30
built_module_name BUILT_MODULE_LOCATION built_module_location
31
DEST_MODULE_NAME dest_module_name MODULES_CONF_OBSOLETES
32
DEST_MODULE_LOCATION dest_module_location
33
modules_conf_obsoletes MODULES_CONF_ALIAS_TYPE
34
modules_conf_alias_type STRIP strip MODULES_CONF_OBSOLETE_ONLY
35
modules_conf_obsolete_only AUTOINSTALL"
37
# Some important regular expressions. Requires bash 3 or above.
38
# Any poor souls still running bash 2 or older really need an upgrade.
39
readonly reserved_tree_names="build|original_module|tarball|driver_disk|rpm|source|kernel"
40
readonly y_re='^(Y|y)'
41
readonly mv_re='^([^/]*)/(.*)$'
42
readonly rh_kernels='(debug|summit|smp|enterprise|bigmem|hugemem|BOOT|vmnix)'
44
#Areas that will vary between Linux and other OS's
48
Linux) DIR="/lib/modules/$KVER/build" ;;
49
GNU/kFreeBSD) DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
55
DIR=$(_get_kernel_dir $1)
57
Linux) test -e $DIR/include ;;
58
GNU/kFreeBSD) test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
64
# Run a command that we may or may not want to be detailed about.
67
# $1 = command to be executed using eval.
68
# $2 = Description of command to run
69
# $3 = 'background' if you want to run the command asynchronously.
71
[[ $verbose ]] && echo -e "$1" || echo -en "$2..."
72
if [[ $3 = background && ! $verbose ]]; then
73
local exitval_file=$(mktemp_or_die $tmp_location/dkms.XXXXXX)
74
(eval "$1" >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
75
while [[ -e $exitval_file && ! -s $exitval_file ]]; do
84
(($exitval > 0)) && echo -en "(bad exit status: $exitval)"
92
for s in "$@"; do echo "$s"; done
98
for s in "$@"; do echo "$s"; done
101
# Print an error message and die with the passed error code.
103
# $1 = error code to return with
104
# rest = strings to print before we exit.
108
[[ $die_is_fatal = yes ]] && exit $ret || return $ret
113
t=$(mktemp "$@") && echo "$t" && return
114
[[ $* = *-d* ]] && die 1 $"Unable to make temporary directory"
115
die 1 "Unable to make temporary file."
120
echo $"Usage: $0 [action] [options]"
121
echo $" [action] = { add | remove | build | install | uninstall | match | autoinstall"
122
echo $" | mkdriverdisk | mktarball | ldtarball | mkrpm | mkkmp | mkdeb | status }"
123
echo $" [options] = [-m module] [-v module-version] [-k kernel-version] [-a arch]"
124
echo $" [-d distro] [-c dkms.conf-location] [-q] [--force] [--all]"
125
echo $" [--templatekernel=kernel] [--directive='cli-directive=cli-value']"
126
echo $" [--config=kernel-.config-location] [--archive=tarball-location]"
127
echo $" [--kernelsourcedir=source-location] [--no-prepare-kernel] [--no-initrd]"
128
echo $" [--binaries-only] [--source-only] [-r release (SuSE)] [--verbose]"
129
echo $" [--size] [--spec=specfile] [--media=floppy|iso|tar] [--legacy-postinst=0|1]"
134
# $1 = kernel version string
136
# Pad all numbers in $1 so that they have at least three digits, e.g.,
137
# 2.6.9-1cvs200409091247 => 002.006.009-001cvs200409091247
138
# The result should compare correctly as a string.
140
echo $1 | sed -e 's:\([^0-9]\)\([0-9]\):\1 \2:g' \
141
-e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
142
-e 's:\(.*\): \1 :' \
143
-e 's: \([0-9]\) : 00\1 :g' \
144
-e 's: \([0-9][0-9]\) : 0\1 :g' \
148
# Figure out the correct module suffix for the kernel we are currently
149
# dealing with, which may or may not be the currently installed kernel.
152
# $1 = the kernel to base the module_suffix on
153
kernel_test="${1-:$(uname -r)}"
155
[[ $(VER $kernel_test) < $(VER 2.5) ]] && module_suffix=".o"
158
set_kernel_source_dir()
160
# $1 = the kernel to base the directory on
161
[[ $kernel_source_dir ]] && return
162
kernel_source_dir="$(_get_kernel_dir "$1")"
165
# A little test function for DKMS commands that only work on one kernel.
167
(( ${#kernelver[@]} > 1 )) && \
168
die 4 $"The action $1 does not support multiple kernel version" \
169
$"parameters on the command line."
170
[[ $all ]] && die 5 $"The action $1 does not support the --all" \
174
# Set up the kernelver and arch arrays. You must have a 1:1 correspondence --
175
# if there is an entry in kernelver[$i], there must also be an entry in arch[$i]
176
# Note the special casing for the status action -- the status functions just
177
# report on what we already have, and will break with the preprocessing that
178
# this function provides.
179
setup_kernels_arches()
181
# If all is set, use dkms status to fill the arrays
182
if [[ $all && $1 != status ]]; then
185
line=${line#*/}; line=${line#*/};
186
# (I would leave out the delimiters in the status output
187
# in the first place.)
188
kernelver[$i]=${line%/*}
191
done < <(module_status_built "$module" "$module_version")
194
# Set default kernel version and arch, if none set (but only --all isn't set)
195
if [[ $1 != status ]]; then
196
if [[ ! $kernelver && ! $all ]]; then
197
kernelver[0]=$(uname -r)
198
kernels_arches_default="yes"
200
if [[ ! $arch ]]; then
201
kernelver_rpm=$(rpm -qf "/lib/modules/$kernelver" 2>/dev/null | \
202
grep -v "not owned by any package" | grep kernel | head -n 1)
203
if ! arch[0]=$(rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null); then
205
if [[ $arch = x86_64 ]] && \
206
grep -q Intel /proc/cpuinfo && \
207
ls $install_tree/$kernelver/build/configs \
208
2>/dev/null | grep -q "ia32e"; then
215
# If only one arch is specified, make it so for all the kernels
216
if ((${#arch[@]} == 1 && ${#kernelver[@]} > 1)); then
217
while ((${#arch[@]} < ${#kernelver[@]})); do
218
arch[${#arch[@]}]=$arch
222
# Set global multi_arch
225
for ((i=0; $i < ${#arch[@]}; i++)); do
226
[[ $arch != ${arch[$i]} ]] && {
235
# $1 = kernel version
236
if [[ -f /boot/System.map-$1 ]]; then
237
/sbin/depmod -a "$1" -F "/boot/System.map-$1"
243
# This function is a little hairy -- every distro has slightly different tools
244
# and naming conventions for creating initial ramdisks. It should probably
245
# be split out into one function per distro, with make_initrd left as a stub.
248
# $1 = kernel version
250
[[ $no_initrd ]] && return
251
local mkinitrd kernel_file initrd_dir="/boot"
252
for mkinitrd in dracut update-initramfs mkinitrd ''; do
253
[[ $mkinitrd ]] && which "$mkinitrd" >/dev/null 2>&1 && break
256
# no mkinitrd? Just return.
257
[[ $mkinitrd ]] || return 0
259
# back up our current initrd
261
[[ $2 = ia64 && -d /boot/efi/efi/redhat ]] && initrd_dir="/boot/efi/efi/redhat"
262
# find out what the proper filename will be
263
for initrd in "initrd-$1.img" "initramfs-$1.img" "initrd.img-$1" "initrd-$1" ''; do
264
[[ $initrd && -f $initrd_dir/$initrd ]] && break
266
if ! [[ $initrd ]]; then
267
# Return if we cannot find an initrd.
268
warn $"Unable to find an initial ram disk that I know how to handle." \
269
$"Will not try to make an initrd."
272
echo $"Backing up $initrd to $initrd_dir/$initrd.old-dkms"
273
cp -f "$initrd_dir/$initrd" "$initrd_dir/$initrd.old-dkms"
274
echo $"Making new $initrd"
275
echo $"(If next boot fails, revert to $initrd.old-dkms image)"
277
if [[ $mkinitrd = dracut ]]; then
278
invoke_command "$mkinitrd $1" "$mkinitrd" background
279
elif [[ $mkinitrd = update-initramfs ]]; then
280
invoke_command "$mkinitrd -u" "$mkinitrd" background
281
elif $mkinitrd --version >/dev/null 2>&1; then
282
invoke_command "$mkinitrd -f $initrd_dir/$initrd $1" "$mkinitrd" background
283
elif [[ -e /etc/SuSE-release || -d /etc/SuSEconfig ]]; then
284
for kernel_file in vmlinuz vmlinux ''; do
285
[[ $kernel_file && -f $initrd_dir ]] && break
287
if [[ ! $kernel_file ]]; then
288
error $"Unable to find valid kernel file under " \
289
$"$initrd_dir for kernel version $1"
292
invoke_command "$mkinitrd -k $kernel_file-$1 -i $initrd" "$mkinitrd" background
293
elif [[ -e /etc/debian_version ]]; then
294
invoke_command "$mkinitrd -o $initrd_dir/$initrd $1" "$mkinitrd" background
297
echo $"Calling $mkinitrd (bad exit status 9 may occur)"
298
invoke_command "$mkinitrd" "$mkinitrd" background
303
# Grab our distro information from RPM-based distros.
306
which rpm > /dev/null 2>&1 || { echo unknown; return; }
309
for r in redhat-release sles-release suse-release ovs-release; do
310
wp=$(rpm -q --whatprovides "$r") || continue
311
ver=$(rpm -q --qf "%{version}\n" ${wp})
313
sles*) echo sles${ver};;
314
suse*) echo suse${ver};;
315
ovs*) echo ovm${ver};;
320
sed -e 's/^\([[:digit:]]*\).*/\1/g')
322
centos*|enterprise*) echo el${ver};;
323
fedora*) echo fc${ver};;
334
# Grab distro information from LSB compliant distros.
335
# Falls back to distro_version_rpm if needed.
338
# What distribution are we running?
339
local LSB_DESCRIPTION DISTRIB_ID DISTRIB_RELEASE ver
341
# try the LSB-provided strings first
342
if [ -r /etc/lsb-release ]; then
344
elif type lsb_release >/dev/null 2>&1; then
345
DISTRIB_ID=$(lsb_release -i -s)
346
DISTRIB_RELEASE=$(lsb_release -r -s)
349
case ${DISTRIB_ID} in
350
Fedora) echo fc${DISTRIB_RELEASE} ;;
351
RedHatEnterprise*|CentOS|ScientificSL) # OEL also reports as such
353
ver=$(echo "${DISTRIB_RELEASE}" | \
354
sed -e 's/^\([[:digit:]]*\).*/\1/g')
358
if [[ $(lsb_release -d -s) =~ Enterprise ]]; then
359
echo sles${DISTRIB_RELEASE}
361
echo suse${DISTRIB_RELEASE}
365
if [[ ${DISTRIB_ID} && ${DISTRIB_RELEASE} ]]; then
366
echo "${DISTRIB_ID}${DISTRIB_RELEASE}"
374
override_dest_module_location()
376
local orig_location="$1"
377
[[ ${addon_modules_dir} ]] && echo "/${addon_modules_dir}" && return
379
if [ "$uname_s" = "GNU/kFreeBSD" ] ; then
380
# Does not support subdirs, regardless of distribution
384
case "$running_distribution" in
390
fc*) echo "/extra" && return ;;
391
el*) echo "/extra" && return ;;
392
ovm*) echo "/extra" && return ;;
393
sles*) echo "/updates" && return ;;
394
suse*) echo "/updates" && return ;;
395
Ubuntu*) echo "/updates/dkms" && return ;;
396
Debian*) echo "/updates/dkms" && return ;;
399
echo "$orig_location"
402
# Source a file safely.
403
# We want to ensure that the .conf file we source does not stomp all over
404
# parts of the environment we don't want them to. This makes it so that
405
# it is harder to accidentally corrupt our environment. conf files can
406
# still deliberatly trash the environment by abusing dkms_directive env
407
# variables or by crafting special values that will make eval do evil things.
409
# $1 = file to source
410
# $@ = environment variables to echo out
411
local to_source_file="$1"; shift
412
declare -a -r export_envs=("$@")
413
local tmpfile=$(mktemp_or_die)
415
. "$to_source_file" >/dev/null
416
# This is really ugly, but a neat hack
417
# Remember, in bash 2.0 and greater all variables are really arrays.
418
for _export_env in "${export_envs[@]}"; do
419
for _i in $(eval echo \${!$_export_env[@]}); do
420
eval echo '$_export_env[$_i]=\"${'$_export_env'[$_i]}\"'
424
# handle DKMS_DIRECTIVE stuff specially.
425
for directive in $(set | grep ^DKMS_DIRECTIVE | cut -d = -f 2-3); do
426
directive_name=${directive%%=*}
427
directive_value=${directive#*=}
428
echo "$directive_name=\"$directive_value\""
435
# Source a dkms.conf file and perform appropriate postprocessing on it.
436
# Do our best to not repeatedly source the same .conf file -- this can happen
437
# when chaining module installtion functions or autoinstalling.
440
# $1 kernel version (required)
442
# $3 dkms.conf location (optional)
445
local read_conf_file="$dkms_tree/$module/$module_version/source/dkms.conf"
447
# Set variables supported in dkms.conf files (eg. $kernelver)
450
set_kernel_source_dir "$1"
453
# Find which conf file to check
454
[[ $conf ]] && read_conf_file="$conf"
455
[[ $3 ]] && read_conf_file="$3"
457
[[ -r $read_conf_file ]] || die 4 $"Could not locate dkms.conf file." \
458
$"File: $conf does not exist."
460
[[ $last_mvka = $module/$module_version/$1/$2 && \
461
$last_mvka_conf = $(readlink -f $read_conf_file) ]] && return
464
# Clear variables and arrays
465
for var in $dkms_conf_variables; do
469
# Source in the dkms.conf.
470
# Allow for user-specified overrides in order of specificity.
472
for _conf_file in "$read_conf_file" "/etc/dkms/$module.conf" \
473
"/etc/dkms/$module-$module_version.conf" "/etc/dkms/$module-$module_version-$1.conf" \
474
"/etc/dkms/$module-$module_version-$1-$2.conf"; do
475
[ -e "$_conf_file" ] && safe_source "$_conf_file" $dkms_conf_variables
478
# Source in the directive_array
479
for directive in "${directive_array[@]}"; do
480
directive_name=${directive%%=*}
481
directive_value=${directive#*=}
482
export $directive_name="$directive_value"
483
echo $"DIRECTIVE: $directive_name=\"$directive_value\""
488
package_name="$PACKAGE_NAME"
489
package_version="$PACKAGE_VERSION"
491
post_build="$POST_BUILD"
492
post_install="$POST_INSTALL"
493
post_remove="$POST_REMOVE"
494
pre_build="$PRE_BUILD"
495
pre_install="$PRE_INSTALL"
496
obsolete_by="$OBSOLETE_BY"
498
# Set module naming/location arrays
499
local index array_size=0 s
500
for s in ${#BUILT_MODULE_NAME[@]} \
501
${#BUILT_MODULE_LOCATION[@]} \
502
${#DEST_MODULE_NAME[@]} \
503
${#DEST_MODULE_LOCATION[@]}; do
504
((s > array_size)) && array_size=$s
506
for ((index=0; index < array_size; index++)); do
508
built_module_name[$index]=${BUILT_MODULE_NAME[$index]}
509
built_module_location[$index]=${BUILT_MODULE_LOCATION[$index]}
510
dest_module_name[$index]=${DEST_MODULE_NAME[$index]}
511
dest_module_location[$index]=${DEST_MODULE_LOCATION[$index]}
512
modules_conf_obsoletes[$index]=${MODULES_CONF_OBSOLETES[$index]}
513
modules_conf_alias_type[$index]=${MODULES_CONF_ALIAS_TYPE[$index]}
514
case ${MODULES_CONF_OBSOLETE_ONLY[$index]} in
515
[yY]*) modules_conf_obsolete_only[$index]="yes";;
517
case ${STRIP[$index]} in
518
[nN]*) strip[$index]="no";;
519
*) strip[$index]="yes";;
522
# If unset, set by defaults
523
[[ ! ${built_module_name[$index]} ]] && \
524
((${#DEST_MODULE_LOCATION[@]} == 1)) && \
525
built_module_name[$index]=$module
526
[[ ! ${dest_module_name[$index]} ]] && \
527
dest_module_name[$index]=${built_module_name[$index]}
528
[[ ${built_module_location[$index]} && \
529
${built_module_location[$index]:(-1)} != / ]] && \
530
built_module_location[$index]="${built_module_location[$index]}/"
532
# FAIL if no built_module_name
533
if [[ ! ${built_module_name[$index]} ]]; then
534
echo $"dkms.conf: Error! No 'BUILT_MODULE_NAME' directive specified for record #$index." >&2
538
# FAIL if built_module_name ends in .o or .ko
539
case ${built_module_name[$index]} in
541
echo $"dkms.conf: Error! 'BUILT_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
546
# FAIL if dest_module_name ends in .o or .ko
547
case ${dest_module_name[$index]} in
549
echo $"dkms.conf: Error! 'DEST_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
554
# Override location for specific kernels
555
dest_module_location[$index]="$(override_dest_module_location ${dest_module_location[$index]})"
557
# Fail if no DEST_MODULE_LOCATION
558
if [[ ! ${DEST_MODULE_LOCATION[$index]} ]]; then
559
echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified for record #$index.">&2
562
# Fail if bad DEST_MODULE_LOCATION
563
case ${DEST_MODULE_LOCATION[$index]} in
568
echo $"dkms.conf: Error! Directive 'DEST_MODULE_LOCATION' does not begin with">&2
569
echo $"'/kernel', '/updates', or '/extra' in record #$index.">&2
575
# Get the correct make command
576
[[ ${MAKE_MATCH[0]} ]] || make_command="${MAKE[0]}"
577
for ((index=0; index < ${#MAKE[@]}; index++)); do
578
[[ ${MAKE[$index]} && ${MAKE_MATCH[$index]} && \
579
$1 =~ ${MAKE_MATCH[$index]} ]] && \
580
make_command="${MAKE[$index]}"
583
# Use the generic make and make clean commands if not specified
584
if [[ $(VER $1) < $(VER 2.6.6) ]]; then
585
[[ ! $make_command ]] && \
586
make_command="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build modules"
588
clean="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build clean"
590
[[ ! $make_command ]] && \
591
make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
593
clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
596
# Set modules_conf_array
597
for ((index=0; index < ${#MODULES_CONF[@]}; index++)); do
598
[[ ${MODULES_CONF[$index]} ]] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
601
# Set patch_array (including kernel specific patches)
603
for ((index=0; index < ${#PATCH[@]}; index++)); do
604
if [[ ${PATCH[$index]} && (! ${PATCH_MATCH[$index]} || \
605
$1 =~ ${PATCH_MATCH[$index]}) ]]; then
606
patch_array[$count]="${PATCH[$index]}"
612
[[ $REMAKE_INITRD =~ $y_re ]] && remake_initrd="yes"
615
[[ $BUILD_EXCLUSIVE_KERNEL && ! $1 =~ $BUILD_EXCLUSIVE_KERNEL ]] && \
617
[[ $BUILD_EXCLUSIVE_ARCH && ! $2 =~ $BUILD_EXCLUSIVE_ARCH ]] && \
620
# Fail if absolutely no DEST_MODULE_LOCATION
621
if ((${#dest_module_location[@]} == 0)); then
622
echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified." >&2
626
# Fail if no PACKAGE_NAME
627
if [[ ! $package_name ]]; then
628
echo $"dkms.conf: Error! No 'PACKAGE_NAME' directive specified.">&2
632
# Fail if no PACKAGE_VERSION
633
if [[ ! $package_version ]]; then
634
echo $"dkms.conf: Error! No 'PACKAGE_VERSION' directive specified.">&2
639
[[ $clean ]] || clean="make clean"
641
((return_value == 0)) && last_mvka="$module/$module_version/$1/$2" && \
642
last_mvka_conf="$(readlink -f "$read_conf_file")"
646
# Little helper function for parsing the output of modinfo.
647
get_module_verinfo(){
649
while read -a vals; do
651
version:) res[0]=${vals[1]}; res[2]=${vals[2]};;
652
srcversion:) res[1]=${vals[1]};;
657
# Perform some module version sanity checking whenever we are installing
658
# or removing modules.
659
check_version_sanity()
661
# $1 = kernel_version
663
# $3 = obs by kernel version
664
# $4 = dest_module_name
666
local lib_tree="$install_tree/$1" res=
667
echo $"Running module version sanity check."
669
local -a kernels_info dkms_info
671
read -a kernels_module < <(find $lib_tree -name ${4}$module_suffix)
672
[[ $kernels_module ]] || return 0
673
if [[ ${kernels_module[1]} ]]; then
674
warn $"Warning! Cannot do version sanity checking because multiple ${4}$module_suffix" \
675
$"modules were found in kernel $1."
678
local dkms_module="$dkms_tree/$module/$module_version/$1/$2/module/${4}$module_suffix"
679
get_module_verinfo $kernels_module; kernels_info=("${res[@]}")
680
get_module_verinfo $dkms_module; dkms_info=("${res[@]}")
681
if [[ ! ${dkms_info[1]} && ${kernels_info[1]} ]]; then
682
# use obsolete checksum info
683
dkms_info[1]=${dkms_info[2]}
684
kernels_info[1]=${kernels_info[2]}
687
if [[ ${kernels_info[1]} && ${dkms_info[1]} && \
688
${kernels_info[1]} = ${dkms_info[1]} && ! $force ]]; then
690
echo $"Good news! Module version $dkms_info for ${4}$module_suffix" >&2
691
echo $"exactly matches what is already found in kernel $1." >&2
692
echo $"DKMS will not replace this module." >&2
693
echo $"You may override by specifying --force." >&2
697
if [[ $kernels_info && $dkms_info && \
698
! ( $(VER $dkms_info) > $(VER $kernels_info) ) && ! $force ]]; then
699
error $"Module version $dkms_info for ${4}$module_suffix" \
700
$"is not newer than what is already found in kernel $1 ($kernels_info)." \
701
$"You may override by specifying --force."
705
# magic split into array syntax saves trivial awk and cut calls.
706
local -a obs=(${3//-/ })
707
local -a my=(${1//-/ })
709
if [[ ${obs} && ${my} ]]; then
710
if [[ $(VER ${obs}) == $(VER ${my}) && ! $force ]]; then
711
#they get obsoleted possibly in this kernel release
712
if [[ ! ${obs[1]} ]]; then
713
#they were obsoleted in this upstream kernel
715
elif [[ $(VER ${my[1]}) > $(VER ${obs[1]}) ]]; then
716
#they were obsoleted in an earlier ABI bump of the kernel
718
elif [[ $(VER ${my[1]}) = $(VER ${obs[1]}) ]]; then
719
#they were obsoleted in this ABI bump of the kernel
722
elif [[ $(VER ${my}) > $(VER ${obs}) && ! $force ]]; then
723
#they were obsoleted in an earlier kernel release
728
if ((obsolete == 1)); then
730
echo $"Module has been obsoleted due to being included" >&2
731
echo $"in kernel $3. We will avoid installing" >&2
732
echo $"for future kernels above $3." >&2
733
echo $"You may override by specifying --force." >&2
739
moduleconfig_update_obsoletes()
741
# $@ = files to process
742
# do nothing if we have no obsoletes
743
[[ ${modules_conf_obsoletes[@]} ]] || return 0
744
# generate sed args to remove obsolete modules
746
for ((index=0; index < ${#dest_module_name[@]}; index++)); do
747
[[ ${modules_conf_obsoletes[$index]} ]] || continue
748
for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
749
# for module.conf style syntax
750
sa_mc_o[${#sa_mc_o[@]}]="-e"
751
sa_mc_o[${#sa_mc_o[@]}]="s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) $obsolete_module$/\1 ${dest_module_name[$index]}/g"
753
# for /etc/sysconfig/kernel style syntax
754
sa_sck_o[${#sa_sck_o[@]}]="-e"
755
sa_sck_o[${#sa_sck_o[@]}]="s/\(INITRD_MODULES.*\)$obsolete_module\b\(.*\)/\1${dest_module_name[$index]}\2/"
759
# do all the changes at once, record the diffs for posterity
761
[[ $file && -w $file ]] || continue
762
if [[ $file = /etc/sysconfig/kernel ]]; then
763
sed "${sa_sck_o[@]}" "$file" > "$temp_dir_name/${file##*/}.new"
765
sed "${sa_mc_o[@]}" "$file" > "$temp_dir_name/${file##*/}.new"
767
if ! mod_diff=$(diff -u "$temp_dir_name/${file##*/}.new" "$file"); then
768
echo $"$file updated to replace obsoleted module references:"
770
cp -fp "$temp_dir_name/${file##*/}.new" "$file"
771
rm -f "$temp_dir_name/${file##*/}.new"
778
# $1 = kernel version
780
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
781
local -a sa_mc_o=() sa_sck_o=()
782
modconfig_files="/etc/modprobe.d/dkms.conf
786
/etc/modprobe.d/$package_name.conf
787
/etc/sysconfig/kernel"
789
moduleconfig_update_obsoletes $modconfig_files
791
for moduleconfig in $modconfig_files; do
792
[[ -e $moduleconfig ]] || continue
793
for ((index=0; index < ${#dest_module_name[@]}; index++)); do
795
# Only add it if it can't be found already in config file
796
if [[ ${modules_conf_alias_type[$index]} ]] && \
797
! grep -qs "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}\b" $moduleconfig && \
798
[[ ${modules_conf_obsolete_only[$index]} != yes ]]; then
799
if [[ $modconfig_files = /etc/modprobe.d/$package_name.conf ]] && \
800
[[ ! -e /etc/modprobe.d/$package_name.conf ]]; then
801
touch /etc/modprobe.d/$package_name.conf
802
echo $"created /etc/modprobe.d/$package_name.conf.">&2
804
aliases=$(awk "/^alias ${modules_conf_alias_type[$index]}/ {print \$2}" $moduleconfig)
805
if [[ $aliases ]]; then
806
alias_number=$(($(echo "$aliases" | sed "s/${modules_conf_alias_type[$index]}//" | sort -n | tail -n 1) + 1))
810
echo -e "alias ${modules_conf_alias_type[$index]}${alias_number} ${dest_module_name[$index]}" >> $moduleconfig
811
echo $"$moduleconfig: added alias reference for '${dest_module_name[$index]}'"
816
for ((index=0; index < ${#modules_conf_array[@]}; index++)); do
817
if [ -n "${modules_conf_array[$index]}" ] && \
818
! grep -q "${modules_conf_array[$index]}" "$moduleconfig"; then
819
echo -e $"$moduleconfig: added '${modules_conf_array[$index]}'"
820
echo -e "${modules_conf_array[$index]}" >> $moduleconfig
825
# Delete the temp dir
826
rm -rf $temp_dir_name
829
moduleconfig_remove()
831
# $1 = kernel version
833
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
835
[ -e /etc/modprobe.d/dkms.conf ] && modconfig_files="/etc/modprobe.d/dkms.conf"
836
[ -e /etc/modprobe.d/dkms ] && modconfig_files="/etc/modprobe.d/dkms"
837
[ -e /etc/modules.conf ] && modconfig_files="$modconfig_files /etc/modules.conf"
838
[ -e /etc/modprobe.conf ] && modconfig_files="$modconfig_files /etc/modprobe.conf"
839
[ -e /etc/modprobe.d/$package_name.conf ] && modconfig_files="/etc/modprobe.d/$package_name.conf"
841
for moduleconfig in $modconfig_files; do
842
for ((index=0; index < ${#dest_module_name[@]}; index++)); do
843
# Remove/Replace aliases (maybe)
844
[[ ${modules_conf_alias_type[$index]} ]] || continue
845
find "$install_tree/$1/" -name "${dest_module_name[$index]}.*" -quit 2>/dev/null && continue
847
local conf_replacement=""
848
for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
849
find $install_tree/$1/ -name "$obsolete_module.*" -quit 2>/dev/null || continue
850
conf_replacement=$obsolete_module
854
if [[ ! $conf_replacement ]]; then
855
grep -v "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}" $moduleconfig > $temp_dir_name/moduleconfig.new
856
mv -f $temp_dir_name/moduleconfig.new $moduleconfig
857
echo $"$moduleconfig: removed alias for '${dest_module_name[$index]}'"
858
if [[ $modconfig_files = /etc/modprobe.d/$package_name.conf ]]; then
859
rm -f /etc/modprobe.d/$package_name.conf
860
echo $"$moduleconfig: deleted /etc/modprobe.d/$package_name.conf file"
862
elif grep -q "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}$" $moduleconfig; then
863
sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) ${dest_module_name[$index]}$/\1 $conf_replacement/g" $moduleconfig > $temp_dir_name/moduleconfig.new
864
mv -f $temp_dir_name/moduleconfig.new $moduleconfig
865
echo $"$moduleconfig: alias for '${dest_module_name[$index]}' changed back to '$conf_replacement'"
869
# Remove static conf entries
870
for ((index=0; index < ${#modules_conf_array[@]}; index++)); do
871
[[ ${modules_conf_array[$index]} ]] || continue
872
grep -v "${modules_conf_array[$index]}" "$moduleconfig" > $temp_dir_name/moduleconfig.new
873
echo $"$moduleconfig: removed '${modules_conf_array[$index]}'"
874
mv -f $temp_dir_name/moduleconfig.new $moduleconfig
878
# Delete the temp dir
879
rm -rf $temp_dir_name
882
etc_sysconfig_kernel_modify()
884
[[ -e /etc/sysconfig/kernel && $remake_initrd ]] || return 0
886
# Make a temp directory to store files
887
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
888
if [[ $1 = add ]]; then
889
. /etc/sysconfig/kernel
890
for m in "${dest_module_name[@]}"; do
891
for l in "${INITRD_MODULES}"; do
892
[[ $m = $l ]] && continue 2
894
sed -e "s/INITRD_MODULES=\"\(.*\)\"/INITRD_MODULES=\"\1 $m\"/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
895
mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
897
# Remove /etc/sysconfig/kernel entries
898
elif [[ $1 = delete ]]; then
899
for m in "${dest_module_name[@]}"; do
900
sed -e "s/\(INITRD_MODULES.*\)$m\b\(.*\)/\1\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
901
mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
904
# Delete the temp dir
905
rm -rf $temp_dir_name
908
check_module_args() {
909
[[ $module && $module_version ]] && return
910
die 1 $"Invalid number of arguments passed." \
911
$"Usage: $1 <module>/<module-version> or" \
912
$" $1 -m <module>/<module-version> or" \
913
$" $1 -m <module> -v <module-version>"
917
read_conf "$@" && return
918
die 8 $"Bad conf file." $"File: $conf" \
919
$"does not represent a valid dkms.conf file."
925
[[ $2 && -x $dkms_tree/$module/$module_version/source/${2%% *} ]] || return 0
927
echo $"Running the $1 script:"
928
$dkms_tree/$module/$module_version/source/$2
931
# Register a DKMS-ified source tree with DKMS.
932
# This function is smart enough to register the module if we
933
# passed a source tree or a tarball instead of relying on the source tree
934
# being unpacked into /usr/src/$module-$module_version.
937
# if $archive is set and $module and $module_version are not,
938
# try loading the tarball passed first.
939
if [[ $archive_location && ! $module && ! $module_version ]]; then
941
elif [[ $try_source_tree && ! $module && ! $module_version ]]; then
942
add_source_tree "$try_source_tree"
945
# Check that we have all the arguments
946
check_module_args add
948
# Check that this module-version hasn't already been added
949
if is_module_added "$module" "$module_version"; then
950
die 3 $"DKMS tree already contains: $module-$module_version" \
951
$"You cannot add the same module/version combo more than once."
954
[[ $conf ]] || conf="$source_tree/$module-$module_version/dkms.conf"
956
# Check that /usr/src/$module-$module_version exists
957
if ! [[ -d $source_tree/$module-$module_version ]]; then
958
die 2 $"Could not find module source directory." \
959
$"Directory: $source_tree/$module-$module_version does not exist."
962
# Do stuff for --rpm_safe_upgrade
963
if [[ $rpm_safe_upgrade ]]; then
964
local pppid=$(awk '/PPid:/ {print $2}' /proc/$PPID/status)
965
local lock_name=$(mktemp_or_die $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.XXXXXX)
966
echo "$module-$module_version" >> $lock_name
967
ps -o lstart --no-headers -p $pppid 2>/dev/null >> $lock_name
970
# Check the conf file for sanity
971
read_conf_or_die "$kernelver" "$arch" "$conf"
973
# Create the necessary dkms tree structure
975
echo $"Creating symlink $dkms_tree/$module/$module_version/source ->"
976
echo $" $source_tree/$module-$module_version"
977
mkdir -p "$dkms_tree/$module/$module_version/build"
978
ln -s "$source_tree/$module-$module_version" "$dkms_tree/$module/$module_version/source"
980
# Run the post_add script
981
run_build_script post_add "$post_add"
984
echo $"DKMS: add Completed."
987
# Prepare a kernel source or include tree for compiling a module.
988
# Most modern-ish distros do not require this function at all,
989
# so it will be removed in a future release.
992
# $1 = kernel version to prepare
993
# $2 = arch to prepare
995
set_kernel_source_dir "$1"
997
# Check that kernel-source exists
998
_check_kernel_dir "$1" || {
999
case "$running_distribution" in
1001
die 1 $"Your kernel headers for kernel $1 cannot be found." \
1002
$"Please install the linux-headers-$1 package," \
1003
$"or use the --kernelsourcedir option to tell DKMS where it's located";;
1004
* ) die 1 echo $"Your kernel headers for kernel $1 cannot be found at" \
1005
$"/lib/modules/$1/build or /lib/modules/$1/source."
1006
$"You can use the --kernelsourcedir option to tell DKMS where it's located."
1010
[[ $no_prepare_kernel ]] && return
1012
if [[ (! ( $(VER $1) < $(VER 2.6.5) ) || -d /etc/SuSEconfig) && \
1013
-d "$kernel_source_dir" && \
1014
-z "$ksourcedir_fromcli" ]]; then
1016
echo $"Kernel preparation unnecessary for this kernel. Skipping..."
1017
no_clean_kernel="no-clean-kernel"
1021
# Prepare kernel for module build
1023
echo $"Preparing kernel $1 for module build:"
1024
echo $"(This is not compiling a kernel, just preparing kernel symbols)"
1025
cd $kernel_source_dir
1026
[[ -r .config ]] && {
1027
config_contents=$(cat .config)
1028
echo $"Storing current .config to be restored when complete"
1032
if [[ -e /etc/redhat-release || -e /etc/fedora-release ]]; then
1033
# Note this also applies to VMware 3.x
1034
if [[ -z $kernel_config && -d $kernel_source_dir/configs ]]; then
1035
local kernel_trunc=${1%%-*}
1036
# Try a .config specific to whatever kernel we are running
1037
if [[ $1 =~ $rh_kernels && \
1038
-e $kernel_source_dir/configs/kernel-$kernel_trunc-$2-${BASH_REMATCH[1]}.config ]]; then
1039
kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2-${BASH_REMATCH[1]}.config"
1040
elif [[ -e $kernel_source_dir/configs/kernel-$kernel_trunc-$2.config ]]; then
1041
# If that one does not exist, try a generic one.
1042
kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2.config"
1044
# If that does not exist, fall back to no config file
1048
elif [[ (-e /etc/SuSE-release || -d /etc/SuSEconfig) && \
1049
-z $kernel_config && -d $kernel_source_dir/arch ]]; then
1050
local kernel_trunc=${1%%-*}
1052
i586|i686) config_arch="i386";;
1055
for config_type in default smp bigsmp; do
1056
[[ $1 =~ $config_type ]] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.$config_type"
1057
[[ -e $kernel_config ]] || kernel_config=""
1059
[[ $kernel_config ]] || kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.default"
1060
[[ -e $kernel_config ]] || kernel_config=""
1064
if [ -e /boot/vmlinuz.version.h ]; then
1065
echo $"Running UnitedLinux preparation routine"
1066
local kernel_config="/boot/vmlinuz.config"
1067
invoke_command "make mrproper" "make mrproper" background
1068
[[ $config_contents ]] && echo "$config_contents" > .config
1069
invoke_command "cp /boot/vmlinuz.version.h include/linux/version.h" "using /boot/vmlinux.version.h"
1070
invoke_command "cp -f $kernel_config .config" "using $kernel_config"
1071
invoke_command "make KERNELRELEASE=$1 cloneconfig" "make cloneconfig" background
1072
invoke_command "make CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
1073
elif grep -q rhconfig.h $kernel_source_dir/include/linux/{modversions,version}.h 2>/dev/null; then
1074
echo $"Running Red Hat style preparation routine"
1075
invoke_command "make clean" "make clean" background
1076
[[ $config_contents ]] && echo "$config_contents" > .config
1078
if [[ $kernel_config ]]; then
1079
echo $"using $kernel_config"
1080
cp -f "$kernel_config" .config
1081
elif [[ -e .config ]]; then
1082
warn $"Using $kernel_source_dir/.config" \
1083
$"(I hope this is the correct config for this kernel)"
1085
warn $"Cannot find a .config file to prepare your kernel with." \
1086
$"Try using the --config option to specify where one can be found." \
1087
$"Your build will likely fail because of this."
1090
# Hack to workaround broken tmp_include_depends for Red Hat
1091
if grep -q "/usr/src/build" $kernel_source_dir/tmp_include_depends 2>/dev/null; then
1092
sed 's/\/usr\/src\/build\/.*\/install//g' $kernel_source_dir/tmp_include_depends > $kernel_source_dir/tmp_include_depends.new
1093
mv -f $kernel_source_dir/tmp_include_depends.new $kernel_source_dir/tmp_include_depends
1096
invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
1097
kerneldoth_contents=$(cat /boot/kernel.h 2>/dev/null)
1098
invoke_command "/usr/lib/dkms/mkkerneldoth --kernelver $1 --targetarch $2 --output /boot/kernel.h" "running mkkerneldoth" background
1100
echo $"Running Generic preparation routine"
1101
invoke_command "make mrproper" "make mrproper" background
1102
[[ $config_contents ]] && echo "$config_contents" > .config
1104
if [[ $kernel_config ]]; then
1105
echo $"using $kernel_config"
1106
cp -f "$kernel_config" .config
1107
elif [[ -e .config ]]; then
1108
warn $"using $kernel_source_dir/.config" \
1109
$"(I hope this is the correct config for this kernel)"
1111
warn $"Warning! Cannot find a .config file to prepare your kernel with." \
1112
$"Try using the --config option to specify where one can be found." \
1113
$"Your build will likely fail because of this."
1116
invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
1117
if [[ $(VER $1) < $(VER 2.5) ]]; then
1118
invoke_command "make KERNELRELEASE=$1 dep" "make dep" background
1120
invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
1126
# Get ready to build a module that has been registered with DKMS.
1129
# If the module has not been added, try to add it.
1130
is_module_added "$module" "$module_version" || add_module
1132
set_kernel_source_dir "$kernelver"
1133
local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
1135
# Check that the right arguments were passed
1136
check_module_args build
1138
# Check that the module has not already been built for this kernel
1139
[[ -d $base_dir ]] && die 3 \
1140
$"This module/version has already been built on: $kernelver" \
1141
$"Directory: $base_dir" \
1142
$"already exists. Use the dkms remove function before trying to build again."
1144
# Read the conf file
1145
set_module_suffix "$kernelver"
1146
read_conf_or_die "$kernelver" "$arch"
1148
# Error out if build_exclude is set
1149
[[ $build_exclude ]] && die 9 \
1150
$" The dkms.conf for this module includes a BUILD_EXCLUSIVE directive which" \
1151
$"does not match this kernel/arch. This indicates that it should not be built."
1153
# Error out if source_tree is basically empty (binary-only dkms tarball w/ --force check)
1154
(($(ls $dkms_tree/$module/$module_version/source | wc -l | awk {'print $1'}) < 2)) && die 8 \
1155
$"The directory $dkms_tree/$module/$module_version/source/" \
1156
$"does not appear to have module source located within it. Build halted."
1158
prepare_kernel "$kernelver" "$arch"
1160
# Set up temporary build directory for build
1161
rm -rf "$dkms_tree/$module/$module_version/build"
1162
cp -rf "$dkms_tree/$module/$module_version/source/" "$dkms_tree/$module/$module_version/build"
1164
# Run the pre_build script
1165
run_build_script pre_build "$pre_build"
1167
cd "$dkms_tree/$module/$module_version/build"
1170
for p in "${patch_array[@]}"; do
1171
[[ ! -e $dkms_tree/$module/$module_version/build/patches/$p ]] && \
1172
report_build_problem 5 \
1173
$" Patch $p as specified in dkms.conf cannot be" \
1174
$"found in $dkms_tree/$module/$module_version/build/patches/."
1175
invoke_command "patch -p1 < ./patches/$p" "applying patch $p" || \
1176
report_build_problem 6 $"Application of patch $p failed." \
1177
$"Check $dkms_tree/$module/$module_version/build/ for more information."
1181
# Build our previously prepared source tree. prepare_build must be called
1182
# before calling this function.
1185
local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
1187
echo $"Building module:"
1189
invoke_command "$clean" "cleaning build area" background
1190
echo $"DKMS make.log for $module-$module_version for kernel $kernelver ($arch)" >> "$dkms_tree/$module/$module_version/build/make.log"
1191
date >> "$dkms_tree/$module/$module_version/build/make.log"
1192
local the_make_command="${make_command/#make/make KERNELRELEASE=$kernelver}"
1194
invoke_command "{ $the_make_command; } >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background || \
1195
report_build_problem 10 $"Bad return status for module build on kernel: $kernelver ($arch)" \
1196
$"Consult $dkms_tree/$module/$module_version/build/make.log for more information."
1198
# Make sure all the modules built successfully
1199
for ((count=0; count < ${#built_module_name[@]}; count++)); do
1200
[[ -e ${built_module_location[$count]}${built_module_name[$count]}$module_suffix ]] && continue
1201
report_build_problem 7 \
1202
$" Build of ${built_module_name[$count]}$module_suffix failed for: $kernelver ($arch)" \
1203
$"Consult the make.log in the build directory" \
1204
$"$dkms_tree/$module/$module_version/build/ for more information."
1208
# Build success, so create DKMS structure for a built module
1209
mkdir -p "$base_dir/log"
1210
[[ $kernel_config ]] && cp -f "$kernel_config" "$base_dir/log/"
1211
mv -f "$dkms_tree/$module/$module_version/build/make.log" "$base_dir/log/make.log" 2>/dev/null
1213
# Save a copy of the new module
1214
mkdir "$base_dir/module" >/dev/null
1215
for ((count=0; count < ${#built_module_name[@]}; count++)); do
1216
[[ ${strip[$count]} != no ]] && strip -g "$dkms_tree/$module/$module_version/build/${built_module_location[$count]}${built_module_name[$count]}$module_suffix"
1217
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
1220
# Run the post_build script
1221
run_build_script post_build "$post_build"
1224
# Clean up after a build.
1227
# Run the clean commands
1228
cd "$dkms_tree/$module/$module_version/build"
1229
invoke_command "$clean" "cleaning build area" background
1232
if [[ ! ( $(VER $kernelver) < $(VER 2.6.6) ) && \
1233
-d $kernel_source_dir && \
1234
! -h $kernel_source_dir && \
1235
! $ksourcedir_fromcli ]]; then
1236
echo $"Kernel cleanup unnecessary for this kernel. Skipping..."
1237
elif [[ ! $no_clean_kernel ]]; then
1238
cd "$kernel_source_dir"
1239
[[ $kerneldoth_contents ]] || invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
1240
[[ $config_contents ]] || echo "$config_contents" > .config
1241
[[ $kerneldoth_contents ]] && echo "$kerneldoth_contents" > /boot/kernel.h
1245
# Clean the build directory
1246
rm -rf "$dkms_tree/$module/$module_version/build/*"
1255
echo $"DKMS: build Completed."
1258
# Install a previously built module
1259
# There are huge swaths of code here that special-case for various distros.
1260
# They should be split into their own functions.
1263
# If the module has not been built, try to build it first.
1264
is_module_built "$module" "$module_version" "$kernelver" "$arch" || build_module
1265
local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
1266
check_module_args install
1268
# Make sure that kernel exists to install into
1269
[[ -e $install_tree/$kernelver ]] || die 6 \
1270
$"The directory $install_tree/$kernelver doesn't exist." \
1271
$"You cannot install a module onto a non-existant kernel."
1273
# Read the conf file
1274
read_conf_or_die "$kernelver" "$arch"
1276
# Check that its not already installed (kernel symlink)
1277
is_module_installed "$module" "$module_version" "$kernelver" "$arch" && die 5 \
1278
$"This module/version combo is already installed" \
1279
$"for kernel: $kernelver ($arch)"
1281
# if upgrading using rpm_safe_upgrade, go ahead and force the install
1282
# else we can wind up with the first half of an upgrade failing to install anything,
1283
# while the second half of the upgrade, the removal, then succeeds, leaving us with
1284
# nothing installed.
1285
[[ $rpm_safe_upgrade ]] && force="true"
1287
# Save the original_module if one exists, none have been saved before, and this is the first module for this kernel
1288
local lib_tree="$install_tree/$kernelver"
1290
for ((count=0; count < ${#built_module_name[@]}; count++)); do
1292
echo $"${dest_module_name[$count]}$module_suffix:"
1293
# Check this version against what is already in the kernel
1294
check_version_sanity "$kernelver" "$arch" \
1295
"$obsolete_by" "${dest_module_name[$count]}" || continue
1297
if ((count == 0)) && ! run_build_script pre_install "$pre_install" && \
1298
! [[ $force ]]; then
1299
die 101 $"pre_install failed, aborting install." \
1300
$"You may override by specifying --force."
1302
local module_count=$(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f | wc -l | awk {'print $1'})
1303
echo $" - Original module"
1304
if [[ -L $dkms_tree/$module/kernel-$kernelver-$arch && \
1305
-e $dkms_tree/$module/original_module/$kernelver/$arch/${dest_module_name[$count]}$module_suffix ]]; then
1306
echo $" - An original module was already stored during a previous install"
1307
elif ! [[ -L $dkms_tree/$module/kernel-$kernelver-$arch ]]; then
1308
local archive_pref1="$lib_tree/extra/${dest_module_name[$count]}$module_suffix"
1309
local archive_pref2="$lib_tree/updates/${dest_module_name[$count]}$module_suffix"
1310
local archive_pref3="$lib_tree${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
1311
local archive_pref4=""
1312
((module_count == 1)) && archive_pref4=$(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f)
1313
local original_module=""
1314
local found_orginal=""
1315
for original_module in $archive_pref1 $archive_pref2 $archive_pref3 $archive_pref4; do
1316
[[ -f $original_module ]] || continue
1317
case "$running_distribution" in
1318
Debian* | Ubuntu* ) ;;
1320
echo $" - Found $original_module"
1321
echo $" - Storing in $dkms_tree/$module/original_module/$kernelver/$arch/"
1322
echo $" - Archiving for uninstallation purposes"
1323
mkdir -p "$dkms_tree/$module/original_module/$kernelver/$arch"
1324
mv -f "$original_module" "$dkms_tree/$module/original_module/$kernelver/$arch/"
1327
found_original="yes"
1330
if [[ ! $found_original ]] && ((module_count > 1)); then
1331
echo $" - Multiple original modules exist but DKMS does not know which to pick"
1332
echo $" - Due to the confusion, none will be considered during a later uninstall"
1333
elif [[ ! $found_original ]]; then
1334
echo $" - No original module exists within this kernel"
1337
echo $" - This kernel never originally had a module by this name"
1340
if ((module_count > 1)); then
1341
echo $" - Multiple same named modules!"
1342
echo $" - $module_count named ${dest_module_name[$count]}$module_suffix in $lib_tree/"
1343
case "$running_distribution" in
1344
Debian* | Ubuntu* ) ;;
1346
echo $" - All instances of this module will now be stored for reference purposes ONLY"
1347
echo $" - Storing in $dkms_tree/$module/original_module/$kernelver/$arch/collisions/"
1350
for module_dup in $(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f); do
1351
dup_tree="${module_dup#$lib_tree}";
1352
dup_tree="${dup_tree/${dest_module_name[$count]}$module_suffix}"
1353
case "$running_distribution" in
1354
Debian* | Ubuntu* ) ;;
1356
echo $" - Stored $module_dup"
1357
mkdir -p "$dkms_tree/$module/original_module/$kernelver/$arch/collisions/$dup_tree"
1358
mv -f $module_dup "$dkms_tree/$module/original_module/$kernelver/$arch/collisions/$dup_tree"
1364
# Copy module to its location
1365
echo $" - Installation"
1366
echo $" - Installing to $install_tree/$kernelver${dest_module_location[$count]}/"
1367
mkdir -p $install_tree/$kernelver${dest_module_location[$count]}
1368
cp -f "$base_dir/module/${dest_module_name[$count]}$module_suffix" "$install_tree/$kernelver${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
1372
# Create the kernel-<kernelver> symlink to designate this version as active
1373
rm -f "$dkms_tree/$module/kernel-$kernelver-$arch" 2>/dev/null
1374
ln -s "$module_version/$kernelver/$arch" "$dkms_tree/$module/kernel-$kernelver-$arch" 2>/dev/null
1376
# add to kabi-tracking
1377
if [[ ${weak_modules} ]]; then
1378
echo $"Adding any weak-modules"
1379
list_each_installed_module "$module" "$kernelver" "$arch" | ${weak_modules} --add-modules
1382
# Run the post_install script
1383
run_build_script post_install "$post_install"
1385
# Make modules.conf changes as necessary
1387
moduleconfig_add "$kernelver"
1388
etc_sysconfig_kernel_modify "add"
1390
invoke_command "do_depmod $kernelver" "depmod" background || {
1391
do_uninstall "$kernelver" "$arch"
1392
die 6 $"Problems with depmod detected. Automatically uninstalling this module." \
1393
$"DKMS: Install Failed (depmod problems). Module rolled back to built state."
1397
# Do remake_initrd things (save old initrd)
1398
[[ $remake_initrd ]] && ! make_initrd "$kernelver" "$arch" && {
1399
do_uninstall "$kernelver" "$arch"
1400
die 7 $"Problems with mkinitrd detected. Automatically uninstalling this module." \
1401
$"DKMS: Install Failed (mkinitrd problems). Module rolled back to built state."
1404
echo $"DKMS: install Completed."
1407
# List each kernel object that has been installed for a particular module.
1408
list_each_installed_module()
1411
# $2 = kernel version
1414
local real_dest_module_location
1415
for ((count=0; count < ${#built_module_name[@]}; count++)); do
1416
real_dest_module_location="$(find_actual_dest_module_location $1 $count $2 $3)"
1417
echo "$install_tree/$2${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
1422
[[ $1 && $2 ]] || return 1
1423
valid_search_tree "$dkms_tree/$1/$2" || return 1
1424
[[ -L $dkms_tree/$1/$2/source || -d $dkms_tree/$1/$2/source ]];
1428
[[ $1 && $2 && $3 && $4 ]] || return 1
1429
local d="$dkms_tree/$1/$2/$3/$4" m=''
1430
valid_search_tree "$d" || return
1431
[[ -d $d/module ]] || return 1
1432
read_conf_or_die "$3" "$4" "$dkms_tree/$1/$2/source/dkms.conf"
1433
for m in "${dest_module_name[@]}"; do
1434
[[ -f $d/module/$m.ko || -f $d/module/$m.o ]] || return 1
1438
# This assumes we have already checked to see if the module has been built.
1439
_is_module_installed() {
1440
[[ $1 && $2 && $3 && $4 ]] || return 1
1441
local d="$dkms_tree/$1/$2/$3/$4"
1442
local k="$dkms_tree/$1/kernel-$3-$4"
1443
[[ -L $k && $(readlink -f $k) = $d ]]
1447
is_module_installed() { is_module_built "$@" && _is_module_installed "$@"; }
1449
maybe_add_module() (
1450
is_module_added "$1" "$2" && {
1451
echo $"Module $1/$2 already added."
1454
module="$1" module_version="$2" add_module
1457
maybe_build_module() (
1458
is_module_built "$1" "$2" "$3" "$4" && {
1459
echo $"Module $1/$2 already built for kernel $3/4"
1462
module="$1" module_version="$2" kernelver="$3" arch="$4" build_module
1465
maybe_install_module() (
1466
is_module_installed "$1" "$2" "$3" "$4" && {
1467
echo $"Module $1/$2 already installed on kernel $3/$4"
1470
module="$1" module_version="$2" kernelver="$3" arch="$4" install_module
1475
for ((i=0; i < ${#kernelver[@]}; i++)); do
1476
maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}"
1482
for ((i=0; i < ${#kernelver[@]}; i++)); do
1483
maybe_install_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}"
1487
check_module_exists() {
1488
is_module_added "$module" "$module_version" && return
1489
die 2 $"DKMS tree does not contain: $module-$module_version" \
1490
$"Build cannot continue without the proper tree."
1493
possible_dest_module_locations()
1496
# There are two places an installed module may really be:
1497
# 1) "$install_tree/$kernelver/${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
1498
# 2) "$install_tree/$kernelver/${DEST_MODULE_LOCATION[$count]}/${dest_module_name[$count]}$module_suffix"
1499
# override_dest_module_location() is what controls whether or not they're the same.
1502
location[0]="${dest_module_location[$count]}"
1503
[[ ${DEST_MODULE_LOCATION[$count]} != ${dest_module_location[$count]} ]] && \
1504
location[1]="${DEST_MODULE_LOCATION[$count]}"
1506
echo "${location[@]}"
1509
find_actual_dest_module_location()
1513
local kernelver="$3"
1515
local locations="$(possible_dest_module_locations $count)"
1519
dkms_owned="${dkms_tree}/${module}/kernel-${kernelver}-${arch}/module/${dest_module_name[$count]}${module_suffix}"
1521
for l in $locations; do
1522
installed="${install_tree}/${kernelver}${l}/${dest_module_name[${count}]}${module_suffix}"
1523
if [[ -f ${installed} ]] && diff "${dkms_owned}" "${installed}" > /dev/null 2>&1; then
1531
# Remove compiled DKMS modules from any kernels they are installed in.
1534
# $1 = kernel version
1538
echo $"-------- Uninstall Beginning --------"
1539
echo $"Module: $module"
1540
echo $"Version: $module_version"
1541
echo $"Kernel: $1 ($2)"
1542
echo $"-------------------------------------"
1544
set_module_suffix "$1"
1546
# If kernel-<kernelver> symlink points to this module, check for original_module and put it back
1548
local kernel_symlink=$(readlink -f "$dkms_tree/$module/kernel-$1-$2")
1549
local real_dest_module_location
1550
if [[ $kernel_symlink = $dkms_tree/$module/$module_version/$1/$2 ]]; then
1553
echo $"Status: Before uninstall, this module version was ACTIVE on this kernel."
1554
# remove kabi-tracking if last instance removed
1555
if [[ ${weak_modules} ]] && \
1556
(module_status_built $module $module_version |grep -q "installed"); then
1557
echo $"Removing any linked weak-modules"
1558
list_each_installed_module "$module" "$1" "$2" | ${weak_modules} --remove-modules
1561
for ((count=0; count < ${#built_module_name[@]}; count++)); do
1562
real_dest_module_location="$(find_actual_dest_module_location $module $count $1 $2)"
1564
echo $"${dest_module_name[$count]}$module_suffix:"
1565
echo $" - Uninstallation"
1566
echo $" - Deleting from: $install_tree/$1${real_dest_module_location}/"
1567
rm -f "$install_tree/$1${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
1568
echo $" - Original module"
1569
if [[ -e $dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix ]]; then
1570
case "$running_distribution" in
1571
Debian* | Ubuntu* ) ;;
1573
echo $" - Archived original module found in the DKMS tree"
1574
echo $" - Moving it to: $install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
1575
mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
1576
mv -f "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" \
1577
"$install_tree/$1${DEST_MODULE_LOCATION[$count]}/" 2>/dev/null
1581
echo $" - No original module was found for this module on this kernel."
1582
echo $" - Use the dkms install command to reinstall any previous module version."
1584
# Remove modules_conf entries from /etc/modules.conf if remake_initrd is set or if this is last instance removed
1585
if [[ $remake_initrd ]] || \
1586
(do_status $module $module_version | grep -q "installed"); then
1588
moduleconfig_remove "$1"
1592
rm -f "$dkms_tree/$module/kernel-$1-$2"
1595
echo $"Status: This module version was INACTIVE for this kernel."
1598
# Run the post_remove script
1599
run_build_script post_remove "$post_remove"
1601
# Run depmod because we changed /lib/modules
1602
invoke_command "do_depmod $1" "depmod" background
1604
# Do remake_initrd things (remake initrd)
1605
if [[ $remake_initrd && $was_active ]] && ! make_initrd "$1" "$2"; then
1606
warn $"There was a problem remaking your initrd. You must manually remake it" \
1607
$"before booting into this kernel."
1610
# Delete the original_module if nothing for this kernel is installed anymore
1611
if [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2 && \
1612
! -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then
1614
echo $"Removing original_module from DKMS tree for kernel $1 ($2)"
1615
rm -rf "$dkms_tree/$module/original_module/$1/$2" 2>/dev/null
1616
[[ $(find $dkms_tree/$module/original_module/$1/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module/$1"
1617
elif [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then
1619
echo $"Keeping directory $dkms_tree/$module/original_module/$1/$2/collisions/"
1620
echo $"for your reference purposes. Your kernel originally contained multiple"
1621
echo $"same-named modules and this directory is now where these are located."
1623
[[ $(find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module"
1625
# Re-add entries to modules.conf if this module/version is still installed on another kernel
1626
# But only do this if it was just ACTIVE on the kernel we just uninstalled from
1627
[[ $was_active && $remake_initrd ]] && do_status $module $module_version | grep -q "installed" && moduleconfig_add "$1"
1630
echo $"DKMS: uninstall Completed."
1633
# Check our preconditions, and then let do_install do all the hard work.
1636
# Check that the right arguments were passed
1637
check_module_args uninstall
1639
# Check that $module is in the dkms tree
1640
[[ -d $dkms_tree/$module ]] || die 2 \
1641
$"There are no instances of module: $module" \
1642
$"located in the DKMS tree."
1644
# Make sure that its installed in the first place
1645
[[ -d $dkms_tree/$module/$module_version ]] || die 3 \
1646
$"The module/version combo: $module-$module_version" \
1647
$"is not located in the DKMS tree."
1649
# Read the conf file
1650
read_conf_or_die "$kernelver" "$arch"
1652
# Only do stuff if module/module version is currently installed
1653
local kernel_symlink=$(readlink -f "$dkms_tree/$module/kernel-$kernelver-$arch")
1654
[[ $kernel_symlink = $dkms_tree/$module/$module_version/$kernelver/$arch ]] || die 5 \
1655
$"The module $module $module_version is not currently installed." \
1656
$"This module is not currently ACTIVE for kernel $kernelver ($arch)."
1657
do_uninstall "$kernelver" "$arch"
1660
# Unregister a DKMS module. This uninstalls any installed modules along the way.
1663
# Check that the right arguments were passed
1664
if [[ ! ($module && $module_version) || $kernels_arches_default ]]; then
1665
die 1 $"Invalid number of parameters passed." \
1666
$"Usage: remove <module>/<module-version> --all" \
1667
$" or: remove <module>/<module-version> -k <kernel-version>"
1670
# Check that $module is in the dkms tree
1671
if ! [[ -d $dkms_tree/$module/$module_version ]]; then
1672
die 3 $"There are no instances of module: $module" \
1673
$"$module_version located in the DKMS tree."
1677
for ((i=0; i < ${#kernelver[@]}; i++)); do
1678
# make sure its there first before removing
1679
if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
1680
die 4 $"There is no instance of $module $module_version" \
1681
$"for kernel ${kernelver[$i]} (${arch[$i]}) located in the DKMS tree."
1684
# Do --rpm_safe_upgrade check (exit out and don't do remove if inter-release RPM upgrade scenario occurs)
1685
if [[ $rpm_safe_upgrade ]]; then
1686
local pppid=$(awk '/PPid:/ {print $2}' /proc/$PPID/status)
1687
local time_stamp=$(ps -o lstart --no-headers -p $pppid 2>/dev/null)
1688
for lock_file in $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.*; do
1689
[[ -f $lock_file ]] || continue
1690
lock_head=$(head -n 1 $lock_file 2>/dev/null)
1691
lock_tail=$(tail -n 1 $lock_file 2>/dev/null)
1692
[[ $lock_head = $module-$module_version && $time_stamp && $lock_tail = $time_stamp ]] || continue
1694
die 0 $"DKMS: Remove cancelled because --rpm_safe_upgrade scenario detected."
1698
# Read the conf file
1699
read_conf_or_die "${kernelver[$i]}" "${arch[$i]}"
1701
do_uninstall "${kernelver[$i]}" "${arch[$i]}"
1703
# Delete the $kernel_version/$arch_used part of the tree
1704
rm -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}"
1705
[[ $(find $dkms_tree/$module/$module_version/${kernelver[$i]}/* \
1706
-maxdepth 0 -type d 2>/dev/null) ]] || \
1707
rm -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}"
1710
# Delete the $module_version part of the tree if no other $module_version/$kernel_version dirs exist
1711
if ! find $dkms_tree/$module/$module_version/* -maxdepth 0 -type d 2>/dev/null | egrep -qv "(build|tarball|driver_disk|rpm|deb|source)$"; then
1713
echo $"------------------------------"
1714
echo $"Deleting module version: $module_version"
1715
echo $"completely from the DKMS tree."
1716
echo $"------------------------------"
1717
rm -rf "$dkms_tree/$module/$module_version"
1721
# Get rid of any remnant directories if necessary
1722
if (($(ls "$dkms_tree/$module" | wc -w | awk '{print $1}') == 0)); then
1723
rm -rf "$dkms_tree/$module" 2>/dev/null
1725
# Its now safe to completely remove references in /etc/sysconfig/kernel for SuSE
1726
etc_sysconfig_kernel_modify "delete"
1730
# Test to see if a pathname is a "valid" pathname
1731
# to use for searching on.
1732
valid_search_tree() {
1733
[[ -d $1 && ! ( $1 =~ $reserved_tree_names ) ]]
1736
# Given a kernel object, figure out which DKMS module it is from.
1737
find_module_from_ko()
1740
local basename_ko="${ko##*/}"
1744
for kernellink in "$dkms_tree"/*/kernel-*; do
1745
[[ -L $kernellink ]] || continue
1746
module=${kernellink#$dkms_tree/}
1747
module=${module%/kernel-*}
1748
diff "$kernellink/module/${basename_ko}" "${ko}" >/dev/null 2>&1 || continue
1749
rest=$(readlink $kernellink)
1750
echo "$module/$rest"
1756
# Check to see if modules meeting the passed parameters are weak-installed.
1757
# This function's calling convention is different from the usual DKMS status
1758
# checking functions -- the kernel version we usually have is the one we are currently
1759
# running on, not necessarily the one we compiled the module for.
1760
module_status_weak() {
1761
# $1 = module, $2 = module version, $3 = kernel version weak installed to,
1762
# $4 = kernel arch, $5 = kernel version built for
1763
[[ $weak_modules ]] || return 1
1764
local weak_ko mod installed_ko f ret=1 oifs=$IFS
1765
local -a already_found
1766
for weak_ko in "$install_tree/"*/weak-updates/*; do
1767
[[ -e $weak_ko ]] || continue
1768
[[ -L $weak_ko ]] && installed_ko="$(readlink -f "$weak_ko")" || continue
1769
IFS=/ read m v k a < <(IFS=$oifs find_module_from_ko "$weak_ko") || continue
1770
kern=${weak_ko#$install_tree/}
1771
kern=${kern%/weak-updates/*}
1772
[[ $m = ${1:-*} && $v = ${2:-*} && $k = ${5:-*} && \
1773
$a = ${4:-*} && $kern = ${3:-*} ]] || \
1776
for f in "${already_found[@]}"; do
1777
[[ $f = $m/$v/$kern/$a/$k ]] && continue 2
1779
already_found[${#already_found[@]}]="$m/$v/$kern/$a/$k"
1780
echo "installed-weak $m/$v/$kern/$a/$k"
1785
# Print the requested status lines for weak-installed modules.
1788
local mvka m v k a kern status
1789
while read status mvka; do
1790
IFS=/ read m v k a kern <<< "$mvka"
1791
echo "$m, $v, $k, $a: installed-weak from $kern"
1792
done < <(module_status_weak "$@")
1795
# Spit out all the extra status information that people running DKMS are
1796
# interested in, but that the DKMS internals do not usually care about.
1797
module_status_built_extra() (
1798
set_module_suffix "$3"
1799
read_conf "$3" "$4" "$dkms_tree/$1/$2/source/dkms.conf"
1800
[[ -d $dkms_tree/$1/original_module/$3/$4 ]] && echo -n " (original_module exists)"
1801
for ((count=0; count < ${#dest_module_name[@]}; count++)); do
1802
tree_mod="$dkms_tree/$1/$2/$3/$4/module/${dest_module_name[$count]}$module_suffix"
1803
if ! [[ -e $tree_mod ]]; then
1804
echo -n " (WARNING! Missing some built modules!)"
1805
elif _is_module_installed "$@"; then
1806
real_dest="$(find_actual_dest_module_location "$1" $count "$3" "$4")"
1807
if ! diff -q "$tree_mod" "$install_tree/$3${real_dest}/${dest_module_name[$count]}$module_suffix" >/dev/null 2>&1; then
1808
echo -n " (WARNING! Diff between built and installed module!)"
1814
# Return a list of all the modules that are either built or installed.
1815
# This and module_status do some juggling of $IFS to ensure that
1816
# we do not get word splitting where it would be inconvienent.
1817
module_status_built() {
1818
local ret=1 directory ka k a state oifs="$IFS" IFS=''
1819
for directory in "$dkms_tree/$1/$2/"${3:-[0-9].*}/${4:-*}; do
1821
valid_search_tree "$directory" || continue
1822
ka="${directory#$dkms_tree/$1/$2/}"
1825
is_module_built "$1" "$2" "$k" "$a" || continue
1828
_is_module_installed "$1" "$2" "$k" "$a" && \
1830
echo "$state $1/$2/$k/$a"
1837
# Return the status of all modules that have been added, built, or installed.
1839
local oifs="$IFS" IFS='' mv m v directory ret=1
1840
for directory in "$dkms_tree/"${1:-*}/${2:-*}; do
1842
valid_search_tree "$directory" || continue
1843
mv="${directory#$dkms_tree/}"
1846
is_module_added "$m" "$v" || continue
1848
module_status_built "$m" "$v" "$3" "$4" || echo "added $m/$v"
1855
# Print out the status in the format that people who call DKMS expect.
1856
# Internal callers should use the module_status functions, as their output
1857
# is easier to parse.
1859
local status mvka m v k a
1860
while read status mvka; do
1861
IFS=/ read m v k a <<< "$mvka"
1863
added) echo "$m, $v: $status";;
1864
built|installed) echo -n "$m, $v, $k, $a: $status"
1865
module_status_built_extra "$m" "$v" "$k" "$a"
1868
done < <(module_status "$@")
1871
# Show all our status in the format that external callers expect, even
1872
# though it is slightly harder to parse.
1876
if ((${#kernelver[@]} == 0)); then
1877
do_status "$module" "$module_version" "$kernelver" "$arch"
1878
do_status_weak "$module" "$module_version" "$kernelver" "$arch"
1880
for ((j=0; j < ${#kernelver[@]}; j++)); do
1881
do_status "$module" "$module_version" "${kernelver[$j]}" "${arch[$j]}"
1882
do_status_weak "$module" "$module_version" "${kernelver[$j]}" "${arch[$j]}"
1887
create_temporary_trees()
1889
[[ $module || $module_version || ! -r dkms.conf ]] && return 0
1892
module="$PACKAGE_NAME"
1893
module_version="$PACKAGE_VERSION"
1895
source_tree=$(mktemp_or_die -d)
1896
dkms_tree=$(mktemp_or_die -d)
1898
local source_tree_dir="$source_tree/$PACKAGE_NAME-$PACKAGE_VERSION"
1899
mkdir -p "$source_tree_dir"
1900
cp -a * "$source_tree_dir" # intentionally skip .git or .hg
1902
temporary_trees_del_command="rm -rf $source_tree $dkms_tree"
1905
delete_temporary_trees()
1907
[[ $temporary_trees_del_command ]] || return 0
1908
$temporary_trees_del_command
1913
temporary_trees_del_command=
1916
in_temporary_trees() { [[ $temporary_trees_del_command ]] ;}
1920
local mrx='^(floppy|iso|tar)$'
1921
[[ $media =~ $mrx ]]
1924
make_driver_disk_floppy()
1926
local image_name="$1"
1927
local source_dir="$2"
1930
[[ $distro = redhat* ]] && fs='vfat'
1933
invoke_command "dd if=/dev/zero of=$image_name bs=$(($size/20))k count=20" "making a blank floppy image" background
1935
vfat) invoke_command "mkdosfs $image_name" "mkdosfs" background;;
1936
ext2) invoke_command "mke2fs -F $image_name" "mke2fs" background;;
1939
local mntdir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
1940
invoke_command "mount -o loop -t $fs $image_name $mntdir >/dev/null 2>&1" "loopback mounting disk image"
1941
[[ -d $mntdir/lost+found ]] && rmdir "$mntdir/lost+found"
1942
invoke_command "cp -r $source_dir/* $mntdir/" " copying files to floppy disk image"
1943
invoke_command "umount $mntdir" "unmounting disk image"
1947
make_driver_disk_isotar()
1950
local image_name="$2"
1951
local source_dir="$3"
1954
iso) invoke_command "mkisofs -v -r -J -pad -V $module -o $image_name ." "mkisofs" background;;
1955
tar) invoke_command "tar cvf $image_name ." "tar" background;;
1959
make_driver_disk_media()
1961
echo "Copying files $2"
1964
floppy*) make_driver_disk_floppy "$1" "$2";;
1965
iso*) make_driver_disk_isotar "iso" "$1" "$2";;
1966
tar*) make_driver_disk_isotar "tar" "$1" "$2";;
1970
driver_disk_suffix()
1973
floppy*) echo "img";;
1979
make_redhat_driver_disk()
1982
# kludge to allow redhat1 driver disks with BOOT kernel modules (arch i386)
1983
if [[ $distro = redhat1 && $multi_arch = true ]]; then
1984
local redhat1_okay="true"
1986
for ((i=0; i < ${#kernelver[@]}; i++)); do
1987
if [[ ${arch[$i]} != i386 && $other_arch != ${arch[$i]} && $other_arch ]]; then
1988
die 3 $"You have specified a Red Hat version 1 driver disk, but have also" \
1989
$"specified multiple architectures. Version 1 does not support this." \
1990
$"Use 'redhat2' instead (only OSes >= RHEL3, FC1 support version 2)."
1991
elif [[ ${arch[$i]} != i386 && $other_arch != ${arch[$i]} && ! $other_arch ]]; then
1992
other_arch="${arch[$i]}"
1996
if [ "$distro" == "redhat2" ] && [ -z "$redhat1_okay" ]; then
1997
echo $"Creating Red Hat v2 driver disk (arch support)."
1999
local rhdd_filename="rhdd"
2000
elif [ "$distro" == "redhat3" ] && [ -z "$redhat1_okay" ]; then
2001
echo $"Creating Red Hat v3 driver disk."
2003
make_redhat3_driver_disk
2006
echo $"Creating Red Hat v1 driver disk."
2008
local rhdd_filename="rhdd-6.1"
2011
cpioarchive_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2013
for ((i=0; i < ${#kernelver[@]}; i++)); do
2014
set_module_suffix "${kernelver[$i]}"
2016
local dd_prefix="${kernelver[$i]}"
2017
[[ $distro = redhat2 ]] && dd_prefix="${kernelver[$i]}/${arch[$i]}"
2018
[[ $multi_arch = true && -z $redhat1_okay ]] && dd_prefix="${kernelver[$i]}/${arch[$i]}"
2019
maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}" || {
2020
rm -rf "$cpioarchive_dir_name"
2021
die 5 $"Cannot build $module/$module_version for redhat driver disk."
2024
# FIXME: add check for KMP binary RPMs to include in the driver disk
2025
if [[ ! $kernel_version_list ]]; then
2026
kernel_version_list="kernel${kernelver[$i]}-${arch[$i]}"
2028
kernel_version_list="$kernel_version_list-kernel${kernelver[$i]}-${arch[$i]}"
2030
mkdir -p $cpioarchive_dir_name/$dd_prefix
2031
for f in "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/"*"$module_suffix"; do
2032
[[ -f $f ]] || continue
2033
echo "Marking ${f#$dkms_tree/$module/$module_version/}..."
2034
cp "$f" "$cpioarchive_dir_name/$dd_prefix/"
2035
modules_cgz_list="$dd_prefix/${f##*/} ${modules_cgz_list}"
2040
# Create directory and necessary files
2041
driver_disk_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2043
# Copy files for the driver disk (or warn if not present)
2044
local files_for_driverdisk="modinfo disk-info modules.dep pcitable modules.pcimap pci.ids"
2045
# Fedora Core 5 and higher, RHEL5 and higher, strictly require: rhdd, modules.cgz, modinfo, modules.alias, modules.dep
2046
# which is in effect ignoring disk-info, pcitable, modules.pcimap and pci.ids
2047
# and adding modules.alias, which will be generated.
2049
local files_into_driverdisk="modules.cgz $rhdd_filename modules.alias"
2050
for file in $files_for_driverdisk; do
2051
if [[ -e $dkms_tree/$module/$module_version/source/redhat_driver_disk/$file ]]; then
2052
files_into_driverdisk="$file $files_into_driverdisk"
2053
cp -f "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" "$driver_disk_dir/" 2>/dev/null
2055
warn $"File: $file not found in $dkms_tree/$module/$module_version/source/redhat_driver_disk/"
2058
echo "$module-$module_version driver disk" > "$driver_disk_dir/$rhdd_filename"
2060
# Make sure the kernel_version_list is not too long
2061
if (( $(echo $kernel_version_list | wc -m | awk {'print $1'}) > 200 )); then
2062
kernel_version_list="manykernels"
2065
local suffix="$(driver_disk_suffix)"
2066
local image_dir="$dkms_tree/$module/$module_version/driver_disk"
2067
local image_name="$module-$module_version-$kernel_version_list-dd.$suffix"
2069
echo $"Creating driver disk on $media media:"
2070
cd "$cpioarchive_dir_name"
2071
invoke_command "echo '$modules_cgz_list' | cpio -oH crc 2>/dev/null | gzip -9 > ./modules.cgz" "compressing modules.cgz" background
2072
cp -f ./modules.cgz "$driver_disk_dir/"
2074
# generate modules.alias file
2075
# On 2.4 kernels and kernels with no aliases. this won't yield anything.
2076
touch ./modules.alias
2077
for f in ${modules_cgz_list}; do
2078
module_wo_suffix=$(basename ${f} ${module_suffix})
2079
tmp_alias="./modules.alias.${module_wo_suffix}"
2081
depmod -n ${f} 2>/dev/null | grep ^alias > ${tmp_alias}
2082
if [[ -s ${tmp_alias} ]]; then
2083
cat "${tmp_alias}" >> ./modules.alias
2086
[[ -e ./modules.alias ]] && cp -f ./modules.alias "$driver_disk_dir/"
2087
# FIXME: add rpms/ directory, copy in KMP RPMs, run createrepo --pretty
2090
rm -rf "$cpioarchive_dir_name"
2092
mkdir -p "$image_dir"
2093
rm -f "$image_dir/$image_name"
2095
cd "$driver_disk_dir"
2096
make_driver_disk_media "$image_dir/$image_name" "$driver_disk_dir"
2098
rm -rf "$driver_disk_dir"
2101
echo $"Disk image location: $image_dir/$image_name"
2103
echo $"DKMS: mkdriverdisk Completed."
2108
# Check that the right arguments were passed
2109
if ! [[ $module && $module_version && $distro && $kernelver ]]; then
2110
die 1 $"Invalid number of parameters passed." \
2111
$"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver> [--media floppy|iso|tar]"
2114
# default to floppy media
2115
[[ $media ]] || media="floppy"
2116
if ! media_valid; then
2117
die 1 $"Media $media is invalid." \
2118
$"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver> [--media floppy|iso|tar]"
2121
# Check that source symlink works
2124
# Confirm that distro is supported
2126
redhat | redhat[123] | suse | UnitedLinux | ubuntu) ;;
2127
*) die 3 $"Invalid distro argument. Currently, the distros" \
2128
$"supported are: redhat, redhat1, redhat2, redhat3, suse, UnitedLinux" \
2132
# Read the conf file
2133
read_conf_or_die "$kernelver" "$arch"
2136
redhat*) make_redhat_driver_disk;;
2137
ubuntu) make_ubuntu_driver_disk;;
2138
*) make_suse_driver_disk;;
2142
find_external_dependencies()
2147
# find all module dependencies
2148
for ((count=0; count < ${#dest_module_name[@]}; count++)); do
2149
for ((i=0; i < ${#kernelver[@]}; i++)); do
2150
set_module_suffix "${kernelver[$i]}"
2151
mod="$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix"
2152
deps=(${deps[@]} $(modinfo "$mod" | sed -n 's/,/ /g; s/^depends: *//p'))
2156
# prune internally satisfied dependencies
2158
for ((i=0; i < ${#deps[@]}; i++)); do
2159
for mod in ${dest_module_name[@]}; do
2160
[[ ${deps[i]} = $mod ]] && deps[i]=
2164
for dep in "${deps[@]}"; do
2169
make_suse_driver_disk()
2171
[[ $release ]] || die 3 \
2172
$"Invalid number of parameters passed for suse/UnitedLinux driver disk." \
2173
$"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver>" \
2174
$" -r <release-number>"
2176
local driver_disk_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2177
local suffix="$(driver_disk_suffix)"
2178
local image_dir="$dkms_tree/$module/$module_version/driver_disk"
2179
local image_name="$module-$module_version-$distro-$release-dd.$suffix"
2182
echo $"Creating driver disk:"
2184
local deps="$(find_external_dependencies)"
2187
# reserve a place for dependencies
2188
[[ ${deps[@]} ]] && offset=1
2191
for ((count=0; count < ${#dest_module_name[@]}; count++)); do
2193
local topdir=$(printf "%02d" $(($count+1+offset)))
2194
for ((i=0; i < ${#kernelver[@]}; i++)); do
2195
set_module_suffix "${kernelver[$i]}"
2197
if ! [[ -e $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix ]]; then
2198
rm -rf $temp_dir_name
2200
$"Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver[$i]} (${arch[$i]})." \
2201
$"Module/version must be in built state before making a driver disk."
2203
# FIXME: add check for KMP binary RPMs to include in the driver disk
2204
suse_arch=${arch[$i]}
2206
i?86) suse_arch=i386;;
2209
echo "Marking ${kernelver[$i]}/${arch[$i]}/modules/${dest_module_name[$count]}$module_suffix..."
2210
mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver[$i]}${dest_module_location[$count]}"
2211
cp "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver[$i]}${dest_module_location[$count]}/"
2213
case ${kernelver[$i]} in
2215
mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
2216
cp "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
2220
# create directory for dependency information
2221
[[ ${deps[@]} ]] && mkdir -p "$driver_disk_dir/01/linux/$distro/$suse_arch-$release/modules"
2226
for arch_release in $(find $driver_disk_dir/$topdir -maxdepth 1 -mindepth 1 -type d | sed "s#$driver_disk_dir\/$topdir\/##"); do
2227
cd "$driver_disk_dir/$topdir/$arch_release/install/"
2228
invoke_command "tar cvzf update.tar.gz lib/" "making update.tar.gz for $arch_release" background
2231
mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install"
2232
mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/modules"
2234
echo $" copying update.tar.gz for $arch_release to disk image..."
2235
cp -f "$driver_disk_dir/$topdir/$arch_release/install/update.tar.gz" "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/"
2238
archtest=${arch_release/-*}
2239
for ((i=0; i<${#kernelver[@]}; i++)); do
2240
[[ ${arch[$i]} = ${archtest} ]] && \
2241
postkernels="${postkernels} ${kernelver[$i]}"
2244
if [[ ${postkernels} ]]; then
2245
dstfile="$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/update.post"
2246
echo $" creating update.post for $arch_release..."
2250
kernlist="${postkernels}"
2252
for kernel in \${kernlist}; do
2253
if [ -e /boot/System.map-\${kernel} ]; then
2254
depmod -a -F /boot/System.map-\${kernel} \${kernel}
2260
chmod a+x ${dstfile}
2263
if [[ -d $driver_disk_dir/$topdir/$arch_release/modules/ ]]; then
2264
echo $" copying kernel modules for installation kernel to disk image..."
2265
cp -f $driver_disk_dir/$topdir/$arch_release/modules/* $driver_disk_dir/$topdir/linux/$distro/$arch_release/modules/ 2>/dev/null
2267
warn $"No kernel modules found for -default kernel."
2270
rm -fr "$driver_disk_dir/$topdir/$arch_release"
2275
if [[ ${deps[@]} ]]; then
2276
for dir in "$driver_disk_dir/01/linux/$distro/"*"/modules"; do
2277
for dep in "${deps[@]}"; do
2278
echo $dep >> "$dir/module.order"
2283
# FIXME: add suse-equivalent rpms/ directory, copy in KMP RPMs, run createrepo --pretty
2285
mkdir -p "$image_dir"
2286
rm -f "$image_dir/$image_name"
2287
cd "$driver_disk_dir"
2288
make_driver_disk_media "$image_dir/$image_name" "$driver_disk_dir"
2290
rm -rf "$driver_disk_dir"
2293
echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
2295
echo $"DKMS: mkdriverdisk Completed."
2298
make_ubuntu_driver_disk()
2300
local suffix="$(driver_disk_suffix)"
2301
local image_dir="$dkms_tree/$module/$module_version/driver_disk"
2302
local image_name="$module-$module_version-$distro-dd.$suffix"
2304
local tempdir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2306
# Check that the dh_make command is present
2307
if ! which dpkg-deb >/dev/null 2>&1 ; then
2308
die 1 $"dpkg-deb not present." \
2309
$"Install the dpkg-dev package."
2313
for ((i=0; i < ${#kernelver[@]}; i++)); do
2314
set_module_suffix "${kernelver[$i]}"
2315
# Driver disks only recognize i386 as package arch
2316
local karch=${arch[$i]/i?86/i386}
2317
local kvers=${kernelver[$i]/-/_}; kvers=${kvers%%_*}
2318
# ubuntu-drivers/<kver>/*_<debarch>.deb
2319
local dd_prefix="ubuntu-drivers/$kvers"
2320
local dd_suffix="_${karch}.deb"
2321
maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}" || {
2323
die 5 $"Unable to build $module/$module_version for Ubuntu driver disk."
2325
mkdir -p "$tempdir/$dd_prefix"
2326
local deb_dir="$tempdir/$dd_prefix/debian"
2327
local deb_lib_dir="$deb_dir/lib/modules/${kernelver[$i]}/updates/dkms"
2328
mkdir -p "$deb_lib_dir"
2329
cp "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/"*"$module_suffix" "$deb_lib_dir"
2330
pushd "$deb_dir" > /dev/null 2>&1
2332
cat > DEBIAN/control <<EOF
2333
Package: ${module}-modules-${kernelver[$i]}
2334
Version: ${module_version}-1
2337
Architecture: $karch
2339
Maintainer: DKMS <dkms-devel@dell.com>
2340
Description: DKMS packaged binary driver update
2341
DKMS automagically generated debian package for
2342
driver update disks, used with Ubuntu installation
2343
programs (such as Ubiquity).
2346
# Generate the DEBIAN/preinst file.
2347
# This is tricky as we need some parts evaluated now
2348
# and some parts evaluated at runtime
2349
cat >DEBIAN/preinst <<EOF
2351
[[ \$(uname -r) = ${kernelver[$i]} ]] || exit 1
2354
chmod 0775 DEBIAN/preinst
2355
cd "$tempdir/$dd_prefix"
2356
dpkg-deb --build debian
2357
mv debian.deb "${module}_${module_version}-${kernelver[$i]}${dd_suffix}"
2359
popd > /dev/null 2>&1
2362
echo "Copying source..."
2363
mkdir -p "$tempdir/ubuntu"
2364
cp -ar "$source_tree/$module-$module_version" "$tempdir/ubuntu/"
2366
mkdir -p "$image_dir"
2367
rm -f "$image_dir/$image_name"
2369
make_driver_disk_media "$image_dir/$image_name" "$tempdir"
2373
echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
2375
echo $"DKMS: mkdriverdisk Completed."
2380
make_common_test "mktarball"
2382
# Check for dkms_dbversion
2383
if ! [[ -e $dkms_tree/dkms_dbversion ]]; then
2385
echo $"Could not find the file $dkms_tree/dkms_dbversion." >&2
2386
echo $"Creating w/ default contents." >&2
2387
echo "2.0.0" > $dkms_tree/dkms_dbversion
2390
# Read the conf file
2391
read_conf_or_die "$kernelver" "$arch"
2393
temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2394
mkdir -p $temp_dir_name/dkms_main_tree
2396
if [[ $source_only ]]; then
2397
kernel_version_list="source-only"
2400
for ((i=0; i<${#kernelver[@]}; i++)); do
2401
if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
2402
rm -rf "$temp_dir_name" 2>/dev/null
2403
die 6 $"No modules built for ${kernelver[$i]} (${arch[$i]})." \
2404
$"Modules must already be in the built state before using mktarball."
2407
set_module_suffix "${kernelver[$i]}"
2409
echo "Marking modules for ${kernelver[$i]} (${arch[$i]}) for archiving..."
2410
if [[ ! $kernel_version_list ]]; then
2411
kernel_version_list="kernel${kernelver[$i]}-${arch[$i]}"
2413
kernel_version_list="${kernel_version_list}-kernel${kernelver[$i]}-${arch[$i]}"
2415
mkdir -p "$temp_dir_name/dkms_main_tree/${kernelver[$i]}/${arch[$i]}"
2416
cp -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}" "$temp_dir_name/dkms_main_tree/${kernelver[$i]}"
2420
# Store the dkms_dbversion in the tarball
2421
cp -f "$dkms_tree/dkms_dbversion" "$temp_dir_name/dkms_main_tree/"
2423
# Copy the source_tree or make special binaries-only structure
2424
if [[ $binaries_only ]]; then
2426
echo $"Creating tarball structure to specifically accomodate binaries."
2427
mkdir $temp_dir_name/dkms_binaries_only
2428
echo "$module" > $temp_dir_name/dkms_binaries_only/PACKAGE_NAME
2429
echo "$module_version" > $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION
2430
[[ ! $conf ]] && conf="$dkms_tree/$module/$module_version/source/dkms.conf"
2431
cp -f $conf $temp_dir_name/dkms_binaries_only/ 2>/dev/null
2434
echo $"Marking $dkms_tree/$module/$module_version/source for archiving..."
2435
mkdir -p $temp_dir_name/dkms_source_tree
2436
cp -rf $dkms_tree/$module/$module_version/source/* $temp_dir_name/dkms_source_tree
2439
if (( $(echo $kernel_version_list | wc -m | awk {'print $1'}) > 200 )); then
2440
kernel_version_list="manykernels"
2443
local tarball_name="$module-$module_version-$kernel_version_list.dkms.tar.gz"
2444
local tarball_dest="$dkms_tree/$module/$module_version/tarball/"
2446
# Die if we will not be able to create the tarball due to permissions.
2447
if [[ $archive_location ]]; then
2448
tarball_name="${archive_location##*/}"
2449
if [[ ${archive_location%/*} != $archive_location && \
2450
-d ${archive_location%/*} && -w ${archive_location%/*} ]]; then
2451
tarball_dest="${archive_location%/*}"
2452
elif [[ ${archive_location%/*} != $archive_location ]] && ! mkdir -p $tarball_dest; then
2453
die 9 $"Will not be able to create $archive_location due to a permissions problem."
2456
if [ ! -d $tarball_dest ]; then
2457
mkdir -p "$dkms_tree/$module/$module_version/tarball/"
2461
echo $"Tarball location: $tarball_dest/$tarball_name"
2463
local tarball_ext=${tarball_name##*.}
2464
[[ $tarball_ext = tar ]] || tarball_name=${tarball_name%.$tarball_ext}
2468
if tar -cf $temp_dir_name/$tarball_name ./* 2>/dev/null; then
2471
mv -f "$temp_dir_name/$tarball_name" "$tarball_dest/$tarball_name"
2472
rm -rf $temp_dir_name
2475
rm -rf $temp_dir_name
2476
die 6 $"Failed to make tarball."
2478
case $tarball_ext in
2479
gz) gzip -9 "$tarball_dest/$tarball_name";;
2480
bz2) bzip2 -9 "$tarball_dest/$tarball_name";;
2481
xz) xz -9 "$tarball_dest/$tarball_name";;
2484
echo $"DKMS: mktarball Completed."
2487
# A tiny helper function to make sure dkms.conf describes a valid package.
2488
get_pkginfo_from_conf() {
2489
[[ -f $1 && $1 = *dkms.conf ]] || return
2490
read_conf_or_die "$kernelver" "$arch" "$1"
2491
[[ $PACKAGE_NAME && $PACKAGE_VERSION ]]
2494
# Unpack a DKMS tarball from a few different supported formats.
2495
# We expect $archive_location to have been passed either as a raw argument or
2499
# Error out if $archive_location does not exist
2500
if [[ ! -e $archive_location ]]; then
2501
die 2 $"$archive_location does not exist."
2504
# If it is an .rpm file. install it with rpm, run an autoinstall, and then exit.
2505
if [[ $archive_location = *.rpm ]]; then
2506
if rpm -Uvh "$archive_location"; then
2510
die 9 $"Unable to install $archive_location using rpm." \
2511
$"Check to ensure that your system can install .rpm files."
2515
# Figure out what kind of archive it is (tar.gz, tar, tar.bz, etc)
2516
# Note that this does not depend on the extensions being correct.
2517
local tar_options=""
2518
for xpand in gzip bzip xz; do
2519
$xpand -t $archive_location 2>/dev/null || continue
2521
gzip) tar_options=z;;
2522
bzip2) tar_options=j;;
2528
# Untar it into $tmp_location
2529
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2530
trap 'rm -rf $temp_dir_name' EXIT
2531
tar -${tar_options}xf $archive_location -C $temp_dir_name
2533
if [[ ! $temp_dir_name/dkms_main_tree ]]; then
2534
# Tarball was not generated from mktarball.
2535
# Just find the dkms.conf file and load the source.
2536
conf=$(find $temp_dir_name/ -name dkms.conf 2>/dev/null | head -n 1)
2537
if [[ ! $conf ]]; then
2538
rm -rf $temp_dir_name
2539
die 3 $"Tarball does not appear to be a correctly formed" \
2540
$"DKMS archive. No dkms.conf found within it."
2542
add_source_tree "${conf%dkms.conf}"
2546
# Check that dkms_dbversion is not a future version
2547
# As far as I can tell, the only reason we bother with this is for detecting
2548
# whether we have arch support or not, which we can also determine by examining
2549
# the structure of the tarball.
2550
db_from_tarball=$(cat $temp_dir_name/dkms_main_tree/dkms_dbversion 2>/dev/null)
2551
db_from_dkms=$(cat $dkms_tree/dkms_dbversion 2>/dev/null)
2552
if [[ $db_from_tarball && $db_from_dkms && \
2553
$(VER "$db_from_tarball") > $(VER "$db_from_dkms") ]]; then
2555
$"The tarball you are trying to load indicates it is database version" \
2556
$"$db_from_tarball. This version of DKMS only supports $db_from_dkms or lower."
2559
# Make sure its a sane tarball. Sane ones will have one of the two
2560
# directories we test for.
2561
for loc in dkms_source_tree dkms_binaries_only ''; do
2562
if [[ ! $loc ]]; then
2563
die 7 $"No valid dkms.conf in dkms_source_tree or dkms_binaries_only." \
2564
$"$archive_location is not a valid DKMS tarball."
2566
local conf="$temp_dir_name/$loc/dkms.conf"
2567
[[ -f $conf ]] || continue
2568
if ! get_pkginfo_from_conf "$conf"; then
2570
echo $"Malformed dkms.conf, refusing to load." >&2
2573
if is_module_added "$PACKAGE_NAME" "$PACKAGE_VERSION" && \
2574
[[ ! $force ]]; then
2575
die 8 $"$PACKAGE_NAME-$PACKAGE_VERSION is already added!" \
2578
module="$PACKAGE_NAME"; module_version="$PACKAGE_VERSION"
2580
echo $"Loading tarball for $module-$module_version"
2583
add_source_tree "$temp_dir_name/dkms_source_tree";;
2585
#if there is a source tree on the system already, don't build a binaries stub
2586
if [[ ! -d $source_tree/$module-$module_version ]]; then
2587
echo $"Creating $dkms_tree/$module/$module_version/source"
2588
mkdir -p "$dkms_tree/$module/$module_version/source"
2589
echo $"Copying dkms.conf to $dkms_tree/$module/$module_version/source..."
2590
cp -rf "$temp_dir_name/dkms_binaries_only/dkms.conf" "$dkms_tree/$module/$module_version/source"
2592
*) die 8 $"$FUNCNAME:$LINENO: Cannot happen." \
2593
$"Report this error to dkms-devel@dell.com";;
2598
# at this point, the source has been copied to the appropriate location
2599
# and registered with dkms, or a binary-only config has been noted.
2600
# Now, add any included precompiled modules.
2602
# Is tarball from before DKMS 2.0 (prior to arch support)
2603
if [[ ! -e $temp_dir_name/dkms_main_tree/dkms_dbversion ]]; then
2604
[[ $loc = dkms_binaries_only ]] && rm -rf "$dkms_tree/$module/$module_version/source"
2605
die 10 $" This tarball was created with dkms < 2.0 and contains" \
2606
$"no arch info. DKMS is refusing to install precompiled modules."
2609
# Load precompiled modules.
2610
for directory in "$temp_dir_name/dkms_main_tree"/*/*; do
2611
[[ -d $directory ]] || continue
2612
kernel_arch_to_load=${directory/*dkms_main_tree\/}
2613
dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_arch_to_load"
2614
if [[ -d $dkms_dir_location && ! $force ]]; then
2615
warn $"$dkms_dir_location already exists. Skipping..."
2617
echo $"Loading $dkms_dir_location..."
2618
rm -rf $dkms_dir_location
2619
mkdir -p $dkms_dir_location
2620
cp -rf $directory/* $dkms_dir_location/
2625
echo $"DKMS: ldtarball Completed."
2626
[[ $loc != dkms_binaries_only ]] || [[ -d $source_tree/$module-$module_version ]]
2631
set_kernel_source_dir "$kernelver"
2633
# Error if $template_kernel is unset
2634
if [[ ! $template_kernel ]]; then
2635
die 1 $"Invalid number of parameters passed." \
2636
$"Usage: match --templatekernel=<kernel-version> -k <kernel-version>" \
2637
$" or: match --templatekernel=<kernel-version> -k <kernel-version> <module>"
2640
# Error out if $template_kernel = $kernel_version
2641
if [[ $template_kernel = $kernelver ]]; then
2642
die 2 $"The templatekernel and the specified kernel version are the same."
2645
# Read in the status of template_kernel
2646
local template_kernel_status=$(do_status '' '' $template_kernel $arch | grep ": installed")
2648
# If $module is set, grep the status only for that module
2649
if [[ $module ]]; then
2650
# Make sure that its installed in the first place
2651
if ! [[ -d $dkms_tree/$module/ ]]; then
2652
die 3 $"The module: $module is not located in the DKMS tree."
2654
template_kernel_status=$(echo "$template_kernel_status" | grep "^$module,")
2658
echo $"Matching modules in kernel: $kernelver ($arch)"
2659
echo $"to the configuration of kernel: $template_kernel ($arch)"
2661
# Prepare the kernel just once but only if there is actual work to do
2662
if [[ ! $template_kernel_status ]]; then
2664
echo $"There is nothing to be done for this match."
2666
prepare_kernel "$kernelver" "$arch"
2668
# Iterate over the kernel_status and match kernel to the template_kernel
2669
while read template_line; do
2670
template_module=`echo "$template_line" | awk {'print $1'} | sed 's/,$//'`
2671
template_version=`echo "$template_line" | awk {'print $2'} | sed 's/,$//'`
2673
# Print out a match header
2675
echo $"---- Match Beginning ----"
2676
echo $"Module: $template_module"
2677
echo $"Version: $template_version"
2678
echo $"-------------------------"
2680
# Figure out what to do from here
2681
if show_status "$template_module" "$template_version" "$kernelver" "$arch" 2>/dev/null | grep -q ": installed"; then
2683
echo $"This module/version combo is already installed. Nothing to be done."
2684
elif show_status "$template_module" "$template_version" "$kernelver" "$arch" 2>/dev/null | grep -q ": built"; then
2686
echo $"This module/version combo is built. Installing it:"
2687
module="$template_module"
2688
module_version="$template_version"
2692
echo $"Building & Installing this module/version:"
2693
module="$template_module"
2694
module_version="$template_version"
2698
done < <(echo "$template_kernel_status")
2700
# Clean up the kernel tree
2701
if [[ ! ( $(VER $kernelver) < $(VER 2.6.6) ) && \
2702
-d "$kernel_source_dir" && \
2703
! -h "$kernel_source_dir" && \
2704
-z "$ksourcedir_fromcli" ]]; then
2705
echo $"Kernel cleanup unnecessary for this kernel. Skipping..."
2706
elif [[ ! $no_clean_kernel ]]; then
2707
cd "$kernel_source_dir"
2708
[[ $kerneldoth_contents ]] || invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
2709
[[ $config_contents ]] && echo "$config_contents" > .config
2710
[[ $kerneldoth_contents ]] && echo "$kerneldoth_contents" > /boot/kernel.h
2717
echo $"DKMS: match Completed."
2722
make_common_test "mkrpm"
2724
# Check that the rpmbuild command is present
2725
if ! which rpmbuild >/dev/null 2>&1 ; then
2726
die 1 $"rpmbuild not present." \
2727
$"Install the rpm-build package."
2730
# Read the conf file
2731
read_conf_or_die "$kernelver" "$arch"
2733
local rpm_basedir="$dkms_tree/$module/$module_version/rpm"
2737
for sp in "$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec" \
2738
"/etc/dkms/template-dkms-mkrpm.spec"; do
2739
[[ -e $sp ]] || continue
2743
if [[ ! $SPECFILE ]]; then
2744
die 5 $"Cannot find $sp which is needed by" \
2745
$"DKMS in order use mkrpm."
2748
# Run a dkms mktarball for use in the rpm
2749
local mktarball_line
2750
if [[ ! $source_only || $binaries_only ]]; then
2751
mktarball_line="--binaries-only"
2754
for ((i=0; i<${#kernelver[@]}; i++)); do
2755
if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
2756
die 5 $"You do not seem to have $module $module_version built for" \
2757
$"${kernelver[$i]} (${arch[$i]}). All modules must be in" \
2758
$"the built state before you can use mkrpm."
2760
echo $"Marking ${kernelver[$i]} (${arch[$i]}) for RPM..."
2761
mktarball_line="-k ${kernelver[$i]} -a ${arch[$i]} $mktarball_line"
2764
mktarball_line="none"
2767
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2768
trap 'rm -rf $temp_dir_name' EXIT HUP TERM
2769
mkdir -p ${temp_dir_name}/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
2770
cp ${SPECFILE} ${temp_dir_name}/SPECS/dkms_mkrpm.spec
2772
#if using legacy mode, install common postinst
2773
if ((legacy_postinst != 0)); then
2774
invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '${temp_dir_name}/SOURCES'" "copying legacy postinstall template"
2777
#Copy in the source tree
2778
if [[ ! $binaries_only ]]; then
2779
invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '${temp_dir_name}/SOURCES/$module-$module_version'" "Copying source tree"
2782
if invoke_command "LC_ALL=C rpmbuild --define \"_topdir ${temp_dir_name}\" --define \"version $module_version\" --define \"module_name $module\" --define \"kernel_versions ${kernelver[*]}\" --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"; then
2783
mkdir -p ${rpm_basedir}
2784
cp -a ${temp_dir_name}/SRPMS/* ${temp_dir_name}/RPMS/*/* ${rpm_basedir}/
2786
cat ${temp_dir_name}/rpmbuild.log | grep ^Wrote | sed -e "s:${temp_dir_name}/:${rpm_basedir}/:" -e 's:SRPMS/::' -e 's:RPMS/.*/::'
2788
echo $"DKMS: mkrpm Completed."
2790
cat ${temp_dir_name}/rpmbuild.log >&2
2791
die 7 $"There was a problem creating your rpm."
2793
rm -rf $temp_dir_name
2794
trap > /dev/null 2>&1
2799
local date_str="$(date -R)"
2800
echo "modifying $1..."
2801
sed -e "s/DEBIAN_PACKAGE/$debian_package/g" \
2802
-e "s/MODULE_NAME/$module/g" \
2803
-e "s/MODULE_VERSION/$module_version/g" \
2804
-e "s/DATE_STAMP/$date_str/" "$1" > "$1.dkms-pp"
2805
mv "$1.dkms-pp" "$1"
2808
# Install a package on a debian system.
2811
local getroot tmpfile i
2812
local -a packages=("$@")
2813
for ((i=0; i < ${#packages[@]}; i++)); do
2814
dpkg-query -s "${packages[$i]}"| egrep -q '^Status:.* installed$' || continue
2817
# if they are already installed, we are OK.
2818
[[ ${package[@]} ]] || return
2819
if ((UID != 0)); then
2820
# figure out how to get root
2821
for getroot in su-to-root gksudo kdesu sudo; do
2822
which $getroot >/dev/null 2>&1 || continue
2824
su-to-root) getroot="$getroot -c";;
2825
gksudo) [[ $DISPLAY ]] || continue
2826
getroot="$getroot --description 'DKMS Debian package builder' ";;
2827
kdesu) [[ $DISPLAY ]] || continue;;
2832
if [[ -x /usr/sbin/synaptic && $DISPLAY ]] && tmpfile=$(mktemp_or_die); then
2833
# Pretty GUI install.
2834
trap 'rm -f "$tmpfile"' EXIT
2835
for ((i=0; i=${#packages[@]}; i++)); do
2836
[[ ${packages[$i]} ]] && echo "install ${packages[$i]}" >>$tmpfile
2838
$getroot "sh -c '/usr/sbin/synaptic --set-selections --non-interactive --hide-main-window < $tmpfile'"
2840
$getroot apt-get -y install "${packages[@]}"
2842
if (( $? != 0)); then
2843
die 4 $"Missing ${packages[@]}" \
2844
$"and unable to install. Please ask an admin to install for you."
2852
create_temporary_trees
2853
trap "delete_temporary_trees" EXIT HUP TERM
2855
make_common_test "mk${create_type}"
2857
debian_package=${module//_/-}
2859
# Read the conf file
2860
read_conf_or_die "$kernelver" "$arch"
2861
debian_install fakeroot dpkg-dev debhelper
2863
#skeleton to load templates from
2864
local system_mk="$dkms_tree/$module/$module_version/source/$module-dkms-mk${create_type}"
2865
local local_mk="/etc/dkms/template-dkms-mk${create_type}"
2866
if [[ -e ${system_mk} ]]; then
2867
echo $"Using ${system_mk}"
2869
elif [[ -e ${local_mk} ]]; then
2870
echo $"Using ${local_mk}"
2873
die 5 $"Cannot find ${local_mk} which is needed by" \
2874
$"DKMS in order to use mk${create_type}."
2877
#prepare build directory and copy template
2878
local temp_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2879
trap "rm -rf $temp_dir; delete_temporary_trees" EXIT HUP TERM
2880
local temp_dir_debian="$temp_dir/$debian_package-dkms-$module_version"
2881
invoke_command "cp -ar '$DEBDIR/' '$temp_dir_debian'" "copying template"
2882
pushd "$temp_dir_debian" > /dev/null 2>&1
2883
for file in debian/*; do
2884
preproc_file "$file"
2887
popd > /dev/null 2>&1
2889
#if using legacy mode, install common postinst
2890
if ((legacy_postinst != 0)); then
2891
invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '$temp_dir_debian'" "copying legacy postinstall template"
2894
#Copy in the source tree
2895
if [[ ! $binaries_only ]]; then
2896
invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '$temp_dir_debian/$module-$module_version'" "Copying source tree"
2899
#Only if we are shipping binary modules, make a .tgz for the deb
2900
local archive_location="$dkms_tree/$module/$module_version/tarball/$module-$module_version.dkms.tar.gz"
2901
if [[ ! $source_only ]]; then
2902
binaries_only="binaries-only"
2903
invoke_command "make_tarball" "Gathering binaries"
2904
if [[ -f $archive_location ]]; then
2905
invoke_command "cp '$archive_location' '$temp_dir_debian'" "Copying DKMS tarball into DKMS tree"
2907
die 12 $"Unable to find created tarball."
2911
#calculate destination directory
2912
deb_basedir=$dkms_tree/$module/$module_version/${create_type}
2913
mkdir -p ${deb_basedir} >/dev/null 2>&1
2916
pushd "$temp_dir_debian" > /dev/null 2>&1
2917
case "$create_type" in
2919
invoke_command "dpkg-buildpackage -S -us -uc 1>/dev/null" "Building source package" || \
2920
die 7 $"There was a problem creating your ${create_type}."
2922
echo $"DKMS: mk${create_type} Completed."
2923
invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_source.changes' '$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"
2926
invoke_command "dpkg-buildpackage -rfakeroot -d -b -us -uc 1>/dev/null" "Building binary package" || \
2927
die 7 $"There was a problem creating your ${create_type}."
2929
echo $"DKMS: mk${create_type} Completed."
2930
invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_all.deb' '$deb_basedir'" "Moving built files to $deb_basedir"
2933
popd > /dev/null 2>&1
2935
if in_temporary_trees; then
2936
echo "Copying built files to "`pwd`"/.." >&2
2937
cp "${deb_basedir}/"* ..
2941
invoke_command "rm $temp_dir -fr" "Cleaning up temporary files"
2942
delete_temporary_trees || \
2943
die 7 $"There was a problem cleaning up temporary files."
2948
local create_type=$1
2949
# Error if $module_version is set but $module is not
2950
check_module_args $create_type
2952
# Check that source symlink works
2955
# Make sure that its installed in the first place
2956
[[ -d $dkms_tree/$module/$module_version ]] ||
2957
die 3 $"The module/version combo: $module-$module_version" \
2958
$"is not located in the DKMS tree."
2963
local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
2964
trap 'rm -rf $temp_dir_name' EXIT HUP TERM
2965
mkdir -p $temp_dir_name/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
2966
pushd "$dkms_tree/$module/$module_version" > /dev/null 2>&1
2967
# want to change name of the top-level of the tarball
2968
# from build to $module-$module_version
2969
cp -lr build ${module}-${module_version}
2970
tar cvjf $temp_dir_name/SOURCES/${module}-${module_version}.tar.bz2 ${module}-${module_version} > /dev/null 2>&1
2971
rm -rf ${module}-${module_version}
2972
popd > /dev/null 2>&1
2973
pushd "$temp_dir_name" > /dev/null 2>&1
2974
invoke_command "rpmbuild --define \"_topdir ${temp_dir_name}\" --target=$arch -bs ${SPECFILE} > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
2975
grep ^Wrote $temp_dir_name/rpmbuild.log > /dev/null 2>&1
2977
if ((RC == 0)); then
2978
local kmp_basedir="$dkms_tree/$module/$module_version/rpm"
2979
mkdir -p $kmp_basedir
2980
RPMS=$(LANG=C cp -va ${temp_dir_name}/SRPMS/* $kmp_basedir | awk '{print $NF}')
2982
echo $"rpmbuild error log:"
2983
cat $temp_dir_name/rpmbuild.log
2985
popd > /dev/null 2>&1
2986
rm -rf $temp_dir_name
2987
trap > /dev/null 2>&1
2991
report_build_problem()
2993
#If apport is on the system, files a build problem
2994
if [ -x /usr/share/apport/apport ] && which python>/dev/null; then
2995
python /usr/share/apport/package-hooks/dkms_packages.py -m $module -v $module_version -k ${kernelver[0]}
3000
# Little helper function for reading args from the commandline.
3001
# it automatically handles -a b and -a=b variants, and returns 1 if
3002
# we need to shift $3.
3006
# $3 = arg parameter
3007
local rematch='^[^=]*=(.*)$'
3008
if [[ $2 =~ $rematch ]]; then
3009
read "$1" <<< "${BASH_REMATCH[1]}"
3012
# There is no way to shift our callers args, so
3013
# return 1 to indicate they should do it instead.
3018
# A couple of helper functions for parsing out our most common arguments.
3019
# This one allows you to pass -k kernel.version-extra/arch instead of
3020
# -k kernel-version.extra -a arch.
3021
# This makes it harder to pass mismatching numbers of kernel/arch pairs, because
3022
# they are all passed at the same time.
3024
if [[ $1 =~ $mv_re ]]; then
3025
kernelver[${#kernelver[@]}]="${BASH_REMATCH[1]}"
3026
arch[${#arch[@]}]="${BASH_REMATCH[2]}"
3028
kernelver[${#kernelver[@]}]="$1"
3032
# This allows you to pass module and module_version information on the commandline
3033
# in a more convienent form. Instead of the mostly mandatory and annoying
3034
# -m module -v module_version, you can use either -m module/module_version,
3035
# or just a raw module/module_version with no -m parameter.
3036
# This vastly improves readability and discoverability of
3037
# commands on the commandline.
3038
parse_moduleversion(){
3039
if [[ $1 =~ $mv_re ]]; then
3040
module="${BASH_REMATCH[1]}"
3041
module_version="${BASH_REMATCH[2]}"
3048
((UID == 0)) && return
3049
die 1 $"You must be root to use this command."
3052
# Add a passed source tree to the default source location.
3053
# We will check the dkms.conf file to make sure it is valid
3056
local from=$(readlink -f $1)
3057
if ! [[ $from && -f $from/dkms.conf ]]; then
3058
die 9 $"$1 must contain a dkms.conf file!"
3061
setup_kernels_arches
3062
if ! get_pkginfo_from_conf "$from/dkms.conf" ; then
3063
die 10 $"Malformed dkms.conf file. Cannot load source tree."
3065
module="$PACKAGE_NAME"
3066
module_version="$PACKAGE_VERSION"
3067
if [[ $force && -d $source_tree/$module-$module_version ]]; then
3069
echo $"Forcing install of $module-$module_version"
3070
rm -rf "$source_tree/$module-$module_version"
3073
# We are already installed, just return.
3075
"$source_tree/$module-$module_version") return;;
3076
"$dkms_tree/$module/$version/source") return;;
3077
"$dkms_tree/$module/$version/build") return;;
3079
mkdir -p "$source_tree/$module-$module_version"
3080
cp -fr "$from"/* "$source_tree/$module-$module_version"
3085
make_common_test "mkkmp"
3087
# Read the conf file
3088
read_conf_or_die "$kernelver" "$arch"
3091
if [[ $specfile && -e $dkms_tree/$module/$module_version/source/$specfile ]]; then
3092
echo $"Using $dkms_tree/$module/$module_version/source/$specfile"
3093
SPECFILE="$dkms_tree/$module/$module_version/source/$specfile"
3094
elif [[ -e $dkms_tree/$module/$module_version/source/$module-kmp.spec ]]; then
3095
echo $"Using $dkms_tree/$module/$module_version/source/$module-kmp.spec"
3096
SPECFILE="$dkms_tree/$module/$module_version/source/$module-kmp.spec"
3098
die 5 $"Cannot find a suitable spec file which is needed by" \
3099
$"DKMS in order use mkkmp. Please specify --spec=specfile."
3107
if ((RC == 0)); then
3109
echo $"KMP SRPM location: $RPMS"
3111
echo $"DKMS: mkkmp Completed."
3113
die 7 $"There was a problem creating your KMP source rpm."
3115
# FIXME: hand SRPM to mock or build system to build
3118
# This code used to be in dkms_autoinstaller.
3119
# Moving it into the main dkms script gets rid of a fair amount of duplicate
3120
# functionality, and makes it much easier to reinstall DKMS kernel modules
3121
# by hand if dkms_autoinstaller is not used.
3123
local status mv mvka m v k a last_v last_m tenative
3124
local -a to_install=()
3125
# Walk through our list of installed and built modules, and create
3126
# a list of modules that need to be reinstalled.
3127
while read status mvka; do
3128
# if it has not been built, do not try and build it now.
3129
[[ $status = added ]] && continue
3130
IFS='/' read m v k a <<< "$mvka"
3131
[[ ! $last_m ]] && last_m="$m"
3132
# If the module is already installed or weak-installed, skip it.
3133
_is_module_installed "$m" "$v" "$kernelver" "$arch" && continue
3134
module_status_weak "$m" "$v" "$kernelver" "$arch" >/dev/null && continue
3135
# if the module does not want to be autoinstalled, skip it.
3136
read_conf_or_die "$k" "$a" "$dkms_tree/$m/$v/source/dkms.conf"
3137
if [[ ! $AUTOINSTALL ]]; then
3139
# otherwise, only autoinstall the latest version we have hanging around.
3140
elif [[ $last_m != $m ]]; then
3143
[[ $tenative ]] && to_install[${#to_install[@]}]="$tenative"
3145
elif [[ $last_m = $m && ($(VER $v) > $(VER $last_v)) ]]; then
3149
done < <(module_status)
3150
# We may have exited the loop with $tenative set. If it is,
3151
# it contains something that should be updated.
3152
[[ $tenative ]] && to_install[${#to_install[@]}]="$tenative"
3153
[[ $to_install ]] || return 0
3154
# Install modules that need to be updated in parallel.
3155
for mv in "${to_install[@]}"; do
3156
IFS=/ read m v <<< "$mv"
3157
(module="$m"; module_version="$v"; install_module) &
3162
function make_redhat3_driver_disk ()
3164
# Check that the rpmbuild command is present
3165
if ! which rpmbuild >/dev/null 2>&1 ; then
3167
echo $"Error! rpmbuild not present." >&2
3168
echo $"Install the rpm-build package." >&2
3172
local kmodtool=$(rpm -ql redhat-rpm-config | grep kmodtool)
3173
#Check that the kmodtool is present
3174
if [ -z "$kmodtool" ]; then
3175
echo $"Error! kmodtool not present." >&2
3176
echo $"Install redhat-rpm-config package." >&2
3180
# Check that the createrepo command is present
3181
if ! which createrepo >/dev/null 2>&1 ; then
3183
echo $"Error! createrepo not present." >&2
3184
echo $"Install the createrepo package." >&2
3189
if [ -n "$specfile" -a -e "$dkms_tree/$module/$module_version/source/$specfile" ]; then
3190
echo $"Using $dkms_tree/$module/$module_version/source/$specfile"
3191
SPECFILE="$dkms_tree/$module/$module_version/source/$specfile"
3192
elif [ -e "/etc/dkms/template-dkms-redhat-kmod.spec" ]; then
3193
echo $"Using /etc/dkms/template-dkms-redhat-kmod.spec"
3194
SPECFILE="/etc/dkms/template-dkms-redhat-kmod.spec"
3197
echo $"Cannot find /etc/dkms/template-dkms-redhat-kmod.spec which is needed by" >&2
3198
echo $"DKMS in order to make Redhat driver disk v3." >&2
3201
# Set up temporary build directory for build
3202
rm -rf "$dkms_tree/$module/$module_version/build"
3203
cp -rf "$dkms_tree/$module/$module_version/source/" "$dkms_tree/$module/$module_version/build"
3205
cd "$dkms_tree/$module/$module_version/build"
3207
# Run the pre_build script
3208
if [ -n "$pre_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_build" | sed 's/ .*//'` ]; then
3210
echo $"Running the pre_build script:"
3211
$dkms_tree/$module/$module_version/build/$pre_build
3216
while [ $index -lt ${#patch_array[@]} ]; do
3217
if ! [ -e "$dkms_tree/$module/$module_version/build/patches/${patch_array[$index]}" ]; then
3219
echo $"Error! Patch ${patch_array[$index]} as specified in dkms.conf cannot be" >&2
3220
echo $"found in $dkms_tree/$module/$module_version/build/patches/." >&2
3223
invoke_command "patch -p1 < ./patches/${patch_array[$index]}" "applying patch ${patch_array[$index]}"
3224
if [ "$?" -ne 0 ]; then
3226
echo $"Error! Application of patch ${patch_array[$index]} failed." >&2
3227
echo $"Check $dkms_tree/$module/$module_version/build/ for more information." >&2
3228
report_build_problem
3233
# Create temp dirs and copy files for build
3234
local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
3235
trap 'rm -rf $temp_dir_name' EXIT HUP TERM
3236
mkdir -p ${temp_dir_name}/{disk,BUILD,RPMS,SRPMS,SPECS,SOURCES}
3237
cp ${SPECFILE} ${temp_dir_name}/SPECS/$module.spec
3238
cp -rax $dkms_tree/$module/$module_version/build/ $temp_dir_name/SOURCES/$module-$module_version/
3239
# Clean the build directory
3240
rm -rf "$dkms_tree/$module/$module_version/build/*"
3241
cd $temp_dir_name/SOURCES
3242
invoke_command "tar -jcvf $temp_dir_name/SOURCES/$module-$module_version.tar.bz2 $module-$module_version/" "creating source tarball"
3245
while [ $i -lt ${#kernelver[@]} ]; do
3246
invoke_command "LC_ALL=C rpmbuild --define \"_topdir ${temp_dir_name}\" --define \"version $module_version\" --define \"module_name $module\" --define \"kernel_version ${kernelver[$i]}\" -bb --target ${arch[$i]} ${temp_dir_name}/SPECS/$module.spec > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
3247
if [ "$?" -ne 0 ]; then
3249
echo $"Error! There was a problem creating your kmod." >&2
3250
cat ${temp_dir_name}/rpmbuild.log >&2
3253
local kabi_whitelist=`rpm -ql kabi-whitelists | grep ${arch[$i]}`
3254
if [ $kabi_whitelist ]; then
3255
local module_file=`rpm -qlp ${temp_dir_name}/RPMS/${arch[$i]}/kmod-${module}-${module_version}* | grep ${module}.ko`
3256
cd ${temp_dir_name}/
3257
rpm2cpio ${temp_dir_name}/RPMS/${arch[$i]}/kmod-${module}-${module_version}* | cpio -id --quiet .${module_file}
3259
local mod_symbols=( $(modprobe --dump-modversions ${temp_dir_name}/${module_file} | cut -f2) )
3260
local miss_sym_count=0
3261
local missing_symbols
3262
for ((i=0; i < "${#mod_symbols[@]}"; i++))
3264
if [ -z "`grep -o ${mod_symbols[${i}]} ${kabi_whitelist}`" ]; then
3265
missing_symbols[$miss_sym_count]="${mod_symbols[${i}]}"
3266
miss_sym_count=$(($miss_sym_count+1))
3269
if [ $miss_sym_count -ne 0 ]; then
3271
echo $"WARNING: ${module}-${module_version} is using following kernel symbols that are not in the ABI whitelist:"
3272
echo $"----------------------------------"
3273
for missing_symbol in ${missing_symbols[*]}
3275
echo "$missing_symbol"
3277
echo $"----------------------------------"
3280
echo $"NOTICE: ${module}-${module_version} module seems to use only official Red Hat ABI."
3283
echo $"WARNING:${module}-${module_version} module is not checked against Red Hat ABI whitelist."
3284
echo $"Install 'kabi-whitelists' package and build driver disk again to run the ABI compliance test."
3290
while [ $i -lt ${#arch[@]} ]; do
3291
invoke_command "createrepo --pretty ${temp_dir_name}/RPMS/${arch[$i]}" "creating repo"
3292
if [ "$?" -ne 0 ]; then
3294
echo $"Error! There was a problem creating repository." >&2
3300
echo "$module-$module_version driver disk" > "${temp_dir_name}/disk/rhdd3"
3301
mkdir ${temp_dir_name}/disk/rpms
3302
cp -rax ${temp_dir_name}/RPMS/* ${temp_dir_name}/disk/rpms/
3304
local suffix="$(driver_disk_suffix)"
3305
local image_dir="$dkms_tree/$module/$module_version/driver_disk"
3306
local image_name="$module-$module_version-dd.$suffix"
3308
echo $"Creating driver disk on $media media:"
3309
cd "${temp_dir_name}/disk"
3310
mkdir -p "$image_dir"
3311
rm -f "$image_dir/$image_name"
3312
make_driver_disk_media "$image_dir/$image_name" "${temp_dir_name}/disk"
3313
rm -rf $temp_dir_name
3316
echo $"Disk image location: $image_dir/$image_name"
3318
echo $"DKMS: mkdriverdisk Completed."
3320
trap > /dev/null 2>&1
3323
#############################
3325
#### Program Starts Here ####
3327
#############################
3329
# Set a standard path
3330
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/lib/dkms"
3332
# Ensure files and directories we create are readable to anyone,
3333
# since we aim to build as a non-root user
3336
# Unset environment variables that may interfere with the build
3337
unset CC CXX CFLAGS CXXFLAGS LDFLAGS
3339
# Set important variables
3340
current_kernel=$(uname -r)
3341
current_os=$(uname -s)
3342
dkms_tree="/var/lib/dkms"
3343
source_tree="/usr/src"
3344
install_tree="/lib/modules"
3345
tmp_location=${TMPDIR:-/tmp}
3347
dkms_frameworkconf="/etc/dkms/framework.conf"
3349
# these can come from the environment or the config file
3350
[[ ! ${ADDON_MODULES_DIR} && -e /etc/sysconfig/module-init-tools ]] && . /etc/sysconfig/module-init-tools
3351
addon_modules_dir="${ADDON_MODULES_DIR}"
3352
[[ ! ${addon_modules_dir} ]] && running_distribution="$(distro_version)"
3353
weak_modules="${WEAK_MODULES_BIN}"
3355
# Source in /etc/dkms_framework.conf
3356
[ -e $dkms_frameworkconf ] && . $dkms_frameworkconf 2>/dev/null
3358
# Clear out command line argument variables
3368
kernel_source_dir=""
3369
ksourcedir_fromcli=""
3372
no_prepare_kernel=""
3382
declare -a directive_array=() kernelver=() arch=()
3388
[ -x /sbin/weak-modules ] && weak_modules='/sbin/weak-modules'
3389
[ -x /usr/lib/module-init-tools/weak-modules ] && weak_modules='/usr/lib/module-init-tools/weak-modules'
3391
action_re='^(remove|(auto|un)?install|match|mk(driverdisk|tarball|rpm|deb|dsc|kmp)|build|add|status|ldtarball)$'
3393
# Parse command line arguments
3394
while (($# > 0)); do
3396
--dkmsframework*) read_arg dkms_frameworkconf "$1" "$2" || shift
3397
#immediately load this config
3398
. $dkms_frameworkconf 2> /dev/null;;
3399
--module*|-m) read_arg _mv "$1" "$2" || shift
3400
parse_moduleversion "$_mv";;
3401
-v) read_arg module_version "$1" "$2" || shift;;
3402
--kernelver*|-k) read_arg _ka "$1" "$2" || shift
3403
parse_kernelarch "$_ka";;
3404
--distro*|-d) read_arg distro "$1" "$2" || shift;;
3405
--media*) read_arg media "$1" "$2" ||shift;;
3406
--release*|-r) read_arg release "$1" "$2" || shift;;
3407
--templatekernel*) read_arg template_kernel "$1" "$2" || shift;;
3408
-c) read_arg conf "$1" "$2" || shift;;
3409
--quiet|-q) exec >/dev/null 2>&1;;
3410
--version|-V) echo $"dkms: 2.2.0.1"
3412
--no-prepare-kernel) no_prepare_kernel="no-prepare-kernel";;
3413
--no-clean-kernel) no_clean_kernel="no-clean-kernel";;
3414
--no-initrd) no_initrd="no-initrd";;
3415
--binaries-only) binaries_only="binaries-only";;
3416
--source-only) source_only="source-only";;
3417
--force) force="true";;
3419
--verbose) verbose="true";;
3420
--rpm_safe_upgrade) rpm_safe_upgrade="true";;
3421
--dkmstree*) read_arg dkms_tree "$1" "$2" || shift;;
3422
--sourcetree*) read_arg source_tree "$1" "$2" || shift;;
3423
--installtree*) read_arg install_tree "$1" "$2" || shift;;
3424
--config*) read_arg kernel_config "$1" "$2" || shift;;
3425
--archive*) read_arg archive_location "$1" "$2" || shift;;
3426
--legacy-postinst*) read_arg legacy_postinst "$1" "$2" || shift;;
3427
--arch*|-a) read_arg _aa "$1" "$2" || shift
3428
arch[${#arch[@]}]="$_aa";;
3429
--size*) read_arg size "$1" "$2" || shift;;
3430
--kernelsourcedir*) read_arg kernel_source_dir "$1" "$2" || shift
3431
ksourcedir_fromcli="true";;
3432
--directive*) read_arg _da "$1" "$2" || shift
3433
directive_array[${#directive_array[@]}]="$_da";;
3434
--spec*) read_arg specfile "$1" "$2" || shift;;
3436
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
3438
-*|--*) error $" Unknown option: $1"
3441
*) if [[ $1 =~ $action_re ]]; then
3442
action="$action $1" # Add actions to the action list
3443
elif [[ -f $1 && $1 = *dkms.conf ]]; then
3444
try_source_tree="${1%dkms.conf}./" # Flag as a source tree
3445
elif [[ -d $1 && -f $1/dkms.conf ]]; then
3446
try_source_tree="$1" # ditto
3447
elif [[ -f $1 ]]; then
3448
archive_location="$1" # It is a file, assume it is an archive.
3449
elif [[ ! $module ]]; then
3450
parse_moduleversion "$1" # Assume it is a module/version pair.
3452
warn $"I do not know how to handle $1."
3460
# Error out if binaries-only is set and source-only is set
3461
if [[ $binaries_only && $source_only ]]; then
3462
die 8 $" You have specified both --binaries-only and --source-only." \
3463
$"You cannot do this."
3466
# Error if # of arches doesn't match # of kernels
3467
if (( ${#kernelver[@]} != ${#arch[@]} && \
3468
${#arch[@]} > 1 )); then
3469
die 1 $" If more than one arch is specified on the command line, then there" \
3470
$"must be an equal number of kernel versions also specified (1:1 relationship)."
3473
# Check that kernel version and all aren't both set simultaneously
3474
if [[ $kernelver && $all ]]; then
3475
die 2 $" You cannot specify a kernel version and also specify" \
3476
$"--all on the command line."
3479
# Check that arch and all aren't both set simultaneously
3480
if [[ $arch && $all ]]; then
3481
die 3 $" You cannot specify an arch and also specify" \
3482
$"--all on the command line."
3485
# Run the specified action
3486
for action_to_run in $action; do
3487
setup_kernels_arches "$action_to_run"
3488
case "$action_to_run" in
3489
remove) check_root && remove_module;;
3490
install) check_root && install_modules;;
3491
autoinstall) check_root && autoinstall;;
3492
match) check_root && have_one_kernel && run_match;;
3493
uninstall) check_root && have_one_kernel && uninstall_module;;
3494
mkdriverdisk) check_root && make_driver_disk;;
3495
build) build_modules;;
3497
mktarball) make_tarball;;
3499
mkdeb) make_debian "deb";;
3500
mkdsc) make_debian "dsc";;
3501
mkkmp) have_one_kernel && make_kmp;;
3502
status) show_status;;
3503
ldtarball) # Make sure they're root if we're using --force
3504
if ((UID != 0)) && [[ $force = true ]]; then
3505
die 1 $"You must be root to use this command with the --force option."
3507
load_tarball && add_module;;
3508
'') error $"No action was specified."
3510
*) error $"Unknown action specified: $action_to_run"