Overview

Request 326 (accepted)

update to 2.2.0.3

Submit package home:etamPL:branc...0:branches:Extra / dkms to package Extra / dkms

dkms.changes Changed
x
 
1
@@ -1,4 +1,14 @@
2
 -------------------------------------------------------------------
3
+Thu Dec 15 17:18:08 CET 2011 - ximi_obs@hotmail.com - 2.2.0.3
4
+
5
+- updated to 2.2.0.3
6
+
7
+-------------------------------------------------------------------
8
+Tue Nov  1 16:53:14 CET 2011 - ximi_obs@hotmail.com - 2.2.0.2
9
+
10
+- updated to 2.2.0.2
11
+
12
+-------------------------------------------------------------------
13
 Sat Oct  9 15:27:10 UTC 2010 - packman@links2linux.de - 2.1.1.2
14
 
15
 - moved to packman repository
16
dkms.spec Changed
138
 
1
@@ -1,35 +1,44 @@
2
 #
3
-# spec file for package dkms (Version 2.1.1.2)
4
+# spec file for package dkms
5
 #
6
 # norootforbuild
7
 #
8
 
9
-Summary:   Dynamic Kernel Module Support Framework
10
-Name:      dkms
11
-Version:   2.1.1.2
12
-Release:   0
13
-License:   GPLv2+
14
-Group:     System/Kernel
15
-BuildArch: noarch
16
-Requires:  sed gawk findutils modutils tar cpio gzip grep mktemp
17
-Requires:  bash > 1.99 
18
-URL:       http://linux.dell.com/dkms
19
-Source0:   http://linux.dell.com/dkms/permalink/dkms-%{version}.tar.bz2
20
-Source100: %{name}.changes
21
-Source101: %{name}.rpmlintrc
22
-Patch0:        %{name}-add_remote_fs_to_init_script.diff
23
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
24
-%if 0%{?suse_version} <= 1100
25
-PreReq:        coreutils /bin/sed /usr/bin/grep 
26
+Summary:   Dynamic Kernel Module Support Framework
27
+Name:      dkms
28
+Version:   2.2.0.3
29
+Release:   0.1
30
+License:   GPLv2+
31
+Group:     System/Kernel
32
+BuildArch: noarch
33
+Requires:  sed gawk findutils modutils tar cpio gzip grep mktemp
34
+Requires:  bash > 1.99
35
+# because Mandriva calls this package dkms-minimal
36
+Provides:  dkms-minimal = %{version}
37
+URL:       http://linux.dell.com/dkms
38
+Source0:   http://linux.dell.com/dkms/permalink/dkms-%{version}.tar.bz2
39
+Source100: %{name}.changes
40
+Source101: %{name}.rpmlintrc
41
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
42
+%if 0%{?suse_version}
43
+Patch0:    %{name}-compat_suse_init_script.diff
44
+Requires:  kernel-devel
45
+%endif
46
+%if 0%{?fedora}
47
+Requires:  kernel-devel
48
 %endif
49
 
50
 %description
51
-This package contains the framework for the Dynamic Kernel Module Support (DKMS) method 
52
-for installing modules (or module packages as RPMs/DEBs/etc.) as originally developed by Dell.
53
+This package contains the framework for the Dynamic
54
+Kernel Module Support (DKMS) method for installing
55
+module RPMS as originally developed by Dell.
56
 
57
 %prep
58
 %setup -q
59
-%patch0 -p0
60
+%if 0%{?suse_version}
61
+%patch0 -p1
62
+%endif
63
+
64
 
65
 %build
66
 
67
@@ -89,8 +98,15 @@
68
     BASHDIR=$RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d \
69
     LIBDIR=$RPM_BUILD_ROOT%{_prefix}/lib/%{name}
70
 
71
+%if 0%{?suse_version}
72
 # create rcdkms_autoinstaller symlink for openSUSE
73
-ln -sf /etc/init.d/dkms_autoinstaller $RPM_BUILD_ROOT/usr/sbin/rcdkms_autoinstaller 
74
+%if 0%{?suse_version} < 1130
75
+%define    _initddir   /etc/init.d
76
+%endif
77
+mkdir -p $RPM_BUILD_ROOT/%{_initddir}
78
+mv $RPM_BUILD_ROOT/etc/rc.d/init.d/dkms_autoinstaller $RPM_BUILD_ROOT/%{_initddir}/dkms_autoinstaller 
79
+ln -sf %{_initddir}/dkms_autoinstaller $RPM_BUILD_ROOT/usr/sbin/rcdkms_autoinstaller 
80
+%endif
81
 
82
 %clean
83
 rm -rf $RPM_BUILD_ROOT
84
@@ -98,36 +114,43 @@
85
 %files
86
 %defattr(-,root,root)
87
 %{_sbindir}/%{name}
88
+%if 0%{?suse_version}
89
 %{_sbindir}/rcdkms_autoinstaller
90
+%endif
91
 %{_localstatedir}/lib/%{name}
92
-%{_sysconfdir}/init.d/dkms_autoinstaller
93
 %{_prefix}/lib/%{name}
94
 %{_mandir}/*/*
95
 %config(noreplace) %{_sysconfdir}/%{name}
96
 %doc sample.spec sample.conf AUTHORS COPYING README.dkms
97
 %doc sample-suse-9-mkkmp.spec sample-suse-10-mkkmp.spec
98
 # these dirs are for plugins - owned by other packages
99
-%dir %{_sysconfdir}/kernel
100
-%dir %{_sysconfdir}/kernel/postinst.d
101
-%dir %{_sysconfdir}/kernel/prerm.d
102
+%{_initddir}/dkms_autoinstaller
103
 %{_sysconfdir}/kernel/postinst.d/%{name}
104
 %{_sysconfdir}/kernel/prerm.d/%{name}
105
 %config %{_sysconfdir}/bash_completion.d/%{name}
106
-%dir %{_datadir}/apport/
107
-%dir %{_datadir}/apport/package-hooks/
108
-%{_datadir}/apport/package-hooks/dkms.py
109
+
110
+%if 0%{?suse_version}
111
+# suse doesnt yet support /etc/kernel/{prerm.d,postinst.d}, but will fail build
112
+# with unowned dirs if we dont own them ourselves
113
+# when opensuse *does* add this support, we will need to BuildRequires kernel
114
+%dir %{_sysconfdir}/kernel
115
+%dir %{_sysconfdir}/kernel/postinst.d
116
+%dir %{_sysconfdir}/kernel/prerm.d
117
+%endif
118
+
119
 
120
 %post
121
 [ -e /sbin/dkms ] && mv -f /sbin/dkms /sbin/dkms.old 2>/dev/null
122
 # enable on initial install
123
 [ $1 -lt 2 ] && /sbin/chkconfig dkms_autoinstaller on ||:
124
 
125
+%postun
126
+%insserv_cleanup
127
+%restart_on_update
128
+
129
 %preun
130
 # remove on uninstall
131
 [ $1 -lt 1 ] && /sbin/chkconfig dkms_autoinstaller off ||:
132
 %stop_on_removal
133
 
134
-%postun
135
-%insserv_cleanup
136
-
137
 %changelog
138
dkms-add_remote_fs_to_init_script.diff Deleted
13
 
1
@@ -1,11 +0,0 @@
2
---- dkms_autoinstaller.orig    2009-12-14 18:18:55.000000000 +0100
3
-+++ dkms_autoinstaller 2009-12-28 12:32:52.000000000 +0100
4
-@@ -9,7 +9,7 @@
5
- # Provides: dkms_autoinstaller dkms
6
- # Default-Start: 2 3 4 5
7
- # Default-Stop:
8
--# Required-Start: $local_fs
9
-+# Required-Start: $local_fs $remote_fs
10
- # Required-Stop: $null
11
- # Short-Description: Automatically install DKMS modules for new kernels
12
- # Description: A service to automatically install DKMS modules for new kernels.
13
dkms-compat_suse_init_script.diff Added
17
 
1
@@ -0,0 +1,15 @@
2
+diff -urN dkms-2.2.0.2.orig/dkms_autoinstaller dkms-2.2.0.2/dkms_autoinstaller
3
+--- dkms-2.2.0.2.orig/dkms_autoinstaller   2011-07-22 01:06:55.000000000 +0200
4
++++ dkms-2.2.0.2/dkms_autoinstaller    2011-11-30 10:14:26.227796621 +0100
5
+@@ -7,9 +7,9 @@
6
+ #
7
+ ### BEGIN INIT INFO
8
+ # Provides: dkms_autoinstaller dkms
9
+-# Default-Start: 2 3 4 5
10
++# Default-Start: 2 3 5
11
+ # Default-Stop:
12
+-# Required-Start: $local_fs
13
++# Required-Start: $local_fs $remote_fs
14
+ # Required-Stop: $null
15
+ # Short-Description: Automatically install DKMS modules for new kernels
16
+ # Description: A service to automatically install DKMS modules for new kernels.
17
dkms-2.1.1.2.tar.bz2/AUTHORS -> dkms-2.2.0.3.tar.bz2/AUTHORS Changed
9
 
1
@@ -20,3 +20,6 @@
2
 
3
 Mike Morgan <Michael_Morgan@dell.com>
4
 - Debian / Ubuntu targeting
5
+
6
+Victor Lowther <Victor_Lowther@dell.com>
7
+- Full bashification and code cleanup
8
\ No newline at end of file
9
dkms-2.1.1.2.tar.bz2/Makefile -> dkms-2.2.0.3.tar.bz2/Makefile Changed
85
 
1
@@ -1,8 +1,8 @@
2
-RELEASE_DATE := "16-Feb-2009"
3
+RELEASE_DATE := "07-December-2011"
4
 RELEASE_MAJOR := 2
5
-RELEASE_MINOR := 1
6
-RELEASE_SUBLEVEL := 1
7
-RELEASE_EXTRALEVEL := .2
8
+RELEASE_MINOR := 2
9
+RELEASE_SUBLEVEL := 0
10
+RELEASE_EXTRALEVEL := .3
11
 RELEASE_NAME := dkms
12
 RELEASE_VERSION := $(RELEASE_MAJOR).$(RELEASE_MINOR).$(RELEASE_SUBLEVEL)$(RELEASE_EXTRALEVEL)
13
 RELEASE_STRING := $(RELEASE_NAME)-$(RELEASE_VERSION)
14
@@ -14,6 +14,7 @@
15
 VAR = $(DESTDIR)/var/lib/dkms
16
 MAN = $(DESTDIR)/usr/share/man/man8
17
 INITD = $(DESTDIR)/etc/init.d
18
+INITD_RH = $(DESTDIR)/etc/rc.d/init.d 
19
 LIBDIR = $(DESTDIR)/usr/lib/dkms
20
 BASHDIR = $(DESTDIR)/etc/bash_completion.d
21
 KCONF = $(DESTDIR)/etc/kernel
22
@@ -35,11 +36,9 @@
23
    mkdir -m 0755 -p $(VAR) $(SBIN) $(MAN) $(ETC) $(BASHDIR) $(SHAREDIR) $(LIBDIR)
24
    sed -e "s/\[INSERT_VERSION_HERE\]/$(RELEASE_VERSION)/" dkms > dkms.versioned
25
    mv -f dkms.versioned dkms
26
-   mkdir   -p -m 0755 $(SHAREDIR)/apport/package-hooks
27
    install -p -m 0755 dkms_common.postinst $(LIBDIR)/common.postinst
28
    install -p -m 0755 dkms $(SBIN)
29
    install -p -m 0755 dkms_autoinstaller $(LIBDIR)
30
-   install -p -m 0755 dkms_apport.py $(SHAREDIR)/apport/package-hooks/dkms.py
31
    install -p -m 0644 dkms_framework.conf $(ETC)/framework.conf
32
    install -p -m 0644 dkms_dbversion $(VAR)
33
    install -p -m 0644 dkms.bash-completion $(BASHDIR)/dkms
34
@@ -58,18 +57,21 @@
35
    chmod 0644 $(DOCFILES)
36
 
37
 install-redhat: install doc-perms
38
-   mkdir -m 0755 -p  $(INITD)
39
+   mkdir -m 0755 -p  $(INITD_RH)
40
    install -p -m 0755 dkms_mkkerneldoth $(LIBDIR)/mkkerneldoth
41
    install -p -m 0755 dkms_find-provides $(LIBDIR)/find-provides
42
    install -p -m 0755 lsb_release $(LIBDIR)/lsb_release
43
    install -p -m 0644 template-dkms-mkrpm.spec $(ETC)
44
-   install -p -m 0755 dkms_autoinstaller $(INITD)
45
+   install -p -m 0644 template-dkms-redhat-kmod.spec $(ETC)
46
+   install -p -m 0755 dkms_autoinstaller $(INITD_RH)
47
 
48
 install-doc:
49
    mkdir -m 0755 -p $(DOCDIR)
50
    install -p -m 0644 $(DOCFILES) $(DOCDIR)
51
 
52
 install-debian: install install-doc
53
+   mkdir   -p -m 0755 $(SHAREDIR)/apport/package-hooks
54
+   install -p -m 0755 dkms_apport.py $(SHAREDIR)/apport/package-hooks/dkms_packages.py
55
    mkdir   -p -m 0755 $(KCONF)/header_postinst.d
56
    install -p -m 0755 kernel_postinst.d_dkms $(KCONF)/header_postinst.d/dkms
57
    mkdir   -p -m 0755 $(ETC)/template-dkms-mkdeb/debian
58
@@ -88,7 +90,7 @@
59
 
60
 $(TARBALL):
61
    mkdir -p $(deb_destdir)
62
-   tmp_dir=`mktemp -d /tmp/dkms.XXXXXXXX` ; \
63
+   tmp_dir=`mktemp -d --tmpdir dkms.XXXXXXXX` ; \
64
    cp -a ../$(RELEASE_NAME) $${tmp_dir}/$(RELEASE_STRING) ; \
65
    sed -e "s/\[INSERT_VERSION_HERE\]/$(RELEASE_VERSION)/" dkms > $${tmp_dir}/$(RELEASE_STRING)/dkms ; \
66
    sed -e "s/\[INSERT_VERSION_HERE\]/$(RELEASE_VERSION)/" dkms.spec > $${tmp_dir}/$(RELEASE_STRING)/dkms.spec ; \
67
@@ -105,7 +107,7 @@
68
 
69
 
70
 rpm: $(TARBALL) dkms.spec
71
-   tmp_dir=`mktemp -d /tmp/dkms.XXXXXXXX` ; \
72
+   tmp_dir=`mktemp -d --tmpdir dkms.XXXXXXXX` ; \
73
    mkdir -p $${tmp_dir}/{BUILD,RPMS,SRPMS,SPECS,SOURCES} ; \
74
    cp $(TARBALL) $${tmp_dir}/SOURCES ; \
75
    sed "s/\[INSERT_VERSION_HERE\]/$(RELEASE_VERSION)/" dkms.spec > $${tmp_dir}/SPECS/dkms.spec ; \
76
@@ -129,7 +131,7 @@
77
    cd -
78
 
79
 debs:
80
-   tmp_dir=`mktemp -d /tmp/dkms.XXXXXXXX` ; \
81
+   tmp_dir=`mktemp -d --tmpdir dkms.XXXXXXXX` ; \
82
    make debmagic DEB_TMP_BUILDDIR=$${tmp_dir} DIST=$(DIST); \
83
    rm -rf $${tmp_dir}
84
 
85
dkms-2.1.1.2.tar.bz2/README.dkms -> dkms-2.2.0.3.tar.bz2/README.dkms Changed
19
 
1
@@ -73,7 +73,7 @@
2
 In order to load any tarball into the DKMS tree, you must use the following
3
 command:
4
 
5
-   dkms ldtarball --archive=/path/to/dkms_enabled.tar.gz
6
+   dkms ldtarball /path/to/dkms_enabled.tar.gz
7
 
8
 This command will first inspect the tarball to ensure that it contains a
9
 dkms.conf configuration file for that module.  If it cannot find this file
10
@@ -111,7 +111,7 @@
11
 If your system does not have module source, loading the dkms tarball will fail
12
 because of this.  To avoid this, use the --force flag, as such:
13
 
14
-   dkms ldtarball --archive=/path/to/dkms_enabled.tar.gz --force
15
+   dkms ldtarball /path/to/dkms_enabled.tar.gz --force
16
 
17
 This will load the pre-built binaries into the dkms tree, and create the
18
 directory /usr/src/<module>-<moduleversion>/ which will only contain the
19
dkms-2.1.1.2.tar.bz2/dkms -> dkms-2.2.0.3.tar.bz2/dkms Changed
6413
 
1
@@ -19,54 +19,116 @@
2
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3
 #
4
 
5
-function invoke_command ()
6
+
7
+# All of the variables we will accept from dkms.conf.
8
+# Does not include directives
9
+readonly dkms_conf_variables="CLEAN REMAKE_INITRD remake_initrd PACKAGE_NAME
10
+       PACKAGE_VERSION POST_ADD POST_INSTALL POST_REMOVE PRE_BUILD
11
+       PRE_INSTALL BUILD_EXCLUSIVE_KERNEL BUILD_EXCLUSIVE_ARCH
12
+       build_exclude OBSOLETE_BY MAKE MAKE_MATCH MODULES_CONF
13
+       modules_conf_array PATCH PATCH_MATCH patch_array BUILT_MODULE_NAME
14
+       built_module_name BUILT_MODULE_LOCATION built_module_location
15
+       DEST_MODULE_NAME dest_module_name MODULES_CONF_OBSOLETES
16
+       DEST_MODULE_LOCATION dest_module_location
17
+       modules_conf_obsoletes MODULES_CONF_ALIAS_TYPE
18
+       modules_conf_alias_type STRIP strip MODULES_CONF_OBSOLETE_ONLY
19
+       modules_conf_obsolete_only AUTOINSTALL"
20
+
21
+# Some important regular expressions.  Requires bash 3 or above.
22
+# Any poor souls still running bash 2 or older really need an upgrade.
23
+readonly y_re='^(Y|y)'
24
+readonly mv_re='^([^/]*)/(.*)$'
25
+readonly rh_kernels='(debug|summit|smp|enterprise|bigmem|hugemem|BOOT|vmnix)'
26
+
27
+#Areas that will vary between Linux and other OS's
28
+_get_kernel_dir() {
29
+    KVER=$1
30
+    case ${current_os} in
31
+       Linux)          DIR="/lib/modules/$KVER/build" ;;
32
+       GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
33
+    esac
34
+    echo $DIR
35
+}
36
+
37
+_check_kernel_dir() {
38
+    DIR=$(_get_kernel_dir $1)
39
+    case ${current_os} in
40
+       Linux)          test -e $DIR/include ;;
41
+       GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
42
+       *)              return 1 ;;
43
+    esac
44
+    return $?
45
+}
46
+
47
+# Run a command that we may or may not want to be detailed about.
48
+invoke_command()
49
 {
50
+    # $1 = command to be executed using eval.
51
+    # $2 = Description of command to run
52
+    # $3 = 'background' if you want to run the command asynchronously.
53
     local exitval=0
54
-    local exitval_file=`mktemp $tmp_location/dkms.XXXXXX`
55
-    [ -z "$verbose" ] && echo -en "$2..." || echo -e "$1"
56
-    if [ "$3" == background ] && [ -z "$verbose" ]; then
57
-        (eval $1 >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
58
-        while [ -e "$exitval_file" ] && ! [ -s "$exitval_file" ]; do
59
-            sleep 3
60
-            echo -en "."
61
-        done
62
-        . "$exitval_file"
63
+    [[ $verbose ]] && echo -e "$1" || echo -en "$2..."
64
+    if [[ $3 = background && ! $verbose ]]; then
65
+   local exitval_file=$(mktemp_or_die $tmp_location/dkms.XXXXXX)
66
+   (eval "$1" >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
67
+   while [[ -e $exitval_file && ! -s $exitval_file ]]; do
68
+       sleep 3
69
+       echo -en "."
70
+   done
71
+   . "$exitval_file"
72
+   rm -f "$exitval_file"
73
     else
74
-        eval $1; exitval=$?
75
+   eval "$1"; exitval=$?
76
     fi
77
-    [ $exitval -gt 0 ] && echo -en "(bad exit status: $exitval)"
78
-    rm -f "$exitval_file"
79
+    (($exitval > 0)) && echo -en "(bad exit status: $exitval)"
80
     echo -en "\n"
81
     return $exitval
82
 }
83
 
84
-function show_usage ()
85
+error() (
86
+    exec >&2
87
+    echo -n $"Error! "
88
+    for s in "$@"; do echo "$s"; done 
89
+)
90
+
91
+warn() (
92
+    exec >&2
93
+    echo -n "$Warning: "
94
+    for s in "$@"; do echo "$s"; done
95
+)
96
+
97
+# Print an error message and die with the passed error code.
98
+die() {
99
+    # $1 = error code to return with
100
+    # rest = strings to print before we exit.
101
+    ret=$1
102
+    shift
103
+    error "$@"
104
+    [[ $die_is_fatal = yes ]] && exit $ret || return $ret
105
+}
106
+
107
+mktemp_or_die() {
108
+    local t
109
+    t=$(mktemp "$@") && echo "$t" && return
110
+    [[ $* = *-d* ]] && die 1 $"Unable to make temporary directory"
111
+    die 1 "Unable to make temporary file."
112
+}
113
+
114
+show_usage()
115
 {
116
     echo $"Usage: $0 [action] [options]"
117
-    echo $"  [action]  = { add | remove | build | install | uninstall | match"
118
+    echo $"  [action]  = { add | remove | build | install | uninstall | match | autoinstall"
119
     echo $"               | mkdriverdisk | mktarball | ldtarball | mkrpm | mkkmp | mkdeb | status }"
120
     echo $"  [options] = [-m module] [-v module-version] [-k kernel-version] [-a arch]"
121
     echo $"              [-d distro] [-c dkms.conf-location] [-q] [--force] [--all]"
122
     echo $"              [--templatekernel=kernel] [--directive='cli-directive=cli-value']"
123
     echo $"              [--config=kernel-.config-location] [--archive=tarball-location]"
124
-    echo $"              [--kernelsourcedir=source-location] [--no-prepare-kernel]"
125
+    echo $"              [--kernelsourcedir=source-location] [--no-prepare-kernel] [--no-initrd]"
126
     echo $"              [--binaries-only] [--source-only] [-r release (SuSE)] [--verbose]"
127
     echo $"              [--size] [--spec=specfile] [--media=floppy|iso|tar] [--legacy-postinst=0|1]"
128
 }
129
 
130
-function readlink()
131
-{
132
-    # $1 = the symlink to read
133
-    read_link=""
134
-    if [ -L "$1" ]; then
135
-        read_link="$1"
136
-        while [ -L "$read_link" ]; do
137
-            read_link=`ls -l $read_link | sed 's/.*-> //'`
138
-        done
139
-    fi
140
-}
141
-
142
-function VER()
143
+VER()
144
 {
145
     # $1 = kernel version string
146
 
147
@@ -75,446 +137,351 @@
148
     # The result should compare correctly as a string.
149
 
150
     echo $1 | sed -e 's:\([^0-9]\)\([0-9]\):\1 \2:g' \
151
-                  -e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
152
-                  -e 's:\(.*\): \1 :' \
153
-                  -e 's: \([0-9]\) : 00\1 :g' \
154
-                  -e 's: \([0-9][0-9]\) : 0\1 :g' \
155
-                  -e 's: ::g'
156
+         -e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
157
+         -e 's:\(.*\): \1 :' \
158
+         -e 's: \([0-9]\) : 00\1 :g' \
159
+         -e 's: \([0-9][0-9]\) : 0\1 :g' \
160
+         -e 's: ::g'
161
 }
162
 
163
-function set_module_suffix ()
164
+# Figure out the correct module suffix for the kernel we are currently
165
+# dealing with, which may or may not be the currently installed kernel.
166
+set_module_suffix()
167
 {
168
     # $1 = the kernel to base the module_suffix on
169
-    kernel_test="$1"
170
-    [ -z "$kernel_test" ] && kernel_test=`uname -r`
171
-
172
-    if [[ $(VER $kernel_test) < $(VER 2.5) ]]; then
173
-        module_suffix=".o"
174
-    else
175
-        module_suffix=".ko"
176
-    fi
177
+    kernel_test="${1-:$(uname -r)}"
178
+    module_suffix=".ko"
179
+    [[ $(VER $kernel_test) < $(VER 2.5) ]] && module_suffix=".o"
180
 }
181
 
182
-function set_kernel_source_dir ()
183
+set_kernel_source_dir()
184
 {
185
     # $1 = the kernel to base the directory on
186
-    if [ -z "$kernel_source_dir" ] && [ -d "$install_tree/$1/build" ]; then
187
-        kernel_source_dir="$install_tree/$1/build"
188
-    fi
189
+    kernel_source_dir="$(_get_kernel_dir "$1")"
190
 }
191
 
192
-function setup_kernels_arches ()
193
+# A little test function for DKMS commands that only work on one kernel.
194
+have_one_kernel() {
195
+    (( ${#kernelver[@]} > 1 )) && \
196
+   die 4 $"The action $1 does not support multiple kernel version" \
197
+   $"parameters on the command line."
198
+    [[ $all ]] && die 5 $"The action $1 does not support the --all" \
199
+   $"parameter."
200
+}
201
+
202
+# Set up the kernelver and arch arrays.  You must have a 1:1 correspondence --
203
+# if there is an entry in kernelver[$i], there must also be an entry in arch[$i]
204
+# Note the special casing for the status action -- the status functions just
205
+# report on what we already have, and will break with the preprocessing that
206
+# this function provides.
207
+setup_kernels_arches()
208
 {
209
-    # Error if # of arches doesn't match # of kernels
210
-    if [ ${#kernelver_array[@]} -ne ${#arch_array[@]} ] && [ ${#arch_array[@]} -gt 1 ]; then
211
-        echo $"" >&2
212
-        echo $"Error!  If more than one arch is specified on the command line, then there" >&2
213
-        echo $"must be an equal number of kernel versions also specified (1:1 relationship)." >&2
214
-        exit 1
215
-    fi
216
-
217
-    # Check that kernel version and all aren't both set simultaneously
218
-    if [ -n "${kernelver_array[0]}" ] && [ -n "$all" ]; then
219
-        echo $"" >&2
220
-        echo $"Error!  You cannot specify a kernel version and also specify" >&2
221
-        echo $"--all on the command line." >&2
222
-        exit 2
223
-    fi
224
-
225
-    # Check that arch and all aren't both set simultaneously
226
-    if [ -n "${arch_array[0]}" ] && [ -n "$all" ]; then
227
-        echo $"" >&2
228
-        echo $"Error!  You cannot specify an arch and also specify" >&2
229
-        echo $"--all on the command line." >&2
230
-        exit 3
231
-    fi
232
-
233
-    # Check that the actions supports multiple kernels
234
-    case "$1" in
235
-    add | build | install | match | uninstall | mkkmp )
236
-        if [ ${#kernelver_array[@]} -gt 1 ]; then
237
-            echo $"" >&2
238
-            echo $"Error! The action $1 does not support multiple kernel version" >&2
239
-            echo $"parameters on the command line." >&2
240
-            exit 4
241
-        fi
242
-        if [ -n "$all" ]; then
243
-            echo $"" >&2
244
-            echo $"Error! The action $1 does not support the --all" >&2
245
-            echo $"parameter." >&2
246
-            exit 5
247
-        fi
248
-        ;;
249
-    esac
250
-
251
     # If all is set, use dkms status to fill the arrays
252
-    if [ -n "$all" ] && [ "$1" != "status" ]; then
253
-        local i=0
254
-        while read line; do
255
-            # (I would leave out the delimiters in the status output
256
-            #  in the first place.)
257
-            kernelver_array[$i]=`echo $line | awk {'print $3'} | sed 's/,$//'`
258
-            arch_array[$i]=`echo $line | awk {'print $4'} | sed 's/:$//'`
259
-            i=$(($i + 1))
260
-        done < <($0 status -m "$module" -v "$module_version" 2>/dev/null | \
261
-            egrep "built|installed" | egrep -v 'installed-weak')
262
+    if [[ $all && $1 != status ]]; then
263
+   local i=0
264
+   while read line; do
265
+       line=${line#*/}; line=${line#*/};
266
+       # (I would leave out the delimiters in the status output
267
+       #  in the first place.)
268
+       kernelver[$i]=${line%/*}
269
+       arch[$i]=${line#*/}
270
+       i=$(($i + 1))
271
+   done < <(module_status_built "$module" "$module_version")
272
     fi
273
 
274
     # Set default kernel version and arch, if none set (but only --all isn't set)
275
-    if [ "$1" != "status" ]; then
276
-        [ -z "${kernelver_array[0]}" ] && [ -z "$all" ] && kernelver_array[0]=`uname -r`
277
-        if [ -z "${arch_array[0]}" ] && [ -n "${kernelver_array[0]}" ]; then
278
-            kernelver_rpm=`rpm -qf "/lib/modules/${kernelver_array[0]}" 2>/dev/null | grep -v "not owned by any package" | grep kernel | head -n 1`
279
-            if ! arch_array[0]=`rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null`; then
280
-                arch_array[0]=`uname -m`
281
-                if [ ${arch_array[0]} == "x86_64" ] && \
282
-                    grep -q Intel /proc/cpuinfo && \
283
-                    ls $install_tree/${kernelver_array[0]}/build/configs \
284
-                    2>/dev/null | grep -q "ia32e"; then
285
-                    arch_array[0]="ia32e"
286
-                fi
287
-            fi
288
-        fi
289
+    if [[ $1 != status ]]; then
290
+   if [[ ! $kernelver && ! $all ]]; then
291
+       kernelver[0]=$(uname -r)
292
+       kernels_arches_default="yes"
293
+   fi
294
+   if [[ ! $arch ]]; then
295
+       kernelver_rpm=$(rpm -qf "/lib/modules/$kernelver" 2>/dev/null | \
296
+       grep -v "not owned by any package" | grep kernel | head -n 1)
297
+       if ! arch[0]=$(rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null); then
298
+       arch[0]=$(uname -m)
299
+       if [[ $arch = x86_64 ]] && \
300
+           grep -q Intel /proc/cpuinfo && \
301
+           ls $install_tree/$kernelver/build/configs \
302
+           2>/dev/null | grep -q "ia32e"; then
303
+           arch[0]="ia32e"
304
+       fi
305
+       fi
306
+   fi
307
     fi
308
 
309
     # If only one arch is specified, make it so for all the kernels
310
-    if [ ${#arch_array[@]} -eq 1 ] && [ ${#kernelver_array[@]} -gt 1 ]; then
311
-        while [ ${#arch_array[@]} -lt ${#kernelver_array[@]} ]; do
312
-            arch_array[${#arch_array[@]}]=${arch_array[0]}
313
-        done
314
+    if ((${#arch[@]} == 1 && ${#kernelver[@]} > 1)); then
315
+   while ((${#arch[@]} < ${#kernelver[@]})); do
316
+       arch[${#arch[@]}]=$arch
317
+   done
318
     fi
319
 
320
     # Set global multi_arch
321
     multi_arch=""
322
     local i=0
323
-    while [ $i -lt ${#arch_array[@]} ]; do
324
-        [ "${arch_array[0]}" != "${arch_array[$i]}" ] && multi_arch="true"
325
-        i=$(($i + 1))
326
+    for ((i=0; $i < ${#arch[@]}; i++)); do
327
+   [[ $arch != ${arch[$i]} ]] && {
328
+       multi_arch="true"
329
+       break
330
+   }
331
     done
332
 }
333
 
334
-function do_depmod()
335
-{
336
-    # $1 = kernel version
337
-    /sbin/depmod -au "$1" -F "/boot/System.map-$1"
338
-}
339
-
340
-function remake_initrd()
341
+do_depmod()
342
 {
343
     # $1 = kernel version
344
-    # $2 = arch
345
-
346
-    local exitval="0"
347
-    local mkinitrd='mkinitrd'
348
-
349
-
350
-    # Support initramfs distributions (Debian/Ubuntu).
351
-    if [ -x "/usr/sbin/update-initramfs" ]; then
352
-        mkinitrd='update-initramfs'
353
+    if [ "${current_os}" != "Linux" ] ; then
354
+        return
355
     fi
356
-
357
-    $mkinitrd --version >/dev/null 2>&1
358
-    if [ "$?" -eq 0 ]; then
359
-        echo $""
360
-        initrd_dir="/boot"
361
-        [ "$2" == "ia64" ] && [ -d "/boot/efi/efi/redhat" ] && initrd_dir="/boot/efi/efi/redhat"
362
-        echo $"Saving old initrd as $initrd_dir/initrd-$1_old.img"
363
-        cp -f "$initrd_dir/initrd-$1.img" "$initrd_dir/initrd-$1_old.img"
364
-        echo $"Making new initrd as $initrd_dir/initrd-$1.img"
365
-        echo $"(If next boot fails, revert to the _old initrd image)"
366
-        invoke_command "$mkinitrd -f $initrd_dir/initrd-$1.img $1" "$mkinitrd" background
367
-        exitval="$?"
368
-    elif [ -e /etc/SuSE-release ] || [ -d /etc/SuSEconfig ]; then
369
-        echo $""
370
-        initrd_dir="/boot"
371
-        kernel_file="vmlinuz"
372
-        if [ ! -f "$initrd_dir/$kernel_file-$1" ]; then
373
-            kernel_file="vmlinux"
374
-            if [ ! -f "$initrd_dir/$kernel_file-$1" ]; then
375
-                echo $"Error! Unable to find valid kernel file under " >&2
376
-                echo $"$initrd_dir for kernel version $1" >&2
377
-                echo $"" >&2
378
-                return 1;
379
-            fi
380
-        fi
381
-        echo $"Saving old initrd as $initrd_dir/initrd-$1_old"
382
-        cp -f "$initrd_dir/initrd-$1" "$initrd_dir/initrd-$1_old"
383
-        echo $"Making new initrd as $initrd_dir/initrd-$1"
384
-        echo $"(If next boot fails, revert to the _old initrd image)"
385
-        invoke_command "$mkinitrd -k $kernel_file-$1 -i initrd-$1" "$mkinitrd" background
386
-        exitval="$?"
387
-    elif [ -e /etc/debian_version ]; then
388
-        echo $""
389
-        initrd_dir="/boot"
390
-        echo $"Updating initrd"
391
-        echo $"Making new initrd as $initrd_dir/initrd.img-$1"
392
-        echo $"(If next boot fails, revert to the .bak initrd image)"
393
-        if [ "$mkinitrd" == "update-initramfs" ]; then
394
-            invoke_command "$mkinitrd -u" "$mkinitrd" background
395
-        else
396
-            echo $"Saving old initrd as $initrd_dir/initrd.img-$1.bak"
397
-            # we use the same convention as update-initramfs, so that we just
398
-            # print the warning once
399
-            cp -f "$initrd_dir/initrd.img-$1" "$initrd_dir/initrd.img-$1.bak"
400
-            invoke_command "$mkinitrd -o $initrd_dir/initrd.img-$1 $1" "$mkinitrd" background
401
-        fi
402
-        exitval="$?"
403
+    if [[ -f /boot/System.map-$1 ]]; then
404
+   /sbin/depmod -a "$1" -F "/boot/System.map-$1"
405
     else
406
-        echo $""
407
-        echo $"Calling $mkinitrd (bad exit status 9 may occur)"
408
-        invoke_command "$mkinitrd" "$mkinitrd" background
409
-        exitval="$?"
410
+   /sbin/depmod -a "$1"
411
     fi
412
-
413
-    return $exitval
414
 }
415
 
416
-function distro_version_rpm()
417
+# This function is a little hairy -- every distro has slightly different tools
418
+# and naming conventions for creating initial ramdisks.  It should probably
419
+# be split out into one function per distro, with make_initrd left as a stub.
420
+make_initrd()
421
 {
422
-    local whatprovides_redhat
423
-    local whatprovides_suse
424
-    local whatprovides_sles
425
-    local whatprovides_ovm
426
-    local DISTRO
427
-    local VER
428
-    local dist=unknown
429
-
430
-    if ! which rpm > /dev/null 2>&1 ; then
431
-        echo "${dist}"
432
-        return
433
-    fi
434
-
435
-    whatprovides_redhat=$(rpm -q --whatprovides redhat-release)
436
-    if [ $? -eq 0 ]; then
437
-        case "${whatprovides_redhat}" in
438
-        redhat*)     DISTRO=redhat ;;
439
-        centos*)     DISTRO=centos ;;
440
-        enterprise*) DISTRO=oel ;; # Oracle Enterprise Linux
441
-        sl*)         DISTRO=sl ;;  # Scientific Linux
442
-        fedora*)     DISTRO=fedora ;;
443
-        *) ;;
444
-        esac
445
-    fi
446
-    whatprovides_sles=$(rpm -q --whatprovides sles-release)
447
-    [ $? -eq 0 ] && DISTRO=sles
448
-    whatprovides_suse=$(rpm -q --whatprovides suse-release)
449
-    [ $? -eq 0 ] && DISTRO=suse
450
-    whatprovides_ovm=$(rpm -q --whatprovides ovs-release)
451
-    [ $? -eq 0 ] && DISTRO=ovm
452
-
453
-    case "${DISTRO}" in
454
-    redhat)
455
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
456
-        # format is 3AS, 4AS, 5Desktop...
457
-        VER=$(echo "${VER}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
458
-        dist=el${VER}
459
-        ;;
460
-    centos)
461
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
462
-        # format is 3, 4, ...
463
-        dist=el${VER}
464
-        ;;
465
-    oel)
466
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
467
-        # format is 3, 4, ...
468
-        dist=el${VER}
469
-        ;;
470
-    ovm)
471
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_ovm})
472
-        # format is 2.1
473
-        dist=ovm${VER}
474
-        ;;
475
-    sl)
476
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
477
-        # format is 4.7, 5.3
478
-        VER=$(echo "${VER}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
479
-        dist=el${VER}
480
-        ;;
481
-    fedora)
482
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_redhat})
483
-        dist=fc${VER}
484
-        ;;
485
-    sles)
486
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_sles})
487
-        dist=sles${VER}
488
-        ;;
489
-    suse)
490
-        VER=$(rpm -q --qf "%{version}\n" ${whatprovides_suse})
491
-        dist=suse${VER}
492
-        ;;
493
-    *)
494
-        dist=unknown
495
-        ;;
496
-    esac
497
-    echo "$dist"
498
-}
499
-
500
-function distro_version()
501
+    # $1 = kernel version
502
+    # $2 = arch
503
+    [[ $no_initrd ]] && return
504
+    local mkinitrd kernel_file initrd_dir="/boot"
505
+    for mkinitrd in dracut update-initramfs mkinitrd ''; do
506
+   [[ $mkinitrd ]] && which "$mkinitrd" >/dev/null 2>&1 && break
507
+    done
508
+
509
+    # no mkinitrd? Just return.
510
+    [[ $mkinitrd ]] || return 0
511
+
512
+    # back up our current initrd
513
+    echo $""
514
+    [[ $2 = ia64 && -d /boot/efi/efi/redhat ]] && initrd_dir="/boot/efi/efi/redhat"
515
+    # find out what the proper filename will be
516
+    for initrd in "initrd-$1.img" "initramfs-$1.img" "initrd.img-$1" "initrd-$1" ''; do
517
+   [[ $initrd && -f $initrd_dir/$initrd ]] && break
518
+    done
519
+    if ! [[ $initrd ]]; then
520
+   # Return if we cannot find an initrd.
521
+   warn $"Unable to find an initial ram disk that I know how to handle." \
522
+       $"Will not try to make an initrd."
523
+   return 0
524
+    fi
525
+    echo $"Backing up $initrd to $initrd_dir/$initrd.old-dkms"
526
+    cp -f "$initrd_dir/$initrd" "$initrd_dir/$initrd.old-dkms"
527
+    echo $"Making new $initrd"
528
+    echo $"(If next boot fails, revert to $initrd.old-dkms image)"
529
+
530
+    if [[ $mkinitrd = dracut ]]; then
531
+   invoke_command "$mkinitrd $1" "$mkinitrd" background
532
+    elif [[ $mkinitrd = update-initramfs ]]; then
533
+   invoke_command "$mkinitrd -u" "$mkinitrd" background
534
+    elif $mkinitrd --version >/dev/null 2>&1; then
535
+   invoke_command "$mkinitrd -f $initrd_dir/$initrd $1" "$mkinitrd" background
536
+    elif [[ -e /etc/SuSE-release || -d /etc/SuSEconfig ]]; then
537
+   for kernel_file in vmlinuz vmlinux ''; do
538
+       [[ $kernel_file && -f $initrd_dir/$kernel_file ]] && break
539
+   done
540
+   if [[ ! $kernel_file ]]; then
541
+       error $"Unable to find valid kernel file under " \
542
+       $"$initrd_dir for kernel version $1" 
543
+       return 1;
544
+   fi
545
+   invoke_command "$mkinitrd -k $kernel_file-$1 -i $initrd" "$mkinitrd" background
546
+    elif [[ -e /etc/debian_version ]]; then
547
+   invoke_command "$mkinitrd -o $initrd_dir/$initrd $1" "$mkinitrd" background
548
+    else
549
+   echo $""
550
+   echo $"Calling $mkinitrd (bad exit status 9 may occur)"
551
+   invoke_command "$mkinitrd" "$mkinitrd" background
552
+    fi
553
+    return
554
+}
555
+
556
+# Grab our distro information from RPM-based distros.
557
+distro_version_rpm()
558
+{
559
+    which rpm > /dev/null 2>&1 || { echo unknown; return; }
560
+    local r wp ver dist
561
+
562
+    for r in redhat-release sles-release suse-release ovs-release; do
563
+   wp=$(rpm -q --whatprovides "$r") || continue
564
+   ver=$(rpm -q --qf "%{version}\n" ${wp})
565
+   case $r in
566
+       sles*) echo sles${ver};;
567
+       suse*) echo suse${ver};;
568
+       ovs*)  echo ovm${ver};;
569
+       redhat*)
570
+       case $wp in
571
+           redhat*|sl*)
572
+           ver=$(echo $ver | \
573
+           sed -e 's/^\([[:digit:]]*\).*/\1/g')
574
+           echo el${ver};;
575
+           centos*|enterprise*) echo el${ver};;
576
+           fedora*) echo fc${ver};;
577
+           *) echo unknown ;;
578
+       esac
579
+          ;;
580
+       *) echo unknown;;
581
+   esac
582
+   return
583
+    done
584
+    echo unknown
585
+}
586
+
587
+# Grab distro information from LSB compliant distros.
588
+# Falls back to distro_version_rpm if needed.
589
+distro_version()
590
 {
591
-# What distribution are we running?
592
-    local LSB_RELEASE
593
-    local LSB_DESCRIPTION
594
-    local DISTRIB_ID
595
-    local DISTRIB_RELEASE
596
-    local VER
597
-    local dist=unknown
598
+    # What distribution are we running?
599
+    local LSB_DESCRIPTION DISTRIB_ID DISTRIB_RELEASE ver
600
 
601
-# try the LSB-provided strings first
602
+    # try the LSB-provided strings first
603
     if [ -r /etc/lsb-release ]; then
604
-        . /etc/lsb-release
605
-        LSB_RELEASE=1
606
+   . /etc/lsb-release
607
     elif type lsb_release >/dev/null 2>&1; then
608
-        DISTRIB_ID=$(lsb_release -i -s)
609
-        DISTRIB_RELEASE=$(lsb_release -r -s)
610
-        LSB_RELEASE=1
611
-    fi
612
-
613
-    case "${DISTRIB_ID}" in
614
-    Fedora)     dist=fc${DISTRIB_RELEASE} ;;
615
-    RedHatEnterprise*)  # OEL also reports as such
616
-        # format is 4.7, 5.3
617
-        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
618
-        dist=el${VER}
619
-        ;;
620
-    CentOS)
621
-        # format is 4.7, 5.3
622
-        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
623
-        dist=el${VER}
624
-        ;;
625
-    ScientificSL)
626
-        # format is 4.7, 5.3
627
-        VER=$(echo "${DISTRIB_RELEASE}" | sed -e 's/^\([[:digit:]]*\).*/\1/g')
628
-        dist=el${VER}
629
-        ;;
630
-    SUSE*)
631
-        LSB_DESCRIPTION="$(lsb_release -d -s)"
632
-        if echo "${LSB_DESCRIPTION}" | grep Enterprise > /dev/null 2>&1; then
633
-            dist=sles${DISTRIB_RELEASE}
634
-        else
635
-            dist=suse${DISTRIB_RELEASE}
636
-        fi
637
-        ;;
638
-    *)
639
-        if [ -n "${LSB_RELEASE}" -a -n "${DISTRIB_ID}" -a -n "${DISTRIB_RELEASE}" ]; then
640
-            dist="${DISTRIB_ID}${DISTRIB_RELEASE}"
641
-        fi
642
-        ;;
643
-    esac
644
-
645
-    if [ "${dist}" == "unknown" ]; then
646
-        dist=$(distro_version_rpm)
647
+   DISTRIB_ID=$(lsb_release -i -s)
648
+   DISTRIB_RELEASE=$(lsb_release -r -s)
649
     fi
650
-    echo "$dist"
651
+
652
+    case ${DISTRIB_ID} in
653
+   Fedora)     echo fc${DISTRIB_RELEASE} ;;
654
+   RedHatEnterprise*|CentOS|ScientificSL)  # OEL also reports as such
655
+   # format is 4.7, 5.3
656
+       ver=$(echo "${DISTRIB_RELEASE}" | \
657
+       sed -e 's/^\([[:digit:]]*\).*/\1/g')
658
+       echo el${ver}
659
+       ;;
660
+   SUSE*)
661
+       if [[ $(lsb_release -d -s) =~ Enterprise ]]; then
662
+       echo sles${DISTRIB_RELEASE}
663
+       else
664
+       echo suse${DISTRIB_RELEASE}
665
+       fi
666
+       ;;
667
+   *)
668
+       if [[ ${DISTRIB_ID} && ${DISTRIB_RELEASE} ]]; then
669
+       echo "${DISTRIB_ID}${DISTRIB_RELEASE}"
670
+       else
671
+       distro_version_rpm
672
+       fi
673
+       ;;
674
+    esac
675
 }
676
 
677
-function override_dest_module_location()
678
+override_dest_module_location()
679
 {
680
     local orig_location="$1"
681
-    [ -n "${addon_modules_dir}" ] && echo "/${addon_modules_dir}" && return
682
+    [[ ${addon_modules_dir} ]] && echo "/${addon_modules_dir}" && return
683
+
684
+    if [ "$current_os" = "GNU/kFreeBSD" ] ; then
685
+   # Does not support subdirs, regardless of distribution
686
+   echo "" && return
687
+    fi
688
 
689
     case "$running_distribution" in
690
-    fc[12345]) ;;
691
-    el[1234]) ;;
692
-    sles[123456789]) ;;
693
-    suse[123456789]) ;;
694
-    suse10\.[01]) ;;
695
-    fc*) echo "/extra" && return ;;
696
-    el*) echo "/extra" && return ;;
697
-    ovm*) echo "/extra" && return ;;
698
-    sles*) echo "/updates" && return ;;
699
-    suse*) echo "/updates" && return ;;
700
-    Ubuntu*) echo "/updates/dkms" && return ;;
701
-    Debian*) echo "/updates/dkms" && return ;;
702
-    *) ;;
703
+   fc[12345]) ;;
704
+   el[1234]) ;;
705
+   sles[123456789]) ;;
706
+   suse[123456789]) ;;
707
+   suse10\.[01]) ;;
708
+   fc*) echo "/extra" && return ;;
709
+   el*) echo "/extra" && return ;;
710
+   ovm*) echo "/extra" && return ;;
711
+   sles*) echo "/updates" && return ;;
712
+   suse*) echo "/updates" && return ;;
713
+   Ubuntu*) echo "/updates/dkms" && return ;;
714
+   Debian*) echo "/updates/dkms" && return ;;
715
+   *) ;;
716
     esac
717
     echo "$orig_location"
718
 }
719
 
720
-function read_conf ()
721
+# Source a file safely.
722
+# We want to ensure that the .conf file we source does not stomp all over
723
+# parts of the environment we don't want them to.  This makes it so that
724
+# it is harder to accidentally corrupt our environment.  conf files can
725
+# still deliberatly trash the environment by abusing dkms_directive env
726
+# variables or by crafting special values that will make eval do evil things.
727
+safe_source() {
728
+    # $1 = file to source
729
+    # $@ = environment variables to echo out
730
+    local to_source_file="$1"; shift
731
+    declare -a -r export_envs=("$@")
732
+    local tmpfile=$(mktemp_or_die)
733
+    ( exec >"$tmpfile"
734
+   . "$to_source_file" >/dev/null
735
+   # This is really ugly, but a neat hack
736
+   # Remember, in bash 2.0 and greater all variables are really arrays.
737
+   for _export_env in "${export_envs[@]}"; do
738
+       for _i in $(eval echo \${!$_export_env[@]}); do
739
+       eval echo '$_export_env[$_i]=\"${'$_export_env'[$_i]}\"'
740
+       done
741
+   done
742
+
743
+   # handle DKMS_DIRECTIVE stuff specially.
744
+   for directive in $(set | grep ^DKMS_DIRECTIVE | cut -d = -f 2-3); do
745
+       directive_name=${directive%%=*}
746
+       directive_value=${directive#*=}
747
+       echo "$directive_name=\"$directive_value\""
748
+   done
749
+    )
750
+    . "$tmpfile"
751
+    rm "$tmpfile"
752
+}
753
+
754
+# Source a dkms.conf file and perform appropriate postprocessing on it.
755
+# Do our best to not repeatedly source the same .conf file -- this can happen
756
+# when chaining module installtion functions or autoinstalling.
757
+read_conf()
758
 {
759
     # $1 kernel version (required)
760
     # $2 arch (required)
761
     # $3 dkms.conf location (optional)
762
 
763
     local return_value=0
764
-    local read_conf_file
765
-
766
-    # Find which conf file to check
767
-    if [ -n "$3" ]; then
768
-        read_conf_file="$3"
769
-    elif [ -n "$conf" ]; then
770
-        read_conf_file="$conf"
771
-    else
772
-        read_conf_file="$dkms_tree/$module/$module_version/source/dkms.conf"
773
-    fi
774
-
775
-    # Clear variables
776
-    MAKE=""
777
-    CLEAN=""
778
-    REMAKE_INITRD=""
779
-    remake_initrd=""
780
-    PACKAGE_NAME=""
781
-    PACKAGE_VERSION=""
782
-    POST_ADD=""
783
-    POST_BUILD=""
784
-    POST_INSTALL=""
785
-    POST_REMOVE=""
786
-    PRE_BUILD=""
787
-    PRE_INSTALL=""
788
-    BUILD_EXCLUSIVE_KERNEL=""
789
-    BUILD_EXCLUSIVE_ARCH=""
790
-    build_exclude=""
791
-    OBSOLETE_BY=""
792
-
793
-    # Clear arrays
794
-    unset MAKE
795
-    unset MAKE_MATCH
796
-    unset MODULES_CONF
797
-    unset modules_conf_array
798
-    unset PATCH
799
-    unset PATCH_MATCH
800
-    unset patch_array
801
-    unset BUILT_MODULE_NAME
802
-    unset built_module_name
803
-    unset BUILT_MODULE_LOCATION
804
-    unset built_module_location
805
-    unset DEST_MODULE_NAME
806
-    unset dest_module_name
807
-    unset DEST_MODULE_LOCATION
808
-    unset dest_module_location
809
-    unset MODULES_CONF_OBSOLETES
810
-    unset modules_conf_obsoletes
811
-    unset MODULES_CONF_ALIAS_TYPE
812
-    unset modules_conf_alias_type
813
-    unset MODULES_CONF_OBSOLETE_ONLY
814
-    unset modules_conf_obsolete_only
815
-    unset STRIP
816
-    unset strip
817
+    local read_conf_file="$dkms_tree/$module/$module_version/source/dkms.conf"
818
 
819
     # Set variables supported in dkms.conf files (eg. $kernelver)
820
-    kernelver="$1"
821
-    arch="$2"
822
+    local kernelver="$1"
823
+    local arch="$2"
824
     set_kernel_source_dir "$1"
825
 
826
-    # Source in the dkms.conf
827
-    . $read_conf_file 2>/dev/null
828
 
829
-    # check environment for directives
830
-    # You can't have an array of variables exported
831
-    # so look for DKMS_DIRECTIVE0, DKMS_DIRECTIVE1, ...
832
-    for directive in `set | grep ^DKMS_DIRECTIVE | cut -d = -f 2-3`; do
833
-        directive_name=${directive%%=*}
834
-        directive_value=${directive#*=}
835
-        export $directive_name="$directive_value"
836
-        echo $"DIRECTIVE: $directive_name=\"$directive_value\""
837
+    # Find which conf file to check
838
+    [[ $conf ]] && read_conf_file="$conf"
839
+    [[ $3 ]] && read_conf_file="$3"
840
+
841
+    [[ -r $read_conf_file ]] || die 4 $"Could not locate dkms.conf file." \
842
+   $"File: $conf does not exist."
843
+
844
+    [[ $last_mvka = $module/$module_version/$1/$2 && \
845
+   $last_mvka_conf = $(readlink -f $read_conf_file) ]] && return
846
+
847
+
848
+    # Clear variables and arrays
849
+    for var in $dkms_conf_variables; do
850
+   unset $var
851
+    done
852
+
853
+    # Source in the dkms.conf.
854
+    # Allow for user-specified overrides in order of specificity.
855
+    local _conf_file
856
+    for _conf_file in "$read_conf_file" "/etc/dkms/$module.conf" \
857
+        "/etc/dkms/$module-$module_version.conf" "/etc/dkms/$module-$module_version-$1.conf" \
858
+        "/etc/dkms/$module-$module_version-$1-$2.conf"; do
859
+        [ -e "$_conf_file" ] && safe_source "$_conf_file" $dkms_conf_variables
860
     done
861
 
862
     # Source in the directive_array
863
     for directive in "${directive_array[@]}"; do
864
-        directive_name=${directive%%=*}
865
-        directive_value=${directive#*=}
866
-        export $directive_name="$directive_value"
867
-        echo $"DIRECTIVE: $directive_name=\"$directive_value\""
868
+   directive_name=${directive%%=*}
869
+   directive_value=${directive#*=}
870
+   export $directive_name="$directive_value"
871
+   echo $"DIRECTIVE: $directive_name=\"$directive_value\""
872
     done
873
 
874
     # Set variables
875
@@ -530,342 +497,341 @@
876
     obsolete_by="$OBSOLETE_BY"
877
 
878
     # Set module naming/location arrays
879
-    local index=0
880
-    array_size=`echo -e "${#BUILT_MODULE_NAME[@]}\n${#BUILT_MODULE_LOCATION[@]}\n${#DEST_MODULE_NAME[@]}\n${#DEST_MODULE_LOCATION[@]}\n" | sort -n | tail -n 1`
881
-    while [ "$index" -lt "$array_size" ]; do
882
-        # Set values
883
-        built_module_name[$index]=${BUILT_MODULE_NAME[$index]}
884
-        built_module_location[$index]=${BUILT_MODULE_LOCATION[$index]}
885
-        dest_module_name[$index]=${DEST_MODULE_NAME[$index]}
886
-        dest_module_location[$index]=${DEST_MODULE_LOCATION[$index]}
887
-        modules_conf_obsoletes[$index]=${MODULES_CONF_OBSOLETES[$index]}
888
-        modules_conf_alias_type[$index]=${MODULES_CONF_ALIAS_TYPE[$index]}
889
-        case "${MODULES_CONF_OBSOLETE_ONLY[$index]}" in
890
-        [yY]*)
891
-            modules_conf_obsolete_only[$index]="yes"
892
-            ;;
893
-        esac
894
-        case "${STRIP[$index]}" in
895
-        [nN]*)
896
-            strip[$index]="no"
897
-            ;;
898
-        *)
899
-            strip[$index]="yes"
900
-            ;;
901
-        esac
902
-
903
-        # If unset, set by defaults
904
-        [ -z "${built_module_name[$index]}" ] && [ ${#DEST_MODULE_LOCATION[@]} -eq 1 ] && built_module_name[$index]=$module
905
-        [ -z "${dest_module_name[$index]}" ] && dest_module_name[$index]=${built_module_name[$index]}
906
-        if [ -n "${built_module_location[$index]}" ] && \
907
-           [ "${built_module_location[$index]:(-1)}" != "/" ]; then
908
-            built_module_location[$index]="${built_module_location[$index]}/"
909
-        fi
910
-
911
-        # FAIL if no built_module_name
912
-        if [ -z "${built_module_name[$index]}" ]; then
913
-            echo $"dkms.conf: Error! No 'BUILT_MODULE_NAME' directive specified for record #$index." >&2
914
-            return_value=1
915
-        fi
916
-
917
-        # FAIL if built_module_name ends in .o or .ko
918
-        case "${built_module_name[$index]}" in
919
-        *.o | *.ko)
920
-            echo $"dkms.conf: Error! 'BUILT_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
921
-            return_value=1
922
-            ;;
923
-        esac
924
-
925
-        # FAIL if dest_module_name ends in .o or .ko
926
-        case "${dest_module_name[$index]}" in
927
-        *.o | *.ko)
928
-            echo $"dkms.conf: Error! 'DEST_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
929
-            return_value=1
930
-            ;;
931
-        esac
932
-
933
-        # Override location for specific kernels
934
-        dest_module_location[$index]="$(override_dest_module_location ${dest_module_location[$index]})"
935
-
936
-        # Fail if no DEST_MODULE_LOCATION
937
-        if [ -z "${DEST_MODULE_LOCATION[$index]}" ]; then
938
-            echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified for record #$index.">&2
939
-            return_value=1
940
-        fi
941
-            # Fail if bad DEST_MODULE_LOCATION
942
-        case "${DEST_MODULE_LOCATION[$index]}" in
943
-        /kernel*) ;;
944
-        /updates*) ;;
945
-        /extra*) ;;
946
-        *)
947
-            echo $"dkms.conf: Error! Directive 'DEST_MODULE_LOCATION' does not begin with">&2
948
-            echo $"'/kernel', '/updates', or '/extra' in record #$index.">&2
949
-            return_value=1
950
-            ;;
951
-        esac
952
-
953
-        index=$(($index+1))
954
+    local index array_size=0 s
955
+    for s in ${#BUILT_MODULE_NAME[@]} \
956
+   ${#BUILT_MODULE_LOCATION[@]} \
957
+   ${#DEST_MODULE_NAME[@]} \
958
+   ${#DEST_MODULE_LOCATION[@]}; do
959
+   ((s > array_size)) && array_size=$s
960
+    done
961
+    for ((index=0; index < array_size; index++)); do
962
+   # Set values
963
+   built_module_name[$index]=${BUILT_MODULE_NAME[$index]}
964
+   built_module_location[$index]=${BUILT_MODULE_LOCATION[$index]}
965
+   dest_module_name[$index]=${DEST_MODULE_NAME[$index]}
966
+   dest_module_location[$index]=${DEST_MODULE_LOCATION[$index]}
967
+   modules_conf_obsoletes[$index]=${MODULES_CONF_OBSOLETES[$index]}
968
+   modules_conf_alias_type[$index]=${MODULES_CONF_ALIAS_TYPE[$index]}
969
+   case ${MODULES_CONF_OBSOLETE_ONLY[$index]} in
970
+       [yY]*) modules_conf_obsolete_only[$index]="yes";;
971
+   esac
972
+   case ${STRIP[$index]} in
973
+       [nN]*) strip[$index]="no";;
974
+       *)     strip[$index]="yes";;
975
+   esac
976
+
977
+   # If unset, set by defaults
978
+   [[ ! ${built_module_name[$index]} ]] && \
979
+       ((${#DEST_MODULE_LOCATION[@]} == 1)) && \
980
+       built_module_name[$index]=$module
981
+   [[ ! ${dest_module_name[$index]} ]] && \
982
+       dest_module_name[$index]=${built_module_name[$index]}
983
+   [[ ${built_module_location[$index]} && \
984
+       ${built_module_location[$index]:(-1)} != / ]] && \
985
+       built_module_location[$index]="${built_module_location[$index]}/"
986
+
987
+   # FAIL if no built_module_name
988
+   if [[ ! ${built_module_name[$index]} ]]; then
989
+       echo $"dkms.conf: Error! No 'BUILT_MODULE_NAME' directive specified for record #$index." >&2
990
+       return_value=1
991
+   fi
992
+
993
+   # FAIL if built_module_name ends in .o or .ko
994
+   case ${built_module_name[$index]} in
995
+   *.o|*.ko)
996
+       echo $"dkms.conf: Error! 'BUILT_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
997
+       return_value=1
998
+       ;;
999
+   esac
1000
+
1001
+   # FAIL if dest_module_name ends in .o or .ko
1002
+   case ${dest_module_name[$index]} in
1003
+   *.o|*.ko)
1004
+       echo $"dkms.conf: Error! 'DEST_MODULE_NAME' directive ends in '.o' or '.ko' in record #$index." >&2
1005
+       return_value=1
1006
+       ;;
1007
+   esac
1008
+
1009
+   # Override location for specific kernels
1010
+   dest_module_location[$index]="$(override_dest_module_location ${dest_module_location[$index]})"
1011
+
1012
+   # Fail if no DEST_MODULE_LOCATION
1013
+   if [[ ! ${DEST_MODULE_LOCATION[$index]} ]]; then
1014
+       echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified for record #$index.">&2
1015
+       return_value=1
1016
+   fi
1017
+       # Fail if bad DEST_MODULE_LOCATION
1018
+   case ${DEST_MODULE_LOCATION[$index]} in
1019
+       /kernel*) ;;
1020
+       /updates*) ;;
1021
+       /extra*) ;;
1022
+       *)
1023
+       echo $"dkms.conf: Error! Directive 'DEST_MODULE_LOCATION' does not begin with">&2
1024
+       echo $"'/kernel', '/updates', or '/extra' in record #$index.">&2
1025
+       return_value=1
1026
+       ;;
1027
+   esac
1028
     done
1029
 
1030
     # Get the correct make command
1031
-    index=0
1032
-    [ -z "${MAKE_MATCH[0]}" ] && make_command="${MAKE[0]}"
1033
-    while [ "$index" -lt ${#MAKE[@]} ]; do
1034
-        if [ -n "${MAKE[$index]}" ] && \
1035
-            [ -n "${MAKE_MATCH[$index]}" ] && \
1036
-            echo $1 | egrep -q "${MAKE_MATCH[$index]}"; then
1037
-            make_command="${MAKE[$index]}"
1038
-        fi
1039
-        index=$(($index+1))
1040
+    [[ ${MAKE_MATCH[0]} ]] || make_command="${MAKE[0]}"
1041
+    for ((index=0; index < ${#MAKE[@]}; index++)); do
1042
+   [[ ${MAKE[$index]} && ${MAKE_MATCH[$index]} && \
1043
+       $1 =~ ${MAKE_MATCH[$index]} ]] && \
1044
+       make_command="${MAKE[$index]}"
1045
     done
1046
 
1047
     # Use the generic make and make clean commands if not specified
1048
     if [[ $(VER $1) < $(VER 2.6.6) ]]; then
1049
-        if [ -z "$make_command" ]; then
1050
-            make_command="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build modules"
1051
-        fi
1052
-        if [ -z "$clean" ]; then
1053
-            clean="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build clean"
1054
-        fi
1055
-    else
1056
-        if [ -z "$make_command" ]; then
1057
-            make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
1058
-        fi
1059
-        if [ -z "$clean" ]; then
1060
-            clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
1061
-        fi
1062
+   [[ ! $make_command ]] && \
1063
+       make_command="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build modules"
1064
+   [[ ! $clean ]] && \
1065
+       clean="make -C $kernel_source_dir SUBDIRS=$dkms_tree/$module/$module_version/build clean"
1066
+    else
1067
+   [[ ! $make_command ]] && \
1068
+       make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
1069
+    [[ ! $clean ]] && \
1070
+        clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
1071
     fi
1072
 
1073
     # Set modules_conf_array
1074
-    index=0
1075
-    while [ "$index" -lt ${#MODULES_CONF[@]} ]; do
1076
-        [ -n "${MODULES_CONF[$index]}" ] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
1077
-        index=$(($index+1))
1078
+    for ((index=0; index < ${#MODULES_CONF[@]}; index++)); do
1079
+   [[ ${MODULES_CONF[$index]} ]] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
1080
     done
1081
 
1082
     # Set patch_array (including kernel specific patches)
1083
-    index=0
1084
     count=0
1085
-    while [ "$index" -lt ${#PATCH[@]} ]; do
1086
-        if [ -n "${PATCH[$index]}" ]; then
1087
-            if [ -z "${PATCH_MATCH[$index]}" ] || \
1088
-                echo $1 | egrep -q "${PATCH_MATCH[$index]}"; then
1089
-                patch_array[$count]="${PATCH[$index]}"
1090
-                count=$(($count+1))
1091
-            fi
1092
-        fi
1093
-        index=$(($index+1))
1094
+    for ((index=0; index < ${#PATCH[@]}; index++)); do
1095
+   if [[ ${PATCH[$index]} && (! ${PATCH_MATCH[$index]} || \
1096
+       $1 =~ ${PATCH_MATCH[$index]}) ]]; then
1097
+       patch_array[$count]="${PATCH[$index]}"
1098
+       count=$(($count+1))
1099
+   fi
1100
     done
1101
 
1102
     # Set remake_initrd
1103
-    [ `echo "$REMAKE_INITRD" | grep -ic "^y"` -gt 0 ] && remake_initrd="yes"
1104
+    [[ $REMAKE_INITRD =~ $y_re ]] && remake_initrd="yes"
1105
 
1106
     # Set build_exclude
1107
-    if [ -n "$BUILD_EXCLUSIVE_KERNEL" ]; then
1108
-        echo $1 | egrep -q "$BUILD_EXCLUSIVE_KERNEL" || build_exclude="yes"
1109
-    fi
1110
-    if [ -n "$BUILD_EXCLUSIVE_ARCH" ]; then
1111
-        echo $2 | egrep -q "$BUILD_EXCLUSIVE_ARCH" || build_exclude="yes"
1112
-    fi
1113
+    [[ $BUILD_EXCLUSIVE_KERNEL && ! $1 =~ $BUILD_EXCLUSIVE_KERNEL ]] && \
1114
+       build_exclude="yes"
1115
+    [[ $BUILD_EXCLUSIVE_ARCH && ! $2 =~ $BUILD_EXCLUSIVE_ARCH ]] && \
1116
+   build_exclude="yes"
1117
 
1118
     # Fail if absolutely no DEST_MODULE_LOCATION
1119
-    if [ ${#dest_module_location[@]} -eq 0 ]; then
1120
-        echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified." >&2
1121
-        return_value=1
1122
+    if ((${#dest_module_location[@]} == 0)); then
1123
+   echo $"dkms.conf: Error! No 'DEST_MODULE_LOCATION' directive specified." >&2
1124
+   return_value=1
1125
     fi
1126
 
1127
     # Fail if no PACKAGE_NAME
1128
-    if [ -z "$package_name" ]; then
1129
-        echo $"dkms.conf: Error! No 'PACKAGE_NAME' directive specified.">&2
1130
-        return_value=1
1131
+    if [[ ! $package_name ]]; then
1132
+   echo $"dkms.conf: Error! No 'PACKAGE_NAME' directive specified.">&2
1133
+   return_value=1
1134
     fi
1135
 
1136
     # Fail if no PACKAGE_VERSION
1137
-    if [ -z "$package_version" ]; then
1138
-        echo $"dkms.conf: Error! No 'PACKAGE_VERSION' directive specified.">&2
1139
-        return_value=1
1140
+    if [[ ! $package_version ]]; then
1141
+   echo $"dkms.conf: Error! No 'PACKAGE_VERSION' directive specified.">&2
1142
+   return_value=1
1143
     fi
1144
 
1145
     # Set clean
1146
-    [ -z "$clean" ] && clean="make clean"
1147
+    [[ $clean ]] || clean="make clean"
1148
 
1149
+    ((return_value == 0)) && last_mvka="$module/$module_version/$1/$2" && \
1150
+   last_mvka_conf="$(readlink -f "$read_conf_file")"
1151
     return $return_value
1152
 }
1153
 
1154
+# Little helper function for parsing the output of modinfo.
1155
+get_module_verinfo(){
1156
+    local vals=
1157
+    while read -a vals; do
1158
+   case ${vals[0]} in
1159
+       version:) res[0]=${vals[1]}; res[2]=${vals[2]};;
1160
+       srcversion:) res[1]=${vals[1]};;
1161
+   esac
1162
+    done < <(modinfo $1)
1163
+}
1164
 
1165
-function check_version_sanity ()
1166
+# Perform some module version sanity checking whenever we are installing
1167
+# or removing modules.
1168
+check_version_sanity()
1169
 {
1170
     # $1 = kernel_version
1171
     # $2 = arch
1172
     # $3 = obs by kernel version
1173
     # $4 = dest_module_name
1174
 
1175
-    local lib_tree="$install_tree/$1"
1176
+    local lib_tree="$install_tree/$1" res=
1177
     echo $"Running module version sanity check."
1178
-    local module_count=`find $lib_tree -name ${4}$module_suffix | wc -l | awk {'print $1'}`
1179
-    if [ $module_count -gt 1 ]; then
1180
-        echo $"Warning! Cannot do version sanity checking because multiple ${4}$module_suffix" >&2
1181
-        echo $"modules were found in kernel $1." >&2
1182
-    elif [ $module_count -eq 1 ]; then
1183
-        local kernels_module=`find $lib_tree -name ${4}$module_suffix`
1184
-        local kernels_ver_string=`modinfo $kernels_module | grep "^version:"`
1185
-        local kernels_ver_value=`echo $kernels_ver_string | awk {'print $2'}`
1186
-        local dkms_module="$dkms_tree/$module/$module_version/$1/$2/module/${4}$module_suffix"
1187
-        local dkms_ver_string=`modinfo $dkms_module | grep "^version:"`
1188
-        local dkms_ver_value=`echo $dkms_ver_string | awk {'print $2'}`
1189
-
1190
-        # there are 2 possible srcversion checksums
1191
-        # one in the 'srcversion' tag alone (preferred)
1192
-        # and one following the version field in the 'version' tag (deprecated)
1193
-        local kernels_ver_checksum=`modinfo $kernels_module | awk '/^srcversion:/ {print $2}'`
1194
-        local dkms_ver_checksum=`modinfo $dkms_module | awk '/^srcversion:/ {print $2}'`
1195
-        if [ -z "$kernels_ver_checksum" -a -z "$dkms_ver_checksum" ]; then
1196
-            kernels_ver_checksum=`echo $kernels_ver_string | awk {'print $3'}`
1197
-            dkms_ver_checksum=`echo $dkms_ver_string | awk {'print $3'}`
1198
-        fi
1199
-
1200
-        if [ -n "$kernels_ver_checksum" -a -n "$dkms_ver_checksum" -a \
1201
-            "$kernels_ver_checksum" == "$dkms_ver_checksum" -a -z "$force" ]; then
1202
-            echo $"" >&2
1203
-            echo $"Good news! Module version $dkms_ver_value for ${4}$module_suffix" >&2
1204
-            echo $"exactly matches what is already found in kernel $1." >&2
1205
-            echo $"DKMS will not replace this module." >&2
1206
-            echo $"You may override by specifying --force." >&2
1207
-            return 1
1208
-        fi
1209
-
1210
-        if [ -n "$kernels_ver_value" -a -n "$dkms_ver_value" ]; then
1211
-            if [[ ! ( $(VER $dkms_ver_value) > \
1212
-                      $(VER $kernels_ver_value) ) && -z "$force" ]]; then
1213
-                echo $"" >&2
1214
-                echo $"Error! Module version $dkms_ver_value for ${4}$module_suffix" >&2
1215
-                echo $"is not newer than what is already found in kernel $1 ($kernels_ver_value)." >&2
1216
-                echo $"You may override by specifying --force." >&2
1217
-                return 1
1218
-            fi
1219
-        fi
1220
-
1221
-        local obs_upstream=`echo $3 | cut -d- -f 1`
1222
-        local obs_local=`echo $3 | cut -d- -f 2`
1223
-        local my_upstream=`echo $1 | cut -d- -f 1`
1224
-        local my_local=`echo $1 | cut -d- -f 2`
1225
-        local obsolete=0
1226
-        if [ -n "$obs_upstream" -a -n "$my_upstream" ]; then
1227
-            if [[ ( $(VER $obs_upstream) == $(VER $my_upstream) ) && -z "$force" ]]; then
1228
-            #they get obsoleted possibly in this kernel release
1229
-                if [ -z "$obs_local" ]; then
1230
-                #they were obsoleted in this upstream kernel
1231
-                    obsolete=1
1232
-                elif [[ ( $(VER $my_local) > $(VER $obs_local) ) ]]; then
1233
-                #they were obsoleted in an earlier ABI bump of the kernel
1234
-                    obsolete=1
1235
-                elif [[ ( $(VER $my_local) = $(VER $obs_local) ) ]]; then
1236
-                #they were obsoleted in this ABI bump of the kernel
1237
-                    obsolete=1
1238
-                fi
1239
-            elif [[ ( $(VER $my_upstream) > $(VER $obs_upstream) ) && -z "$force" ]]; then
1240
-            #they were obsoleted in an earlier kernel release
1241
-                obsolete=1
1242
-            fi
1243
-        fi
1244
-
1245
-        if [ "$obsolete" == 1 ]; then
1246
-            echo $"" >&2
1247
-            echo $"Module has been obsoleted due to being included" >&2
1248
-            echo $"in kernel $3.  We will avoid installing" >&2
1249
-            echo $"for future kernels above $3." >&2
1250
-            echo $"You may override by specifying --force." >&2
1251
-            return 1
1252
-        fi
1253
+    local i=0
1254
+    local -a kernels_info dkms_info
1255
+    set_module_suffix
1256
+    read -a kernels_module < <(find $lib_tree -name ${4}$module_suffix)
1257
+    [[ $kernels_module ]] || return 0
1258
+    if [[ ${kernels_module[1]} ]]; then
1259
+   warn $"Warning! Cannot do version sanity checking because multiple ${4}$module_suffix" \
1260
+       $"modules were found in kernel $1."
1261
+   return 0
1262
+    fi
1263
+    local dkms_module="$dkms_tree/$module/$module_version/$1/$2/module/${4}$module_suffix"
1264
+    get_module_verinfo $kernels_module; kernels_info=("${res[@]}")
1265
+    get_module_verinfo $dkms_module; dkms_info=("${res[@]}")
1266
+    if [[ ! ${dkms_info[1]} && ${kernels_info[1]} ]]; then
1267
+   # use obsolete checksum info
1268
+   dkms_info[1]=${dkms_info[2]}
1269
+   kernels_info[1]=${kernels_info[2]}
1270
+    fi
1271
+
1272
+    if [[ ${kernels_info[1]} && ${dkms_info[1]} && \
1273
+   ${kernels_info[1]} = ${dkms_info[1]} && ! $force ]]; then
1274
+   echo $"" >&2
1275
+   echo $"Good news! Module version $dkms_info for ${4}$module_suffix" >&2
1276
+   echo $"exactly matches what is already found in kernel $1." >&2
1277
+   echo $"DKMS will not replace this module." >&2
1278
+   echo $"You may override by specifying --force." >&2
1279
+   return 1
1280
+    fi
1281
+
1282
+    if [[ $kernels_info && $dkms_info && \
1283
+   ! ( $(VER $dkms_info) > $(VER $kernels_info) ) && ! $force ]]; then
1284
+   error $"Module version $dkms_info for ${4}$module_suffix" \
1285
+       $"is not newer than what is already found in kernel $1 ($kernels_info)." \
1286
+       $"You may override by specifying --force."
1287
+   return 1
1288
+    fi
1289
+
1290
+    # magic split into array syntax saves trivial awk and cut calls.
1291
+    local -a obs=(${3//-/ })
1292
+    local -a my=(${1//-/ })
1293
+    local obsolete=0
1294
+    if [[ ${obs} && ${my} ]]; then
1295
+   if [[ $(VER ${obs}) == $(VER ${my}) && ! $force ]]; then
1296
+       #they get obsoleted possibly in this kernel release
1297
+       if [[ ! ${obs[1]} ]]; then
1298
+       #they were obsoleted in this upstream kernel
1299
+       obsolete=1
1300
+       elif [[ $(VER ${my[1]}) > $(VER ${obs[1]}) ]]; then
1301
+       #they were obsoleted in an earlier ABI bump of the kernel
1302
+       obsolete=1
1303
+       elif [[ $(VER ${my[1]}) = $(VER ${obs[1]}) ]]; then
1304
+       #they were obsoleted in this ABI bump of the kernel
1305
+       obsolete=1
1306
+       fi
1307
+   elif [[ $(VER ${my}) > $(VER ${obs}) && ! $force ]]; then
1308
+       #they were obsoleted in an earlier kernel release
1309
+       obsolete=1
1310
+   fi
1311
+    fi
1312
+
1313
+    if ((obsolete == 1)); then
1314
+   echo $"" >&2
1315
+   echo $"Module has been obsoleted due to being included" >&2
1316
+   echo $"in kernel $3.  We will avoid installing" >&2
1317
+   echo $"for future kernels above $3." >&2
1318
+   echo $"You may override by specifying --force." >&2
1319
+   return 1
1320
     fi
1321
     return 0
1322
 }
1323
 
1324
+moduleconfig_update_obsoletes()
1325
+{
1326
+    # $@ = files to process
1327
+    # do nothing if we have no obsoletes
1328
+    [[ ${modules_conf_obsoletes[@]} ]] || return 0
1329
+    # generate sed args to remove obsolete modules
1330
+    local mod_diff
1331
+    for ((index=0; index < ${#dest_module_name[@]}; index++)); do
1332
+   [[ ${modules_conf_obsoletes[$index]} ]] || continue
1333
+   for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
1334
+       # for module.conf style syntax
1335
+       sa_mc_o[${#sa_mc_o[@]}]="-e"
1336
+       sa_mc_o[${#sa_mc_o[@]}]="s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) $obsolete_module$/\1 ${dest_module_name[$index]}/g"
1337
+
1338
+       # for /etc/sysconfig/kernel style syntax
1339
+       sa_sck_o[${#sa_sck_o[@]}]="-e"
1340
+       sa_sck_o[${#sa_sck_o[@]}]="s/\(INITRD_MODULES.*\)$obsolete_module\b\(.*\)/\1${dest_module_name[$index]}\2/"
1341
+   done
1342
+    done
1343
+
1344
+    # do all the changes at once, record the diffs for posterity
1345
+    for file in "$@"; do
1346
+   [[ $file && -w $file ]] || continue
1347
+   if [[ $file = /etc/sysconfig/kernel ]]; then
1348
+       sed "${sa_sck_o[@]}" "$file" > "$temp_dir_name/${file##*/}.new"
1349
+   else
1350
+       sed "${sa_mc_o[@]}" "$file" > "$temp_dir_name/${file##*/}.new"
1351
+   fi
1352
+   if ! mod_diff=$(diff -u "$temp_dir_name/${file##*/}.new" "$file"); then
1353
+       echo $"$file updated to replace obsoleted module references:"
1354
+       echo "$mod_diff"
1355
+       cp -fp "$temp_dir_name/${file##*/}.new" "$file"
1356
+       rm -f "$temp_dir_name/${file##*/}.new"
1357
+   fi
1358
+    done
1359
+}
1360
 
1361
-function moduleconfig_add ()
1362
+moduleconfig_add()
1363
 {
1364
     # $1 = kernel version
1365
 
1366
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
1367
-    modconfig_files=""
1368
-    [ -e /etc/modprobe.d/dkms.conf ] && modconfig_files="/etc/modprobe.d/dkms.conf"
1369
-    [ -e /etc/modprobe.d/dkms ] && modconfig_files="/etc/modprobe.d/dkms"
1370
-    [ -e /etc/modules.conf ] && modconfig_files="$modconfig_files /etc/modules.conf"
1371
-    [ -e /etc/modprobe.conf ] && modconfig_files="$modconfig_files /etc/modprobe.conf"
1372
-    [ -e /etc/modprobe.d/$package_name.conf ] && modconfig_files="/etc/modprobe.d/$package_name.conf"
1373
-
1374
-    if [ -z "$modconfig_files" ]; then
1375
-        modconfig_files="/etc/modprobe.d/$package_name.conf"
1376
-    fi
1377
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
1378
+    local -a sa_mc_o=() sa_sck_o=()
1379
+    modconfig_files="/etc/modprobe.d/dkms.conf
1380
+            /etc/modprobe.d/dkms
1381
+            /etc/modules.conf
1382
+            /etc/modprobe.conf
1383
+            /etc/modprobe.d/$package_name.conf
1384
+            /etc/sysconfig/kernel"
1385
 
1386
+    moduleconfig_update_obsoletes $modconfig_files
1387
 
1388
     for moduleconfig in $modconfig_files; do
1389
-        local index=0
1390
-        while [ $index -lt ${#dest_module_name[@]} ]; do
1391
-            # Replace obsolete references in module-config-file with the new module name
1392
-            if [ -n "${modules_conf_obsoletes[$index]}" ]; then
1393
-                for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
1394
-                    sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) $obsolete_module$/\1 ${dest_module_name[$index]}/g" $moduleconfig > $temp_dir_name/moduleconfig.new
1395
-                    if ! diff $moduleconfig $temp_dir_name/moduleconfig.new >/dev/null 2>&1; then
1396
-                        cp -fp $temp_dir_name/moduleconfig.new $moduleconfig 2>/dev/null
1397
-                        rm -f $temp_dir_name/moduleconfig.new 2>/dev/null
1398
-                        echo $"$moduleconfig: obsolete alias '$obsolete_module' changed to '${dest_module_name[$index]}'"
1399
-                    fi
1400
-                    if [ -e /etc/sysconfig/kernel ]; then
1401
-                       sed -e "s/\(INITRD_MODULES.*\)$obsolete_module\b\(.*\)/\1${dest_module_name[$index]}\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
1402
-                       if ! diff $temp_dir_name/kernel.new /etc/sysconfig/kernel >/dev/null 2>&1; then
1403
-                           cp -fp $temp_dir_name/kernel.new /etc/sysconfig/kernel 2>/dev/null
1404
-                           rm -f $temp_dir_name/kernel.new 2>/dev/null
1405
-                           echo $"/etc/sysconfig/kernel: obsolete alias '$obsolete_module' changed to '${dest_module_name[$index]}'"
1406
-                       fi
1407
-                    fi
1408
-                done
1409
-            fi
1410
-
1411
-            # Only add it if it can't be found already in config file
1412
-            if [ -n "${modules_conf_alias_type[$index]}" ] && \
1413
-               ! grep -qs "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}\b" $moduleconfig && \
1414
-               [ "${modules_conf_obsolete_only[$index]}" != "yes" ]; then
1415
-                if [ "$modconfig_files" == "/etc/modprobe.d/$package_name.conf" ] && \
1416
-                    [ ! -e /etc/modprobe.d/$package_name.conf ]; then
1417
-                    touch /etc/modprobe.d/$package_name.conf
1418
-                    echo $"created /etc/modprobe.d/$package_name.conf.">&2
1419
-                fi
1420
-                aliases=$(awk "/^alias ${modules_conf_alias_type[$index]}/ {print \$2}" $moduleconfig)
1421
-                if [ -n "$aliases" ]; then
1422
-                    alias_number=$(($(echo "$aliases" | sed "s/${modules_conf_alias_type[$index]}//" | sort -n | tail -n 1) + 1))
1423
-                else
1424
-                    alias_number=0
1425
-                fi
1426
-                echo -e "alias ${modules_conf_alias_type[$index]}${alias_number} ${dest_module_name[$index]}" >> $moduleconfig
1427
-                echo $"$moduleconfig: added alias reference for '${dest_module_name[$index]}'"
1428
-            fi
1429
+   [[ -e $moduleconfig ]] || continue
1430
+   for ((index=0; index < ${#dest_module_name[@]}; index++)); do
1431
 
1432
-            index=$(($index+1))
1433
-        done
1434
-
1435
-        # Add anything else
1436
-        index=0
1437
-        while [ $index -lt ${#modules_conf_array[@]} ]; do
1438
-            if [ -n "${modules_conf_array[$index]}" ] && \
1439
-            ! grep -q "${modules_conf_array[$index]}" "$moduleconfig"; then
1440
-            echo -e $"$moduleconfig: added '${modules_conf_array[$index]}'"
1441
-            echo -e "${modules_conf_array[$index]}" >> $moduleconfig
1442
-            fi
1443
-            index=$(($index+1))
1444
-        done
1445
+       # Only add it if it can't be found already in config file
1446
+       if [[ ${modules_conf_alias_type[$index]} ]] && \
1447
+          ! grep -qs "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}\b" $moduleconfig && \
1448
+          [[ ${modules_conf_obsolete_only[$index]} != yes ]]; then
1449
+       if [[ $modconfig_files = /etc/modprobe.d/$package_name.conf ]] && \
1450
+           [[ ! -e /etc/modprobe.d/$package_name.conf ]]; then
1451
+           touch /etc/modprobe.d/$package_name.conf
1452
+           echo $"created /etc/modprobe.d/$package_name.conf.">&2
1453
+       fi
1454
+       aliases=$(awk "/^alias ${modules_conf_alias_type[$index]}/ {print \$2}" $moduleconfig)
1455
+       if [[ $aliases ]]; then
1456
+           alias_number=$(($(echo "$aliases" | sed "s/${modules_conf_alias_type[$index]}//" | sort -n | tail -n 1) + 1))
1457
+       else
1458
+           alias_number=0
1459
+       fi
1460
+       echo -e "alias ${modules_conf_alias_type[$index]}${alias_number} ${dest_module_name[$index]}" >> $moduleconfig
1461
+       echo $"$moduleconfig: added alias reference for '${dest_module_name[$index]}'"
1462
+       fi
1463
+   done
1464
+
1465
+   # Add anything else
1466
+   for ((index=0; index < ${#modules_conf_array[@]}; index++)); do
1467
+       if [ -n "${modules_conf_array[$index]}" ] && \
1468
+       ! grep -q "${modules_conf_array[$index]}" "$moduleconfig"; then
1469
+       echo -e $"$moduleconfig: added '${modules_conf_array[$index]}'"
1470
+       echo -e "${modules_conf_array[$index]}" >> $moduleconfig
1471
+       fi
1472
+   done
1473
     done
1474
 
1475
     # Delete the temp dir
1476
     rm -rf $temp_dir_name
1477
 }
1478
 
1479
-
1480
-function moduleconfig_remove ()
1481
+moduleconfig_remove()
1482
 {
1483
     # $1 = kernel version
1484
 
1485
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
1486
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
1487
     modconfig_files=""
1488
     [ -e /etc/modprobe.d/dkms.conf ] && modconfig_files="/etc/modprobe.d/dkms.conf"
1489
     [ -e /etc/modprobe.d/dkms ] && modconfig_files="/etc/modprobe.d/dkms"
1490
@@ -874,152 +840,150 @@
1491
     [ -e /etc/modprobe.d/$package_name.conf ] && modconfig_files="/etc/modprobe.d/$package_name.conf"
1492
 
1493
     for moduleconfig in $modconfig_files; do
1494
-        index=0
1495
-        while [ $index -lt ${#dest_module_name[@]} ]; do
1496
-
1497
-            # Remove/Replace aliases (maybe)
1498
-            if [ -n "${modules_conf_alias_type[$index]}" ] && [ `find $install_tree/$1/ -name "${dest_module_name[$index]}.*" 2>/dev/null | wc -l | awk '{print $1}'` -eq 0 ]; then
1499
-
1500
-                local conf_replacement=""
1501
-                for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
1502
-                    if [ `find $install_tree/$1/ -name "$obsolete_module.*" 2>/dev/null | wc -l | awk '{print $1}'` -gt 0 ] && [ -z "$conf_replacement" ]; then
1503
-                        conf_replacement=$obsolete_module
1504
-                    fi
1505
-                done
1506
-
1507
-                if [ -n "$conf_replacement" ] && \
1508
-                    grep -q "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}$" $moduleconfig; then
1509
-                    sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) ${dest_module_name[$index]}$/\1 $conf_replacement/g" $moduleconfig > $temp_dir_name/moduleconfig.new
1510
-                    mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1511
-                    echo $"$moduleconfig: alias for '${dest_module_name[$index]}' changed back to '$conf_replacement'"
1512
-                elif [ -z "$conf_replacement" ]; then
1513
-                    grep -v "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}" $moduleconfig > $temp_dir_name/moduleconfig.new
1514
-                    mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1515
-                    echo $"$moduleconfig: removed alias for '${dest_module_name[$index]}'"
1516
-                    if [ "$modconfig_files" == "/etc/modprobe.d/$package_name.conf" ]; then
1517
-                        rm -f /etc/modprobe.d/$package_name.conf
1518
-                        echo $"$moduleconfig: deleted /etc/modprobe.d/$package_name.conf file"
1519
-                    fi
1520
-                fi
1521
-            fi
1522
-
1523
-            index=$(($index+1))
1524
-        done
1525
-
1526
-        # Remove static conf entries
1527
-        index=0
1528
-        while [ $index -lt ${#modules_conf_array[@]} ]; do
1529
-            if [ -n "${modules_conf_array[$index]}" ]; then
1530
-            grep -v "${modules_conf_array[$index]}" "$moduleconfig" > $temp_dir_name/moduleconfig.new
1531
-            echo $"$moduleconfig: removed '${modules_conf_array[$index]}'"
1532
-            mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1533
-            fi
1534
-            index=$(($index+1))
1535
-        done
1536
+   for ((index=0; index < ${#dest_module_name[@]}; index++)); do
1537
+       # Remove/Replace aliases (maybe)
1538
+       [[ ${modules_conf_alias_type[$index]} ]] || continue
1539
+       find "$install_tree/$1/" -name "${dest_module_name[$index]}.*" -quit 2>/dev/null && continue
1540
+
1541
+       local conf_replacement=""
1542
+       for obsolete_module in ${modules_conf_obsoletes[$index]//,/ }; do
1543
+       find $install_tree/$1/ -name "$obsolete_module.*" -quit 2>/dev/null || continue
1544
+       conf_replacement=$obsolete_module
1545
+       break
1546
+       done
1547
+
1548
+       if [[ ! $conf_replacement ]]; then
1549
+       grep -v "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}" $moduleconfig > $temp_dir_name/moduleconfig.new
1550
+       mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1551
+       echo $"$moduleconfig: removed alias for '${dest_module_name[$index]}'"
1552
+       if [[ $modconfig_files = /etc/modprobe.d/$package_name.conf ]]; then
1553
+           rm -f /etc/modprobe.d/$package_name.conf
1554
+           echo $"$moduleconfig: deleted /etc/modprobe.d/$package_name.conf file"
1555
+       fi
1556
+       elif grep -q "alias ${modules_conf_alias_type[$index]}[0-9]* ${dest_module_name[$index]}$" $moduleconfig; then
1557
+       sed "s/\(alias ${modules_conf_alias_type[$index]}[0-9]*\) ${dest_module_name[$index]}$/\1 $conf_replacement/g" $moduleconfig > $temp_dir_name/moduleconfig.new
1558
+       mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1559
+       echo $"$moduleconfig: alias for '${dest_module_name[$index]}' changed back to '$conf_replacement'"
1560
+       fi
1561
+   done
1562
+
1563
+   # Remove static conf entries
1564
+   for ((index=0; index < ${#modules_conf_array[@]}; index++)); do
1565
+       [[ ${modules_conf_array[$index]} ]] || continue
1566
+       grep -v "${modules_conf_array[$index]}" "$moduleconfig" > $temp_dir_name/moduleconfig.new
1567
+       echo $"$moduleconfig: removed '${modules_conf_array[$index]}'"
1568
+       mv -f $temp_dir_name/moduleconfig.new $moduleconfig
1569
+   done
1570
     done
1571
 
1572
     # Delete the temp dir
1573
     rm -rf $temp_dir_name
1574
 }
1575
 
1576
-# Does string word exist as a word in string list?
1577
-# returns 0 if word present, 1 if word not present
1578
-function is_word_in_list ()
1579
-{
1580
-    for l in $2; do
1581
-        [ "$1" = "${l}" ] && return 0
1582
-    done
1583
-    return 1
1584
-}
1585
+etc_sysconfig_kernel_modify()
1586
+(
1587
+    [[ -e /etc/sysconfig/kernel && $remake_initrd ]] || return 0
1588
 
1589
-function etc_sysconfig_kernel_modify ()
1590
-{
1591
     # Make a temp directory to store files
1592
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
1593
-
1594
-    if [ -e "/etc/sysconfig/kernel" ] && [ -n "$remake_initrd" ]; then
1595
-        # Make /etc/sysconfig/kernel changes as necessary
1596
-        if [ "$1" == "add" ]; then
1597
-            unset INITRD_MODULES
1598
-            eval `grep ^INITRD_MODULES= /etc/sysconfig/kernel`
1599
-            for module_name_after in "${dest_module_name[@]}"; do
1600
-                if ! is_word_in_list "${module_name_after}" "${INITRD_MODULES}"; then
1601
-                    sed -e "s/INITRD_MODULES=\"\(.*\)\"/INITRD_MODULES=\"\1 $module_name_after\"/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
1602
-                    mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
1603
-                fi
1604
-            done
1605
-        unset INITRD_MODULES
1606
-
1607
-        # Remove /etc/sysconfig/kernel entries
1608
-        elif [ "$1" == "delete" ]; then
1609
-            for module_name_after in "${dest_module_name[@]}"; do
1610
-                sed -e "s/\(INITRD_MODULES.*\)$module_name_after\b\(.*\)/\1\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
1611
-                mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
1612
-            done
1613
-        fi
1614
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
1615
+    if [[ $1 = add ]]; then
1616
+   . /etc/sysconfig/kernel
1617
+   for m in "${dest_module_name[@]}"; do
1618
+       for l in "${INITRD_MODULES}"; do
1619
+       [[ $m = $l ]] && continue 2
1620
+       done
1621
+       sed -e "s/INITRD_MODULES=\"\(.*\)\"/INITRD_MODULES=\"\1 $m\"/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
1622
+       mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
1623
+   done
1624
+    # Remove /etc/sysconfig/kernel entries
1625
+    elif [[ $1 = delete ]]; then
1626
+   for m in "${dest_module_name[@]}"; do
1627
+       sed -e "s/\(INITRD_MODULES.*\)$m\b\(.*\)/\1\2/" /etc/sysconfig/kernel > $temp_dir_name/kernel.new
1628
+       mv $temp_dir_name/kernel.new /etc/sysconfig/kernel
1629
+   done
1630
     fi
1631
-
1632
     # Delete the temp dir
1633
     rm -rf $temp_dir_name
1634
+)
1635
+
1636
+check_module_args() {
1637
+    [[ $module && $module_version ]] && return
1638
+    die 1 $"Invalid number of arguments passed." \
1639
+        $"Usage: $1 <module>/<module-version> or" \
1640
+        $"       $1 -m <module>/<module-version> or" \
1641
+   $"       $1 -m <module> -v <module-version>"
1642
+}
1643
+
1644
+read_conf_or_die() {
1645
+    read_conf "$@" && return
1646
+    die 8 $"Bad conf file." $"File: $conf" \
1647
+   $"does not represent a valid dkms.conf file."
1648
+}
1649
+
1650
+run_build_script() {
1651
+    # $1 = script type
1652
+    # $2 = script to run
1653
+    local script_type run
1654
+    [[ $2 ]] || return 0
1655
+    case "$1" in
1656
+        pre_build|post_build) script_type='build';;
1657
+        *) script_type='source'
1658
+    esac
1659
+    run="$dkms_tree/$module/$module_version/$script_type/$2"
1660
+    if [[ -x ${run%% *} ]]; then
1661
+        echo $""
1662
+        echo $"Running the $1 script:"
1663
+        (
1664
+            cd "$dkms_tree/$module/$module_version/$script_type/"
1665
+            exec $run
1666
+        )
1667
+    else
1668
+        echo $""
1669
+        warn $"The $1 script is not executable."
1670
+    fi
1671
 }
1672
 
1673
-function add_module ()
1674
+# Register a DKMS-ified source tree with DKMS.
1675
+# This function is smart enough to register the module if we
1676
+# passed a source tree or a tarball instead of relying on the source tree
1677
+# being unpacked into /usr/src/$module-$module_version.
1678
+add_module()
1679
 {
1680
-    setup_kernels_arches "add"
1681
+    # if $archive is set and $module and $module_version are not,
1682
+    # try loading the tarball passed first.
1683
+    if [[ $archive_location && ! $module && ! $module_version ]]; then
1684
+   load_tarball
1685
+    elif [[ $try_source_tree && ! $module && ! $module_version ]]; then
1686
+   add_source_tree "$try_source_tree"
1687
+    fi
1688
 
1689
     # Check that we have all the arguments
1690
-    if [ -z "$module" ] || [ -z "$module_version" ]; then
1691
-        echo $"" >&2
1692
-        echo $"Error! Invalid number of arguments passed." >&2
1693
-        echo $"Usage: add -m <module> -v <module-version>" >&2
1694
-        exit 1
1695
-    fi
1696
+    check_module_args add
1697
 
1698
-    if [ -z "$conf" ]; then
1699
-        conf="$source_tree/$module-$module_version/dkms.conf"
1700
+    # Check that this module-version hasn't already been added
1701
+    if is_module_added "$module" "$module_version"; then
1702
+   die 3 $"DKMS tree already contains: $module-$module_version" \
1703
+       $"You cannot add the same module/version combo more than once."
1704
     fi
1705
 
1706
+    [[ $conf ]] || conf="$source_tree/$module-$module_version/dkms.conf"
1707
+
1708
     # Check that /usr/src/$module-$module_version exists
1709
-    if ! [ -d "$source_tree/$module-$module_version" ]; then
1710
-        echo $"" >&2
1711
-        echo $"Error! Could not find module source directory." >&2
1712
-        echo $"Directory: $source_tree/$module-$module_version does not exist." >&2
1713
-        exit 2
1714
+    if ! [[ -d $source_tree/$module-$module_version ]]; then
1715
+   die 2 $"Could not find module source directory." \
1716
+       $"Directory: $source_tree/$module-$module_version does not exist."
1717
     fi
1718
 
1719
     # Do stuff for --rpm_safe_upgrade
1720
-    if [ -n "$rpm_safe_upgrade" ]; then
1721
-        local pppid=`sed -ne 's/PPid:[ \t]*//p' /proc/$PPID/status`
1722
-        local temp_dir_name=`mktemp $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.XXXXXX 2>/dev/null`
1723
-        echo "$module-$module_version" >> $temp_dir_name
1724
-        ps -o lstart --no-headers -p $pppid 2>/dev/null >> $temp_dir_name
1725
-    fi
1726
-
1727
-    # Check that this module-version hasn't already been added
1728
-    if [ -d "$dkms_tree/$module/$module_version" ]; then
1729
-        echo $"" >&2
1730
-        echo $"Error! DKMS tree already contains: $module-$module_version" >&2
1731
-        echo $"You cannot add the same module/version combo more than once." >&2
1732
-        exit 3
1733
-    fi
1734
-
1735
-    # Check that the conf file exists or any other script specified
1736
-    if ! [ -e "$conf" ]; then
1737
-        echo $"" >&2
1738
-        echo $"Error! Could not locate dkms.conf file." >&2
1739
-        echo $"File: $conf does not exist." >&2
1740
-        exit 4
1741
+    if [[ $rpm_safe_upgrade ]]; then
1742
+   local pppid=$(awk '/PPid:/ {print $2}' /proc/$PPID/status)
1743
+   local lock_name=$(mktemp_or_die $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.XXXXXX)
1744
+   echo "$module-$module_version" >> $lock_name
1745
+   ps -o lstart --no-headers -p $pppid 2>/dev/null >> $lock_name
1746
     fi
1747
 
1748
     # Check the conf file for sanity
1749
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
1750
-    if [ "$?" -ne 0 ]; then
1751
-        echo $"" >&2
1752
-        echo $"Error! Bad conf file." >&2
1753
-        echo $"File: $conf" >&2
1754
-        echo $"does not represent a valid dkms.conf file." >&2
1755
-        exit 8
1756
-    fi
1757
+    read_conf_or_die "$kernelver" "$arch" "$conf"
1758
 
1759
     # Create the necessary dkms tree structure
1760
     echo $""
1761
@@ -1029,17 +993,16 @@
1762
     ln -s "$source_tree/$module-$module_version" "$dkms_tree/$module/$module_version/source"
1763
 
1764
     # Run the post_add script
1765
-    if [ -n "$post_add" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_add" | sed 's/ .*//'` ]; then
1766
-        echo $""
1767
-        echo $"Running the post_add script:"
1768
-        $dkms_tree/$module/$module_version/source/$post_add
1769
-    fi
1770
+    run_build_script post_add "$post_add"
1771
 
1772
     echo $""
1773
-    echo $"DKMS: add Completed."
1774
+    echo $"DKMS: add completed."
1775
 }
1776
 
1777
-function prepare_kernel()
1778
+# Prepare a kernel source or include tree for compiling a module.
1779
+# Most modern-ish distros do not require this function at all,
1780
+# so it will be removed in a future release.
1781
+prepare_kernel()
1782
 {
1783
     # $1 = kernel version to prepare
1784
     # $2 = arch to prepare
1785
@@ -1047,33 +1010,27 @@
1786
     set_kernel_source_dir "$1"
1787
 
1788
     # Check that kernel-source exists
1789
-    if ! [ -e "$kernel_source_dir/include" ]; then
1790
-        echo $"" >&2
1791
-        echo $"Error! Your kernel headers for kernel $1 cannot be found at" >&2
1792
-        echo $"/lib/modules/$1/build or /lib/modules/$1/source." >&2
1793
-        echo -n $"You can use the --kernelsourcedir option to tell DKMS where it's located"
1794
-        case "$running_distribution" in
1795
-        Debian* | Ubuntu* )
1796
-            echo $", or you could install the linux-headers-$1 package."
1797
-            ;;
1798
-        * )
1799
-            echo $"."
1800
-            ;;
1801
-        esac
1802
-        exit 1
1803
-    fi
1804
+    _check_kernel_dir "$1" || {
1805
+   case "$running_distribution" in
1806
+       Debian* | Ubuntu* )
1807
+       die 1 $"Your kernel headers for kernel $1 cannot be found." \
1808
+           $"Please install the linux-headers-$1 package," \
1809
+           $"or use the --kernelsourcedir option to tell DKMS where it's located";;
1810
+       * ) die 1 echo $"Your kernel headers for kernel $1 cannot be found at" \
1811
+       $"/lib/modules/$1/build or /lib/modules/$1/source."
1812
+       $"You can use the --kernelsourcedir option to tell DKMS where it's located."
1813
+   esac
1814
+    }
1815
 
1816
-    if [ -n "$no_prepare_kernel" ]; then
1817
-        return
1818
-    fi
1819
+    [[ $no_prepare_kernel ]] && return
1820
 
1821
-    if [[ (! ( $(VER $1) < $(VER 2.6.5) ) || (-d /etc/SuSEconfig)) && \
1822
+    if [[ (! ( $(VER $1) < $(VER 2.6.5) ) || -d /etc/SuSEconfig) && \
1823
        -d "$kernel_source_dir" && \
1824
        -z "$ksourcedir_fromcli" ]]; then
1825
-        echo $""
1826
-        echo $"Kernel preparation unnecessary for this kernel.  Skipping..."
1827
-        no_clean_kernel="no-clean-kernel"
1828
-        return 1
1829
+   echo $""
1830
+   echo $"Kernel preparation unnecessary for this kernel.  Skipping..."
1831
+   no_clean_kernel="no-clean-kernel"
1832
+   return 1
1833
     fi
1834
 
1835
     # Prepare kernel for module build
1836
@@ -1081,540 +1038,473 @@
1837
     echo $"Preparing kernel $1 for module build:"
1838
     echo $"(This is not compiling a kernel, just preparing kernel symbols)"
1839
     cd $kernel_source_dir
1840
-    config_contents=`cat .config 2>/dev/null`
1841
-    [ -n "$config_contents" ] && echo $"Storing current .config to be restored when complete"
1842
+    [[ -r .config ]] && {
1843
+   config_contents=$(cat .config)
1844
+   echo $"Storing current .config to be restored when complete"
1845
+    }
1846
 
1847
     # Set kernel_config
1848
-    if [ -e /etc/redhat-release ] || [ -e /etc/fedora-release ]; then
1849
-        # Note this also applies to VMware 3.x
1850
-        if [ -z "$kernel_config" ] && [ -d "$kernel_source_dir/configs" ]; then
1851
-            local kernel_trunc=`echo $1 | sed 's/-.*//'`
1852
-            for config_type in debug summit smp enterprise bigmem hugemem BOOT vmnix; do
1853
-                [ `echo "$1" | grep "$config_type"` ] && kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2-$config_type.config"
1854
-                [ ! -e "$kernel_config" ] && kernel_config=""
1855
-            done
1856
-            [ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2.config"
1857
-            [ ! -e "$kernel_config" ] && kernel_config=""
1858
-        fi
1859
-    elif [ -e /etc/SuSE-release ] || [ -d /etc/SuSEconfig ]; then
1860
-        if [ -z "$kernel_config" ] && [ -d "$kernel_source_dir/arch" ]; then
1861
-            local kernel_trunc=`echo $1 | sed 's/-.*//'`
1862
-            if [ "$2" == "i586" ] || [ "$2" == "i686" ]; then
1863
-                config_arch="i386"
1864
-            else
1865
-                config_arch=$2
1866
-            fi
1867
-            for config_type in default smp bigsmp; do
1868
-                [ `echo "$1" | grep "$config_type"` ] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.$config_type"
1869
-                [ ! -e "$kernel_config" ] && kernel_config=""
1870
-            done
1871
-            [ -z "$kernel_config" ] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.default"
1872
-            [ ! -e "$kernel_config" ] && kernel_config=""
1873
-        fi
1874
+    if [[ -e /etc/redhat-release || -e /etc/fedora-release ]]; then
1875
+   # Note this also applies to VMware 3.x
1876
+   if [[ -z $kernel_config && -d $kernel_source_dir/configs ]]; then
1877
+       local kernel_trunc=${1%%-*}
1878
+       # Try a .config specific to whatever kernel we are running
1879
+       if [[ $1 =~ $rh_kernels && \
1880
+       -e $kernel_source_dir/configs/kernel-$kernel_trunc-$2-${BASH_REMATCH[1]}.config ]]; then
1881
+       kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2-${BASH_REMATCH[1]}.config"
1882
+       elif [[ -e $kernel_source_dir/configs/kernel-$kernel_trunc-$2.config ]]; then
1883
+       # If that one does not exist, try a generic one.
1884
+       kernel_config="$kernel_source_dir/configs/kernel-$kernel_trunc-$2.config"
1885
+       else
1886
+       # If that does not exist, fall back to no config file
1887
+       kernel_config=""
1888
+       fi
1889
+   fi
1890
+    elif [[ (-e /etc/SuSE-release || -d /etc/SuSEconfig) && \
1891
+   -z $kernel_config && -d $kernel_source_dir/arch ]]; then
1892
+       local kernel_trunc=${1%%-*}
1893
+       case $2 in
1894
+       i586|i686) config_arch="i386";;
1895
+       *) config_arch=$2;;
1896
+       esac
1897
+       for config_type in default smp bigsmp; do
1898
+       [[ $1 =~ $config_type ]] && kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.$config_type"
1899
+       [[ -e $kernel_config ]] || kernel_config=""
1900
+       done
1901
+       [[ $kernel_config ]] || kernel_config="$kernel_source_dir/arch/$config_arch/defconfig.default"
1902
+       [[ -e $kernel_config ]] || kernel_config=""
1903
     fi
1904
 
1905
     # Do preparation
1906
     if [ -e /boot/vmlinuz.version.h ]; then
1907
-        echo $"Running UnitedLinux preparation routine"
1908
-        local kernel_config="/boot/vmlinuz.config"
1909
-        invoke_command "make mrproper" "make mrproper" background
1910
-        [ -n "$config_contents" ] && echo "$config_contents" > .config
1911
-        invoke_command "cp /boot/vmlinuz.version.h include/linux/version.h" "using /boot/vmlinux.version.h"
1912
-        invoke_command "cp -f $kernel_config .config" "using $kernel_config"
1913
-        invoke_command "make KERNELRELEASE=$1 cloneconfig" "make cloneconfig" background
1914
-        invoke_command "make CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
1915
+   echo $"Running UnitedLinux preparation routine"
1916
+   local kernel_config="/boot/vmlinuz.config"
1917
+   invoke_command "make mrproper" "make mrproper" background
1918
+   [[ $config_contents ]] && echo "$config_contents" > .config
1919
+   invoke_command "cp /boot/vmlinuz.version.h include/linux/version.h" "using /boot/vmlinux.version.h"
1920
+   invoke_command "cp -f $kernel_config .config" "using $kernel_config"
1921
+   invoke_command "make KERNELRELEASE=$1 cloneconfig" "make cloneconfig" background
1922
+   invoke_command "make CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
1923
     elif grep -q rhconfig.h $kernel_source_dir/include/linux/{modversions,version}.h 2>/dev/null; then
1924
-        echo $"Running Red Hat style preparation routine"
1925
-        invoke_command "make clean" "make clean" background
1926
-        [ -n "$config_contents" ] && echo "$config_contents" > .config
1927
-
1928
-        if [ -n "$kernel_config" ]; then
1929
-            echo $"using $kernel_config"
1930
-            cp -f "$kernel_config" .config
1931
-        elif [ -e .config ]; then
1932
-            echo $"using $kernel_source_dir/.config"
1933
-            echo $"(I hope this is the correct config for this kernel)"
1934
-        else
1935
-            echo $""
1936
-            echo $"Warning! Cannot find a .config file to prepare your kernel with." >&2
1937
-            echo $"Try using the --config option to specify where one can be found." >&2
1938
-            echo $"Your build will likely fail because of this." >&2
1939
-        fi
1940
-
1941
-        # Hack to workaround broken tmp_include_depends for Red Hat
1942
-        if grep -q "/usr/src/build" $kernel_source_dir/tmp_include_depends 2>/dev/null; then
1943
-            sed 's/\/usr\/src\/build\/.*\/install//g' $kernel_source_dir/tmp_include_depends > $kernel_source_dir/tmp_include_depends.new
1944
-            mv -f $kernel_source_dir/tmp_include_depends.new $kernel_source_dir/tmp_include_depends
1945
-        fi
1946
-
1947
-        invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
1948
-        kerneldoth_contents=`cat /boot/kernel.h 2>/dev/null`
1949
-        invoke_command "/usr/lib/dkms/mkkerneldoth --kernelver $1 --targetarch $2 --output /boot/kernel.h" "running mkkerneldoth" background
1950
-    else
1951
-        echo $"Running Generic preparation routine"
1952
-        invoke_command "make mrproper" "make mrproper" background
1953
-        [ -n "$config_contents" ] && echo "$config_contents" > .config
1954
-
1955
-        if [ -n "$kernel_config" ]; then
1956
-            echo $"using $kernel_config"
1957
-            cp -f "$kernel_config" .config
1958
-        elif [ -e .config ]; then
1959
-            echo $"using $kernel_source_dir/.config"
1960
-            echo $"(I hope this is the correct config for this kernel)"
1961
-        else
1962
-            echo $""
1963
-            echo $"Warning! Cannot find a .config file to prepare your kernel with." >&2
1964
-            echo $"Try using the --config option to specify where one can be found." >&2
1965
-            echo $"Your build will likely fail because of this." >&2
1966
-        fi
1967
-
1968
-        invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
1969
-        if [[ $(VER $1) < $(VER 2.5) ]]; then
1970
-            invoke_command "make KERNELRELEASE=$1 dep" "make dep" background
1971
-        else
1972
-            invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
1973
-        fi
1974
+   echo $"Running Red Hat style preparation routine"
1975
+   invoke_command "make clean" "make clean" background
1976
+   [[ $config_contents ]] && echo "$config_contents" > .config
1977
+
1978
+   if [[ $kernel_config ]]; then
1979
+       echo $"using $kernel_config"
1980
+       cp -f "$kernel_config" .config
1981
+   elif [[ -e .config ]]; then
1982
+       warn $"Using $kernel_source_dir/.config" \
1983
+       $"(I hope this is the correct config for this kernel)"
1984
+   else
1985
+       warn $"Cannot find a .config file to prepare your kernel with." \
1986
+       $"Try using the --config option to specify where one can be found." \
1987
+       $"Your build will likely fail because of this."
1988
+   fi
1989
+
1990
+   # Hack to workaround broken tmp_include_depends for Red Hat
1991
+   if grep -q "/usr/src/build" $kernel_source_dir/tmp_include_depends 2>/dev/null; then
1992
+       sed 's/\/usr\/src\/build\/.*\/install//g' $kernel_source_dir/tmp_include_depends > $kernel_source_dir/tmp_include_depends.new
1993
+       mv -f $kernel_source_dir/tmp_include_depends.new $kernel_source_dir/tmp_include_depends
1994
+   fi
1995
+
1996
+   invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
1997
+   kerneldoth_contents=$(cat /boot/kernel.h 2>/dev/null)
1998
+   invoke_command "/usr/lib/dkms/mkkerneldoth --kernelver $1 --targetarch $2 --output /boot/kernel.h" "running mkkerneldoth" background
1999
+    else
2000
+   echo $"Running Generic preparation routine"
2001
+   invoke_command "make mrproper" "make mrproper" background
2002
+   [[ $config_contents ]] && echo "$config_contents" > .config
2003
+
2004
+   if [[ $kernel_config ]]; then
2005
+       echo $"using $kernel_config"
2006
+       cp -f "$kernel_config" .config
2007
+   elif [[ -e .config ]]; then
2008
+       warn $"using $kernel_source_dir/.config" \
2009
+       $"(I hope this is the correct config for this kernel)"
2010
+   else
2011
+       warn $"Warning! Cannot find a .config file to prepare your kernel with." \
2012
+       $"Try using the --config option to specify where one can be found." \
2013
+       $"Your build will likely fail because of this."
2014
+   fi
2015
+
2016
+   invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
2017
+   if [[ $(VER $1) < $(VER 2.5) ]]; then
2018
+       invoke_command "make KERNELRELEASE=$1 dep" "make dep" background
2019
+   else
2020
+       invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
2021
+   fi
2022
     fi
2023
     cd - >/dev/null
2024
 }
2025
 
2026
-function list_each_installed_module ()
2027
+# Get ready to build a module that has been registered with DKMS.
2028
+prepare_build()
2029
 {
2030
-    # $1 = module
2031
-    # $2 = kernel version
2032
-    # $3 = arch
2033
-    local count=0
2034
-    local real_dest_module_location
2035
-    while [ "$count" -lt "${#built_module_name[@]}" ]; do
2036
-        real_dest_module_location="$(find_actual_dest_module_location $1 $count $2 $3)"
2037
-        echo "$install_tree/$2${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
2038
-        count=$(($count + 1))
2039
-    done
2040
-}
2041
-
2042
-function set_weak_modules()
2043
-{
2044
-    [ -n "${weak_modules}" ] && return
2045
-    [ -x /sbin/weak-modules ] && weak_modules='/sbin/weak-modules'
2046
-    [ -x /usr/lib/module-init-tools/weak-modules ] && weak_modules='/usr/lib/module-init-tools/weak-modules'
2047
-}
2048
-
2049
-function install_module()
2050
-{
2051
-    setup_kernels_arches "install"
2052
-    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
2053
-
2054
-    # Check that the right arguments were passed
2055
-    if [ -z "$module" ] || [ -z "$module_version" ]; then
2056
-        echo $"" >&2
2057
-        echo $"Error! Invalid number of parameters passed." >&2
2058
-        echo $"Usage: install -m <module> -v <module-version>" >&2
2059
-        exit 1
2060
-    fi
2061
-
2062
-    # Check that $module-$module_version exists by checking the source symlink
2063
-    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
2064
-        echo $"" >&2
2065
-        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
2066
-        echo $"Build cannot continue without the proper tree." >&2
2067
-        exit 2
2068
-    fi
2069
-
2070
-    # Make sure that kernel exists to install into
2071
-    if ! [ -e "$install_tree/${kernelver_array[0]}" ]; then
2072
-        echo $"" >&2
2073
-        echo $"Error! The directory $install_tree/${kernelver_array[0]} doesn't exist." >&2
2074
-        echo $"You cannot install a module onto a non-existant kernel." >&2
2075
-        exit 6
2076
-    fi
2077
-
2078
-    # Read the conf file
2079
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
2080
-    if [ "$?" -ne 0 ]; then
2081
-        echo $"" >&2
2082
-        echo $"Error! Bad conf file." >&2
2083
-        echo $"Your dkms.conf is not valid." >&2
2084
-        exit 3
2085
-    fi
2086
-
2087
-    # Make sure the $module_name_after exists
2088
-    set_module_suffix "${kernelver_array[0]}"
2089
-    for module_name_after in "${dest_module_name[@]}"; do
2090
-        if ! [ -e "$base_dir/module/$module_name_after$module_suffix" ]; then
2091
-            echo $"" >&2
2092
-            echo $"Error! Could not locate $module_name_after$module_suffix for module $module in the DKMS tree." >&2
2093
-            echo $"You must run a dkms build for kernel ${kernelver_array[0]} (${arch_array[0]}) first." >&2
2094
-            exit 4
2095
-        fi
2096
-    done
2097
+    # If the module has not been added, try to add it.
2098
+    is_module_added "$module" "$module_version" || add_module
2099
 
2100
-    # Check that its not already installed (kernel symlink)
2101
-    readlink "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}"
2102
-    kernel_symlink="$read_link"
2103
-    if [ "$kernel_symlink" == "$module_version/${kernelver_array[0]}/${arch_array[0]}" ]; then
2104
-        echo $"" >&2
2105
-        echo $"Error! This module/version combo is already installed" >&2
2106
-        echo $"for kernel: ${kernelver_array[0]} (${arch_array[0]})" >&2
2107
-        exit 5
2108
-    fi
2109
-
2110
-    # if upgrading using rpm_safe_upgrade, go ahead and force the install
2111
-    # else we can wind up with the first half of an upgrade failing to install anything,
2112
-    # while the second half of the upgrade, the removal, then succeeds, leaving us with
2113
-    # nothing installed.
2114
-    if [ -n "$rpm_safe_upgrade" ]; then
2115
-        force="true"
2116
-    fi
2117
-
2118
-    # Save the original_module if one exists, none have been saved before, and this is the first module for this kernel
2119
-    local lib_tree="$install_tree/${kernelver_array[0]}"
2120
-    local count=0
2121
-    while [ "$count" -lt ${#built_module_name[@]} ]; do
2122
-        echo $""
2123
-        echo $"${dest_module_name[$count]}$module_suffix:"
2124
-        # Check this version against what is already in the kernel
2125
-        if ! check_version_sanity "${kernelver_array[0]}" "${arch_array[0]}" "$obsolete_by" "${dest_module_name[$count]}"; then
2126
-            count=$(($count + 1))
2127
-            continue
2128
-        fi
2129
-
2130
-        if [ "$count" -eq 0 ]; then
2131
-            # Run the pre_install script
2132
-            if [ -n "$pre_install" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_install" | sed 's/ .*//'` ]; then
2133
-                echo $""
2134
-                echo $"Running the pre_install script:"
2135
-                $dkms_tree/$module/$module_version/source/$pre_install
2136
-                if [ "$?" -ne 0 -a -z "$force" ]; then
2137
-                    echo $"pre_install failed, aborting install." >&2
2138
-                    echo $"You may override by specifying --force." >&2
2139
-                    exit 101
2140
-                fi
2141
-            fi
2142
-        fi
2143
-        local module_count=`find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f | wc -l | awk {'print $1'}`
2144
-        echo $" - Original module"
2145
-        if ! [ -L "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" ]; then
2146
-            local archive_pref1="$lib_tree/extra/${dest_module_name[$count]}$module_suffix"
2147
-            local archive_pref2="$lib_tree/updates/${dest_module_name[$count]}$module_suffix"
2148
-            local archive_pref3="$lib_tree${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
2149
-            local archive_pref4=""
2150
-            [ "$module_count" -eq 1 ] && archive_pref4="`find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f`"
2151
-            local original_module=""
2152
-            local found_orginal=""
2153
-            for original_module in $archive_pref1 $archive_pref2 $archive_pref3 $archive_pref4; do
2154
-                if [ -f "$original_module" ]; then
2155
-                    case "$running_distribution" in
2156
-                        Debian* | Ubuntu* ) ;;
2157
-                        *)
2158
-                            echo $"   - Found $original_module"
2159
-                            echo $"   - Storing in $dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/"
2160
-                            echo $"   - Archiving for uninstallation purposes"
2161
-                            mkdir -p "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}"
2162
-                            mv -f "$original_module" "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/"
2163
-                            ;;
2164
-                    esac
2165
-                    found_original="yes"
2166
-                    break
2167
-                fi
2168
-            done
2169
-            if [ -z "$found_original" ] && [ "$module_count" -gt 1 ]; then
2170
-                echo $"   - Multiple original modules exist but DKMS does not know which to pick"
2171
-                echo $"   - Due to the confusion, none will be considered during a later uninstall"
2172
-            elif [ -z "$found_original" ]; then
2173
-                echo $"   - No original module exists within this kernel"
2174
-            fi
2175
-        elif [ -L "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" ] && [ -e "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/${dest_module_name[$count]}$module_suffix" ]; then
2176
-            echo $"   - An original module was already stored during a previous install"
2177
-        else
2178
-            echo $"   - This kernel never originally had a module by this name"
2179
-        fi
2180
-
2181
-        if [ "$module_count" -gt 1 ]; then
2182
-            echo $" - Multiple same named modules!"
2183
-            echo $"   - $module_count named ${dest_module_name[$count]}$module_suffix in $lib_tree/"
2184
-            case "$running_distribution" in
2185
-            Debian* | Ubuntu* ) ;;
2186
-            *)
2187
-                echo $"   - All instances of this module will now be stored for reference purposes ONLY"
2188
-                echo $"   - Storing in $dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/"
2189
-                ;;
2190
-            esac
2191
-            for module_dup in `find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f`; do
2192
-                dup_tree=`echo $module_dup | sed "s#^$lib_tree##" | sed "s#${dest_module_name[$count]}$module_suffix##"`
2193
-                case "$running_distribution" in
2194
-                Debian* | Ubuntu* ) ;;
2195
-                *)
2196
-                   echo $"     - Stored $module_dup"
2197
-                   mkdir -p "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/$dup_tree"
2198
-                   mv -f $module_dup "$dkms_tree/$module/original_module/${kernelver_array[0]}/${arch_array[0]}/collisions/$dup_tree"
2199
-                   ;;
2200
-                esac
2201
-            done
2202
-        fi
2203
-
2204
-        # Copy module to its location
2205
-        echo $" - Installation"
2206
-        echo $"   - Installing to $install_tree/${kernelver_array[0]}${dest_module_location[$count]}/"
2207
-        mkdir -p $install_tree/${kernelver_array[0]}${dest_module_location[$count]}
2208
-        cp -f "$base_dir/module/${dest_module_name[$count]}$module_suffix" "$install_tree/${kernelver_array[0]}${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
2209
-
2210
-        count=$(($count + 1))
2211
-    done
2212
-
2213
-    # Create the kernel-<kernelver> symlink to designate this version as active
2214
-    rm -f "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" 2>/dev/null
2215
-    ln -s "$module_version/${kernelver_array[0]}/${arch_array[0]}" "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}" 2>/dev/null
2216
-
2217
-    # add to kabi-tracking
2218
-    set_weak_modules
2219
-    if [ -n "${weak_modules}" ]; then
2220
-        echo $"Adding any weak-modules"
2221
-        list_each_installed_module "$module" "${kernelver_array[0]}" "${arch_array[0]}" | ${weak_modules} --add-modules
2222
-    fi
2223
-
2224
-    # Run the post_install script
2225
-    if [ -n "$post_install" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_install" | sed 's/ .*//'` ]; then
2226
-        echo $""
2227
-        echo $"Running post_install:"
2228
-        $dkms_tree/$module/$module_version/source/$post_install
2229
-    fi
2230
-
2231
-    # Make modules.conf changes as necessary
2232
-    echo $""
2233
-    moduleconfig_add "${kernelver_array[0]}"
2234
-    etc_sysconfig_kernel_modify "add"
2235
-
2236
-    invoke_command "do_depmod ${kernelver_array[0]}" "depmod" background
2237
-    if [ "$?" -ne 0 ]; then
2238
-        local unresolved_symbols="$(do_depmod ${kernelver_array[0]} 2>&1)"
2239
-        local count=0
2240
-        while [ "$count" -lt "${#built_module_name[@]}" ]; do
2241
-            if echo "$unresolved_symbols" | grep -q "${dest_module_name[$count]}$module_suffix$"; then
2242
-                echo $""
2243
-                echo $"Problems with depmod detected.  Automatically uninstalling this module."
2244
-                sleep 2
2245
-                do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
2246
-                echo $""
2247
-                echo $"DKMS: Install Failed (depmod problems).  Module rolled back to built state."
2248
-                exit 6
2249
-            fi
2250
-            count=$(($count + 1))
2251
-        done
2252
-    fi
2253
-
2254
-    # Do remake_initrd things (save old initrd)
2255
-    if [ -n "$remake_initrd" ]; then
2256
-        remake_initrd "${kernelver_array[0]}" "${arch_array[0]}"
2257
-        if [ "$?" -ne 0 ]; then
2258
-            echo $"Problems with mkinitrd detected.  Automatically uninstalling this module."
2259
-            sleep 2
2260
-            do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
2261
-            echo $""
2262
-            echo $"DKMS: Install Failed (mkinitrd problems).  Module rolled back to built state."
2263
-            exit 7
2264
-        fi
2265
-    fi
2266
-
2267
-    echo $""
2268
-    echo $"DKMS: install Completed."
2269
-}
2270
-
2271
-
2272
-function prepare_build()
2273
-{
2274
-    setup_kernels_arches "build"
2275
-    set_kernel_source_dir "${kernelver_array[0]}"
2276
-    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
2277
+    set_kernel_source_dir "$kernelver"
2278
+    local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
2279
 
2280
     # Check that the right arguments were passed
2281
-    if [ -z "$module" ] || [ -z "$module_version" ]; then
2282
-        echo $"" >&2
2283
-        echo $"Error! Invalid number of parameters passed." >&2
2284
-        echo $"Usage: build -m <module> -v <module-version>" >&2
2285
-        exit 1
2286
-    fi
2287
-
2288
-    # Check that source symlink works
2289
-    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
2290
-        echo $"" >&2
2291
-        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
2292
-        echo $"Build cannot continue without the proper tree." >&2
2293
-        exit 2
2294
-    fi
2295
+    check_module_args build
2296
 
2297
     # Check that the module has not already been built for this kernel
2298
-    if [ -d "$base_dir" ]; then
2299
-        echo $"" >&2
2300
-        echo $"Error! This module/version has already been built on: ${kernelver_array[0]}" >&2
2301
-        echo $"Directory: $base_dir" >&2
2302
-        echo $"already exists.  Use the dkms remove function before trying to build again." >&2
2303
-        exit 3
2304
-    fi
2305
+    [[ -d $base_dir ]] && die 3 \
2306
+   $"This module/version has already been built on: $kernelver" \
2307
+   $"Directory: $base_dir" \
2308
+   $"already exists.  Use the dkms remove function before trying to build again."
2309
 
2310
     # Read the conf file
2311
-    set_module_suffix "${kernelver_array[0]}"
2312
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
2313
-    if [ "$?" -ne 0 ]; then
2314
-        echo $"" >&2
2315
-        echo $"Error! Bad conf file." >&2
2316
-        echo $"Your dkms.conf is not valid." >&2
2317
-        exit 4
2318
-    fi
2319
+    set_module_suffix "$kernelver"
2320
+    read_conf_or_die "$kernelver" "$arch"
2321
 
2322
     # Error out if build_exclude is set
2323
-    if [ -n "$build_exclude" ]; then
2324
-        echo "" >&2
2325
-        echo "Error!  The dkms.conf for this module includes a BUILD_EXCLUSIVE directive which" >&2
2326
-        echo "does not match this kernel/arch.  This indicates that it should not be built." >&2
2327
-        exit 9
2328
-    fi
2329
+    [[ $build_exclude ]] && die 9 \
2330
+   $" The dkms.conf for this module includes a BUILD_EXCLUSIVE directive which" \
2331
+   $"does not match this kernel/arch.  This indicates that it should not be built."
2332
 
2333
     # Error out if source_tree is basically empty (binary-only dkms tarball w/ --force check)
2334
-    if [ `ls $dkms_tree/$module/$module_version/source | wc -l | awk {'print $1'}` -lt 2 ]; then
2335
-        echo "" >&2
2336
-        echo $"Error! The directory $dkms_tree/$module/$module_version/source/" >&2
2337
-        echo $"does not appear to have module source located within it.  Build halted." >&2
2338
-        exit 8
2339
-    fi
2340
+    (($(ls $dkms_tree/$module/$module_version/source | wc -l | awk {'print $1'}) < 2)) && die 8 \
2341
+   $"The directory $dkms_tree/$module/$module_version/source/" \
2342
+   $"does not appear to have module source located within it.  Build halted."
2343
 
2344
-    prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
2345
+    prepare_kernel "$kernelver" "$arch"
2346
 
2347
     # Set up temporary build directory for build
2348
     rm -rf "$dkms_tree/$module/$module_version/build"
2349
     cp -rf "$dkms_tree/$module/$module_version/source/" "$dkms_tree/$module/$module_version/build"
2350
 
2351
-    # Run the pre_build script
2352
-    if [ -n "$pre_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_build" | sed 's/ .*//'` ]; then
2353
-        echo $""
2354
-        echo $"Running the pre_build script:"
2355
-        $dkms_tree/$module/$module_version/source/$pre_build
2356
-    fi
2357
-
2358
     cd "$dkms_tree/$module/$module_version/build"
2359
 
2360
     # Apply any patches
2361
-    local index=0
2362
-    while [ $index -lt ${#patch_array[@]} ]; do
2363
-        if ! [ -e "$dkms_tree/$module/$module_version/build/patches/${patch_array[$index]}" ]; then
2364
-            echo $"" >&2
2365
-            echo $"Error!  Patch ${patch_array[$index]} as specified in dkms.conf cannot be" >&2
2366
-            echo $"found in $dkms_tree/$module/$module_version/build/patches/." >&2
2367
-            exit 5
2368
-        fi
2369
-        invoke_command "patch -p1 < ./patches/${patch_array[$index]}" "applying patch ${patch_array[$index]}"
2370
-        if [ "$?" -ne 0 ]; then
2371
-            echo $"" >&2
2372
-            echo $"Error! Application of patch ${patch_array[$index]} failed." >&2
2373
-            echo $"Check $dkms_tree/$module/$module_version/build/ for more information." >&2
2374
-                report_build_problem
2375
-            exit 6
2376
-        fi
2377
-        index=$(($index+1))
2378
+    for p in "${patch_array[@]}"; do
2379
+   [[ ! -e $dkms_tree/$module/$module_version/build/patches/$p ]] && \
2380
+       report_build_problem 5 \
2381
+       $" Patch $p as specified in dkms.conf cannot be" \
2382
+       $"found in $dkms_tree/$module/$module_version/build/patches/."
2383
+   invoke_command "patch -p1 < ./patches/$p" "applying patch $p" || \
2384
+       report_build_problem 6 $"Application of patch $p failed." \
2385
+       $"Check $dkms_tree/$module/$module_version/build/ for more information."
2386
     done
2387
+
2388
+    # Run the pre_build script
2389
+    run_build_script pre_build "$pre_build"
2390
 }
2391
 
2392
-function do_build()
2393
+# Build our previously prepared source tree.  prepare_build must be called
2394
+# before calling this function.
2395
+do_build()
2396
 {
2397
-    local base_dir="$dkms_tree/$module/$module_version/${kernelver_array[0]}/${arch_array[0]}"
2398
+    local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
2399
     echo $""
2400
     echo $"Building module:"
2401
 
2402
     invoke_command "$clean" "cleaning build area" background
2403
-    echo $"DKMS make.log for $module-$module_version for kernel ${kernelver_array[0]} (${arch_array[0]})" >> "$dkms_tree/$module/$module_version/build/make.log"
2404
-    echo $"`date`" >> "$dkms_tree/$module/$module_version/build/make.log"
2405
-    local the_make_command=`echo $make_command | sed "s/^make/make KERNELRELEASE=${kernelver_array[0]}/"`
2406
-
2407
-    invoke_command "$the_make_command >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background
2408
-
2409
-    # Make sure good return status
2410
-    if [ "$?" -ne 0 ]; then
2411
-        echo $"" >&2
2412
-        echo $"Error! Bad return status for module build on kernel: ${kernelver_array[0]} (${arch_array[0]})" >&2
2413
-        echo $"Consult the make.log in the build directory" >&2
2414
-        echo $"$dkms_tree/$module/$module_version/build/ for more information." >&2
2415
-        if grep -ic "gcc: Command not found" "$dkms_tree/$module/$module_version/build/make.log"; then
2416
-            echo $"" >&2
2417
-            echo $"DO YOU HAVE gcc INSTALLED???" >&2
2418
-        fi
2419
-        if grep -ic "make: command not found" "$dkms_tree/$module/$module_version/build/make.log"; then
2420
-            echo $"" >&2
2421
-            echo $"DO YOU HAVE make INSTALLED???" >&2
2422
-        fi
2423
-        report_build_problem
2424
-        exit 10
2425
-    fi
2426
+    echo $"DKMS make.log for $module-$module_version for kernel $kernelver ($arch)" >> "$dkms_tree/$module/$module_version/build/make.log"
2427
+    date >> "$dkms_tree/$module/$module_version/build/make.log"
2428
+    local the_make_command="${make_command/#make/make KERNELRELEASE=$kernelver}"
2429
+
2430
+    invoke_command "{ $the_make_command; } >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background || \
2431
+   report_build_problem 10 $"Bad return status for module build on kernel: $kernelver ($arch)" \
2432
+   $"Consult $dkms_tree/$module/$module_version/build/make.log for more information."
2433
 
2434
     # Make sure all the modules built successfully
2435
-    local count=0
2436
-    while [ "$count" -lt "${#built_module_name[@]}" ]; do
2437
-        if ! [ -e "${built_module_location[$count]}${built_module_name[$count]}$module_suffix" ]; then
2438
-            echo $"" >&2
2439
-            echo $"Error!  Build of ${built_module_name[$count]}$module_suffix failed for: ${kernelver_array[0]} (${arch_array[0]})" >&2
2440
-            echo $"Consult the make.log in the build directory" >&2
2441
-            echo $"$dkms_tree/$module/$module_version/build/ for more information." >&2
2442
-            report_build_problem
2443
-            exit 7
2444
-        fi
2445
-        count=$(($count+1))
2446
+    for ((count=0; count < ${#built_module_name[@]}; count++)); do
2447
+   [[ -e ${built_module_location[$count]}${built_module_name[$count]}$module_suffix ]] && continue
2448
+   report_build_problem 7 \
2449
+       $" Build of ${built_module_name[$count]}$module_suffix failed for: $kernelver ($arch)" \
2450
+       $"Consult the make.log in the build directory" \
2451
+       $"$dkms_tree/$module/$module_version/build/ for more information."
2452
     done
2453
     cd - >/dev/null
2454
 
2455
     # Build success, so create DKMS structure for a built module
2456
     mkdir -p "$base_dir/log"
2457
-    [ -n "$kernel_config" ] && cp -f "$kernel_config" "$base_dir/log/"
2458
+    [[ $kernel_config ]] && cp -f "$kernel_config" "$base_dir/log/"
2459
     mv -f "$dkms_tree/$module/$module_version/build/make.log" "$base_dir/log/make.log" 2>/dev/null
2460
 
2461
     # Save a copy of the new module
2462
     mkdir "$base_dir/module" >/dev/null
2463
-    local count=0
2464
-    while [ "$count" -lt "${#built_module_name[@]}" ]; do
2465
-        [ "${strip[$count]}" != "no" ] && strip -g "$dkms_tree/$module/$module_version/build/${built_module_location[$count]}${built_module_name[$count]}$module_suffix"
2466
-        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
2467
-        count=$(($count+1))
2468
+    for ((count=0; count < ${#built_module_name[@]}; count++)); do
2469
+   [[ ${strip[$count]} != no ]] && strip -g "$dkms_tree/$module/$module_version/build/${built_module_location[$count]}${built_module_name[$count]}$module_suffix"
2470
+   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
2471
     done
2472
 
2473
     # Run the post_build script
2474
-    if [ -n "$post_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_build" | sed 's/ .*//'` ]; then
2475
-        echo $""
2476
-        echo $"Running the post_build script:"
2477
-        $dkms_tree/$module/$module_version/source/$post_build
2478
-    fi
2479
+    run_build_script post_build "$post_build"
2480
 }
2481
 
2482
-function clean_build()
2483
+# Clean up after a build.
2484
+clean_build()
2485
 {
2486
     # Run the clean commands
2487
     cd "$dkms_tree/$module/$module_version/build"
2488
     invoke_command "$clean" "cleaning build area" background
2489
     cd - >/dev/null
2490
 
2491
-    if [[ ! ( $(VER ${kernelver_array[0]}) < $(VER 2.6.6) ) && \
2492
-       -d "$kernel_source_dir" && \
2493
-       ! -h "$kernel_source_dir" && \
2494
-       -z "$ksourcedir_fromcli" ]]; then
2495
-        echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
2496
-    elif [ -z "$no_clean_kernel" ]; then
2497
-        cd "$kernel_source_dir"
2498
-        [ -z "$kerneldoth_contents" ] && invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
2499
-        [ -n "$config_contents" ] && echo "$config_contents" > .config
2500
-        [ -n "$kerneldoth_contents" ] && echo "$kerneldoth_contents" > /boot/kernel.h
2501
-        cd - >/dev/null
2502
+    if [[ ! ( $(VER $kernelver) < $(VER 2.6.6) ) && \
2503
+       -d $kernel_source_dir && \
2504
+       ! -h $kernel_source_dir && \
2505
+       ! $ksourcedir_fromcli ]]; then
2506
+   echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
2507
+    elif [[ ! $no_clean_kernel ]]; then
2508
+   cd "$kernel_source_dir"
2509
+   [[ $kerneldoth_contents ]] || invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
2510
+   [[ $config_contents ]] || echo "$config_contents" > .config
2511
+   [[ $kerneldoth_contents ]] && echo "$kerneldoth_contents" > /boot/kernel.h
2512
+   cd - >/dev/null
2513
     fi
2514
 
2515
     # Clean the build directory
2516
     rm -rf "$dkms_tree/$module/$module_version/build/*"
2517
 }
2518
 
2519
-function build_module()
2520
+build_module()
2521
 {
2522
     prepare_build
2523
     do_build
2524
     clean_build
2525
     echo $""
2526
-    echo $"DKMS: build Completed."
2527
+    echo $"DKMS: build completed."
2528
 }
2529
 
2530
-function possible_dest_module_locations()
2531
+# Install a previously built module
2532
+# There are huge swaths of code here that special-case for various distros.
2533
+# They should be split into their own functions.
2534
+install_module()
2535
+{
2536
+    # If the module has not been built, try to build it first.
2537
+    is_module_built "$module" "$module_version" "$kernelver" "$arch" || build_module
2538
+    local base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch"
2539
+    check_module_args install
2540
+
2541
+    # Make sure that kernel exists to install into
2542
+    [[ -e $install_tree/$kernelver ]] || die 6 \
2543
+   $"The directory $install_tree/$kernelver doesn't exist." \
2544
+   $"You cannot install a module onto a non-existant kernel."
2545
+
2546
+    # Read the conf file
2547
+    read_conf_or_die "$kernelver" "$arch"
2548
+
2549
+    # Check that its not already installed (kernel symlink)
2550
+    is_module_installed "$module" "$module_version" "$kernelver" "$arch" && die 5 \
2551
+   $"This module/version combo is already installed" \
2552
+   $"for kernel: $kernelver ($arch)"
2553
+
2554
+    # if upgrading using rpm_safe_upgrade, go ahead and force the install
2555
+    # else we can wind up with the first half of an upgrade failing to install anything,
2556
+    # while the second half of the upgrade, the removal, then succeeds, leaving us with
2557
+    # nothing installed.
2558
+    [[ $rpm_safe_upgrade ]] && force="true"
2559
+
2560
+    # Save the original_module if one exists, none have been saved before, and this is the first module for this kernel
2561
+    local lib_tree="$install_tree/$kernelver"
2562
+    local count
2563
+    for ((count=0; count < ${#built_module_name[@]}; count++)); do
2564
+   echo $""
2565
+   echo $"${dest_module_name[$count]}$module_suffix:"
2566
+   # Check this version against what is already in the kernel
2567
+   check_version_sanity "$kernelver" "$arch" \
2568
+       "$obsolete_by" "${dest_module_name[$count]}" || continue
2569
+
2570
+   if ((count == 0)) && ! run_build_script pre_install "$pre_install" && \
2571
+       ! [[ $force ]]; then
2572
+       die 101 $"pre_install failed, aborting install." \
2573
+       $"You may override by specifying --force."
2574
+   fi
2575
+   local module_count=$(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f | wc -l | awk {'print $1'})
2576
+   echo $" - Original module"
2577
+   if [[ -L $dkms_tree/$module/kernel-$kernelver-$arch && \
2578
+       -e $dkms_tree/$module/original_module/$kernelver/$arch/${dest_module_name[$count]}$module_suffix ]]; then
2579
+       echo $"   - An original module was already stored during a previous install"
2580
+   elif ! [[ -L $dkms_tree/$module/kernel-$kernelver-$arch ]]; then
2581
+       local archive_pref1="$lib_tree/extra/${dest_module_name[$count]}$module_suffix"
2582
+       local archive_pref2="$lib_tree/updates/${dest_module_name[$count]}$module_suffix"
2583
+       local archive_pref3="$lib_tree${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
2584
+       local archive_pref4=""
2585
+       ((module_count == 1)) && archive_pref4=$(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f)
2586
+       local original_module=""
2587
+       local found_orginal=""
2588
+       for original_module in $archive_pref1 $archive_pref2 $archive_pref3 $archive_pref4; do
2589
+       [[ -f $original_module ]] || continue
2590
+       case "$running_distribution" in
2591
+           Debian* | Ubuntu* ) ;;
2592
+           *)
2593
+           echo $"   - Found $original_module"
2594
+           echo $"   - Storing in $dkms_tree/$module/original_module/$kernelver/$arch/"
2595
+           echo $"   - Archiving for uninstallation purposes"
2596
+           mkdir -p "$dkms_tree/$module/original_module/$kernelver/$arch"
2597
+           mv -f "$original_module" "$dkms_tree/$module/original_module/$kernelver/$arch/"
2598
+           ;;
2599
+       esac
2600
+       found_original="yes"
2601
+       break
2602
+       done
2603
+       if [[ ! $found_original ]] && ((module_count > 1)); then
2604
+       echo $"   - Multiple original modules exist but DKMS does not know which to pick"
2605
+       echo $"   - Due to the confusion, none will be considered during a later uninstall"
2606
+       elif [[ ! $found_original ]]; then
2607
+       echo $"   - No original module exists within this kernel"
2608
+       fi
2609
+   else
2610
+       echo $"   - This kernel never originally had a module by this name"
2611
+   fi
2612
+
2613
+   if ((module_count > 1)); then
2614
+       echo $" - Multiple same named modules!"
2615
+       echo $"   - $module_count named ${dest_module_name[$count]}$module_suffix in $lib_tree/"
2616
+       case "$running_distribution" in
2617
+       Debian* | Ubuntu* ) ;;
2618
+       *)
2619
+           echo $"   - All instances of this module will now be stored for reference purposes ONLY"
2620
+           echo $"   - Storing in $dkms_tree/$module/original_module/$kernelver/$arch/collisions/"
2621
+           ;;
2622
+       esac
2623
+       for module_dup in $(find $lib_tree -name ${dest_module_name[$count]}$module_suffix -type f); do
2624
+       dup_tree="${module_dup#$lib_tree}";
2625
+       dup_tree="${dup_tree/${dest_module_name[$count]}$module_suffix}"
2626
+       case "$running_distribution" in
2627
+       Debian* | Ubuntu* ) ;;
2628
+       *)
2629
+          echo $"     - Stored $module_dup"
2630
+          mkdir -p "$dkms_tree/$module/original_module/$kernelver/$arch/collisions/$dup_tree"
2631
+          mv -f $module_dup "$dkms_tree/$module/original_module/$kernelver/$arch/collisions/$dup_tree"
2632
+          ;;
2633
+       esac
2634
+       done
2635
+   fi
2636
+
2637
+   # Copy module to its location
2638
+   echo $" - Installation"
2639
+   echo $"   - Installing to $install_tree/$kernelver${dest_module_location[$count]}/"
2640
+   mkdir -p $install_tree/$kernelver${dest_module_location[$count]}
2641
+   cp -f "$base_dir/module/${dest_module_name[$count]}$module_suffix" "$install_tree/$kernelver${dest_module_location[$count]}/${dest_module_name[$count]}$module_suffix"
2642
+
2643
+    done
2644
+
2645
+    # Create the kernel-<kernelver> symlink to designate this version as active
2646
+    rm -f "$dkms_tree/$module/kernel-$kernelver-$arch" 2>/dev/null
2647
+    ln -s "$module_version/$kernelver/$arch" "$dkms_tree/$module/kernel-$kernelver-$arch" 2>/dev/null
2648
+
2649
+    # add to kabi-tracking
2650
+    if [[ ${weak_modules} ]]; then
2651
+   echo $"Adding any weak-modules"
2652
+   list_each_installed_module "$module" "$kernelver" "$arch" | ${weak_modules} --add-modules
2653
+    fi
2654
+
2655
+    # Run the post_install script
2656
+    run_build_script post_install "$post_install"
2657
+
2658
+    # Make modules.conf changes as necessary
2659
+    echo $""
2660
+    moduleconfig_add "$kernelver"
2661
+    etc_sysconfig_kernel_modify "add"
2662
+
2663
+    invoke_command "do_depmod $kernelver" "depmod" background || {
2664
+   do_uninstall "$kernelver" "$arch"
2665
+   die 6 $"Problems with depmod detected.  Automatically uninstalling this module." \
2666
+       $"DKMS: Install Failed (depmod problems).  Module rolled back to built state."
2667
+       exit 6
2668
+    }
2669
+
2670
+    # Do remake_initrd things (save old initrd)
2671
+    [[ $remake_initrd ]] && ! make_initrd "$kernelver" "$arch" && {
2672
+   do_uninstall "$kernelver" "$arch"
2673
+   die 7 $"Problems with mkinitrd detected.  Automatically uninstalling this module." \
2674
+       $"DKMS: Install Failed (mkinitrd problems).  Module rolled back to built state."
2675
+    }
2676
+    echo $""
2677
+    echo $"DKMS: install completed."
2678
+}
2679
+
2680
+# List each kernel object that has been installed for a particular module.
2681
+list_each_installed_module()
2682
+{
2683
+    # $1 = module
2684
+    # $2 = kernel version
2685
+    # $3 = arch
2686
+    local count
2687
+    local real_dest_module_location
2688
+    for ((count=0; count < ${#built_module_name[@]}; count++)); do
2689
+   real_dest_module_location="$(find_actual_dest_module_location $1 $count $2 $3)"
2690
+   echo "$install_tree/$2${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
2691
+    done
2692
+}
2693
+
2694
+is_module_added() {
2695
+    [[ $1 && $2 ]] || return 1
2696
+    [[ -d $dkms_tree/$1/$2 ]] || return 2
2697
+    [[ -L $dkms_tree/$1/$2/source || -d $dkms_tree/$1/$2/source ]];
2698
+}
2699
+
2700
+is_module_built() {
2701
+    [[ $1 && $2 && $3 && $4 ]] || return 1
2702
+    local d="$dkms_tree/$1/$2/$3/$4" m=''
2703
+    [[ -d $d/module ]] || return 1
2704
+    read_conf_or_die "$3" "$4" "$dkms_tree/$1/$2/source/dkms.conf"
2705
+    for m in "${dest_module_name[@]}"; do
2706
+   [[ -f $d/module/$m.ko || -f $d/module/$m.o ]] || return 1
2707
+    done
2708
+}
2709
+
2710
+# This assumes we have already checked to see if the module has been built.
2711
+_is_module_installed() {
2712
+    [[ $1 && $2 && $3 && $4 ]] || return 1
2713
+    local d="$dkms_tree/$1/$2/$3/$4"
2714
+    local k="$dkms_tree/$1/kernel-$3-$4"
2715
+    [[ -L $k && $(readlink -f $k) = $d ]]
2716
+}
2717
+
2718
+# This does not.
2719
+is_module_installed() { is_module_built "$@" && _is_module_installed "$@"; }
2720
+
2721
+maybe_add_module() (
2722
+    is_module_added "$1" "$2" && {
2723
+   echo $"Module $1/$2 already added."
2724
+   return 0
2725
+    }
2726
+    module="$1" module_version="$2" add_module
2727
+)
2728
+
2729
+maybe_build_module() (
2730
+    is_module_built "$1" "$2" "$3" "$4" && {
2731
+   echo $"Module $1/$2 already built for kernel $3/4"
2732
+   return 0
2733
+    }
2734
+    module="$1" module_version="$2" kernelver="$3" arch="$4" build_module
2735
+)
2736
+
2737
+maybe_install_module() (
2738
+    is_module_installed "$1" "$2" "$3" "$4" && {
2739
+   echo $"Module $1/$2 already installed on kernel $3/$4"
2740
+   return 0
2741
+    }
2742
+    module="$1" module_version="$2" kernelver="$3" arch="$4" install_module
2743
+)
2744
+
2745
+build_modules() {
2746
+    local i=0
2747
+    for ((i=0; i < ${#kernelver[@]}; i++)); do
2748
+   maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}"
2749
+    done
2750
+}
2751
+
2752
+install_modules() {
2753
+    local i=0
2754
+    for ((i=0; i < ${#kernelver[@]}; i++)); do
2755
+   maybe_install_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}"
2756
+    done
2757
+}
2758
+
2759
+check_module_exists() {
2760
+    is_module_added "$module" "$module_version" && return
2761
+    die 2 $"DKMS tree does not contain: $module-$module_version" \
2762
+   $"Build cannot continue without the proper tree."
2763
+}
2764
+
2765
+possible_dest_module_locations()
2766
 {
2767
     # $1 = count
2768
     # There are two places an installed module may really be:
2769
@@ -1624,13 +1514,13 @@
2770
 
2771
     local location
2772
     location[0]="${dest_module_location[$count]}"
2773
-    [ "${DEST_MODULE_LOCATION[$count]}" != "${dest_module_location[$count]}" ] && \
2774
+    [[ ${DEST_MODULE_LOCATION[$count]} != ${dest_module_location[$count]} ]] && \
2775
     location[1]="${DEST_MODULE_LOCATION[$count]}"
2776
 
2777
-    echo "${location[0]} ${location[1]}"
2778
+    echo "${location[@]}"
2779
 }
2780
 
2781
-function find_actual_dest_module_location()
2782
+find_actual_dest_module_location()
2783
 {
2784
     local module="$1"
2785
     local count="$2"
2786
@@ -1643,16 +1533,17 @@
2787
     dkms_owned="${dkms_tree}/${module}/kernel-${kernelver}-${arch}/module/${dest_module_name[$count]}${module_suffix}"
2788
 
2789
     for l in $locations; do
2790
-        installed="${install_tree}/${kernelver}${l}/${dest_module_name[${count}]}${module_suffix}"
2791
-        if [ -f "${installed}" ] && diff "${dkms_owned}" "${installed}" > /dev/null 2>&1; then
2792
-            echo "${l}"
2793
-            return 0
2794
-        fi
2795
+   installed="${install_tree}/${kernelver}${l}/${dest_module_name[${count}]}${module_suffix}"
2796
+   if [[ -f ${installed} ]] && diff "${dkms_owned}" "${installed}" > /dev/null 2>&1; then
2797
+       echo "${l}"
2798
+       return 0
2799
+   fi
2800
     done
2801
 
2802
 }
2803
 
2804
-function do_uninstall()
2805
+# Remove compiled DKMS modules from any kernels they are installed in.
2806
+do_uninstall()
2807
 {
2808
     # $1 = kernel version
2809
     # $2 = arch
2810
@@ -1668,440 +1559,347 @@
2811
 
2812
     # If kernel-<kernelver> symlink points to this module, check for original_module and put it back
2813
     local was_active=""
2814
-    readlink "$dkms_tree/$module/kernel-$1-$2"
2815
-    local kernel_symlink="$read_link"
2816
+    local kernel_symlink=$(readlink -f "$dkms_tree/$module/kernel-$1-$2")
2817
     local real_dest_module_location
2818
-    if [ "$kernel_symlink" == "$module_version/$1/$2" ]; then
2819
-        was_active="true"
2820
-        echo $""
2821
-        echo $"Status: Before uninstall, this module version was ACTIVE on this kernel."
2822
-        # remove kabi-tracking if last instance removed
2823
-        set_weak_modules
2824
-        if [ -n "${weak_modules}" ] &&
2825
-            [ `$0 status -m $module -v $module_version | grep -v "installed-weak" | grep -c "installed"` -eq 1 ]; then
2826
-            echo $"Removing any linked weak-modules"
2827
-            list_each_installed_module "$module" "$1" "$2" | ${weak_modules} --remove-modules
2828
-        fi
2829
-
2830
-        count=0
2831
-        while [ "$count" -lt "${#built_module_name[@]}" ]; do
2832
-            real_dest_module_location="$(find_actual_dest_module_location $module $count $1 $2)"
2833
-            echo $""
2834
-            echo $"${dest_module_name[$count]}$module_suffix:"
2835
-            echo $" - Uninstallation"
2836
-            echo $"   - Deleting from: $install_tree/$1${real_dest_module_location}/"
2837
-            rm -f "$install_tree/$1${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
2838
-            echo $" - Original module"
2839
-            if [ -e "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" ]; then
2840
-                case "$running_distribution" in
2841
-                Debian* | Ubuntu* ) ;;
2842
-                *)
2843
-                    echo $"   - Archived original module found in the DKMS tree"
2844
-                    echo $"   - Moving it to: $install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
2845
-                    mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
2846
-                    mv -f "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" \
2847
-                        "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/" 2>/dev/null
2848
-                    ;;
2849
-                esac
2850
-            else
2851
-                echo $"   - No original module was found for this module on this kernel."
2852
-                echo $"   - Use the dkms install command to reinstall any previous module version."
2853
-
2854
-                # Remove modules_conf entries from /etc/modules.conf if remake_initrd is set or if this is last instance removed
2855
-                if [ -n "$remake_initrd" ] || \
2856
-                    [ `$0 status -m $module -v $module_version | \
2857
-                    grep -c "installed"` -eq 1 ]; then
2858
-                    echo $""
2859
-                    moduleconfig_remove "$1"
2860
-                fi
2861
-            fi
2862
-            count=$(($count+1))
2863
-        done
2864
-        rm -f "$dkms_tree/$module/kernel-$1-$2"
2865
+    if [[ $kernel_symlink = $dkms_tree/$module/$module_version/$1/$2 ]]; then
2866
+   was_active="true"
2867
+   echo $""
2868
+   echo $"Status: Before uninstall, this module version was ACTIVE on this kernel."
2869
+   # remove kabi-tracking if last instance removed
2870
+   if [[ ${weak_modules} ]] && \
2871
+       (module_status_built $module $module_version |grep -q "installed"); then
2872
+       echo $"Removing any linked weak-modules"
2873
+       list_each_installed_module "$module" "$1" "$2" | ${weak_modules} --remove-modules
2874
+   fi
2875
+
2876
+   for ((count=0; count < ${#built_module_name[@]}; count++)); do
2877
+       real_dest_module_location="$(find_actual_dest_module_location $module $count $1 $2)"
2878
+       echo $""
2879
+       echo $"${dest_module_name[$count]}$module_suffix:"
2880
+       echo $" - Uninstallation"
2881
+       echo $"   - Deleting from: $install_tree/$1${real_dest_module_location}/"
2882
+       rm -f "$install_tree/$1${real_dest_module_location}/${dest_module_name[$count]}$module_suffix"
2883
+       echo $" - Original module"
2884
+       if [[ -e $dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix ]]; then
2885
+       case "$running_distribution" in
2886
+       Debian* | Ubuntu* ) ;;
2887
+       *)
2888
+           echo $"   - Archived original module found in the DKMS tree"
2889
+           echo $"   - Moving it to: $install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
2890
+           mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
2891
+           mv -f "$dkms_tree/$module/original_module/$1/$2/${dest_module_name[$count]}$module_suffix" \
2892
+           "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/" 2>/dev/null
2893
+           ;;
2894
+       esac
2895
+       else
2896
+       echo $"   - No original module was found for this module on this kernel."
2897
+       echo $"   - Use the dkms install command to reinstall any previous module version."
2898
+
2899
+       # Remove modules_conf entries from /etc/modules.conf if remake_initrd is set or if this is last instance removed
2900
+       if [[ $remake_initrd ]] || \
2901
+           (do_status $module $module_version | grep -q "installed"); then
2902
+           echo $""
2903
+           moduleconfig_remove "$1"
2904
+       fi
2905
+       fi
2906
+   done
2907
+   rm -f "$dkms_tree/$module/kernel-$1-$2"
2908
     else
2909
-        echo $""
2910
-        echo $"Status: This module version was INACTIVE for this kernel."
2911
+   echo $""
2912
+   echo $"Status: This module version was INACTIVE for this kernel."
2913
     fi
2914
 
2915
     # Run the post_remove script
2916
-    if [ -n "$post_remove" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$post_remove" | sed 's/ .*//'` ]; then
2917
-        echo $""
2918
-        echo $"Running the post_remove script:"
2919
-        $dkms_tree/$module/$module_version/source/$post_remove
2920
-    fi
2921
+    run_build_script post_remove "$post_remove"
2922
 
2923
     # Run depmod because we changed /lib/modules
2924
     invoke_command "do_depmod $1" "depmod" background
2925
 
2926
     # Do remake_initrd things (remake initrd)
2927
-    if [ -n "$remake_initrd" ] && [ -n "$was_active" ]; then
2928
-        remake_initrd "$1" "$2"
2929
-        if [ "$?" -ne 0 ]; then
2930
-            echo $""
2931
-            echo $"WARNING! WARNING! WARNING!"
2932
-            echo $"There was a problem remaking your initrd.  You must manually remake it"
2933
-            echo $"before booting into this kernel."
2934
-            echo $""
2935
-        fi
2936
+    if [[ $remake_initrd && $was_active ]] && ! make_initrd "$1" "$2"; then
2937
+   warn $"There was a problem remaking your initrd.  You must manually remake it" \
2938
+       $"before booting into this kernel."
2939
     fi
2940
 
2941
     # Delete the original_module if nothing for this kernel is installed anymore
2942
-    if [ -n "$was_active" ] && [ -d "$dkms_tree/$module/original_module/$1/$2" ] && ! [ -d "$dkms_tree/$module/original_module/$1/$2/collisions" ]; then
2943
-        echo $""
2944
-        echo $"Removing original_module from DKMS tree for kernel $1 ($2)"
2945
-        rm -rf "$dkms_tree/$module/original_module/$1/$2" 2>/dev/null
2946
-        [ -z "`find $dkms_tree/$module/original_module/$1/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/original_module/$1"
2947
-    elif [ -n "$was_active" ] && [ -d "$dkms_tree/$module/original_module/$1/$2/collisions" ]; then
2948
-        echo $""
2949
-        echo $"Keeping directory $dkms_tree/$module/original_module/$1/$2/collisions/"
2950
-        echo $"for your reference purposes.  Your kernel originally contained multiple"
2951
-        echo $"same-named modules and this directory is now where these are located."
2952
+    if [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2 && \
2953
+   ! -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then
2954
+   echo $""
2955
+   echo $"Removing original_module from DKMS tree for kernel $1 ($2)"
2956
+   rm -rf "$dkms_tree/$module/original_module/$1/$2" 2>/dev/null
2957
+   [[ $(find $dkms_tree/$module/original_module/$1/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module/$1"
2958
+    elif [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then
2959
+   echo $""
2960
+   echo $"Keeping directory $dkms_tree/$module/original_module/$1/$2/collisions/"
2961
+   echo $"for your reference purposes.  Your kernel originally contained multiple"
2962
+   echo $"same-named modules and this directory is now where these are located."
2963
     fi
2964
-    [ -z "`find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/original_module"
2965
+    [[ $(find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module"
2966
 
2967
     # Re-add entries to modules.conf if this module/version is still installed on another kernel
2968
     # But only do this if it was just ACTIVE on the kernel we just uninstalled from
2969
-    [ -n "$was_active" ] && [ -n "$remake_initrd" ] && $0 status -m $module -v $module_version | grep -q "installed" && moduleconfig_add "$1"
2970
+    [[ $was_active && $remake_initrd ]] && do_status $module $module_version | grep -q "installed" && moduleconfig_add "$1"
2971
 
2972
     echo $""
2973
-    echo $"DKMS: uninstall Completed."
2974
+    echo $"DKMS: uninstall completed."
2975
 }
2976
 
2977
-function uninstall_module ()
2978
+# Check our preconditions, and then let do_install do all the hard work.
2979
+uninstall_module()
2980
 {
2981
-    setup_kernels_arches "uninstall"
2982
-
2983
     # Check that the right arguments were passed
2984
-    if [ -z "$module" ] || [ -z "$module_version" ]; then
2985
-        echo $"" >&2
2986
-        echo $"Error! Invalid number of parameters passed." >&2
2987
-        echo $"Usage: uninstall -m <module> -v <module-version>" >&2
2988
-        echo $"   or: uninstall -m <module> -v <module-version> -k <kernel-version>" >&2
2989
-        exit 1
2990
-    fi
2991
+    check_module_args uninstall
2992
 
2993
     # Check that $module is in the dkms tree
2994
-    if ! [ -d "$dkms_tree/$module" ]; then
2995
-        echo $"" >&2
2996
-        echo $"Error! There are no instances of module: $module" >&2
2997
-        echo $"located in the DKMS tree." >&2
2998
-        exit 2
2999
-    fi
3000
+    [[ -d $dkms_tree/$module ]] || die 2 \
3001
+   $"There are no instances of module: $module" \
3002
+   $"located in the DKMS tree."
3003
 
3004
     # Make sure that its installed in the first place
3005
-    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
3006
-        echo $"" >&2
3007
-        echo $"Error! The module/version combo: $module-$module_version" >&2
3008
-        echo $"is not located in the DKMS tree." >&2
3009
-        exit 3
3010
-    fi
3011
+    [[ -d $dkms_tree/$module/$module_version ]] || die 3 \
3012
+   $"The module/version combo: $module-$module_version" \
3013
+   $"is not located in the DKMS tree."
3014
 
3015
     # Read the conf file
3016
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
3017
-    if [ "$?" -ne 0 ]; then
3018
-        echo $"" >&2
3019
-        echo $"Error! Bad conf file." >&2
3020
-        echo $"Your dkms.conf is not valid." >&2
3021
-        exit 4
3022
-    fi
3023
+    read_conf_or_die "$kernelver" "$arch"
3024
 
3025
     # Only do stuff if module/module version is currently installed
3026
-    readlink "$dkms_tree/$module/kernel-${kernelver_array[0]}-${arch_array[0]}"
3027
-    local kernel_symlink="$read_link"
3028
-    if [ "$kernel_symlink" == "$module_version/${kernelver_array[0]}/${arch_array[0]}" ]; then
3029
-        do_uninstall "${kernelver_array[0]}" "${arch_array[0]}"
3030
-    else
3031
-        echo $"" >&2
3032
-        echo $"Error! The module $module $module_version is not currently installed." >&2
3033
-        echo $"This module is not currently ACTIVE for kernel ${kernelver_array[0]} (${arch_array[0]})." >&2
3034
-        exit 5
3035
-    fi
3036
+    local kernel_symlink=$(readlink -f "$dkms_tree/$module/kernel-$kernelver-$arch")
3037
+    [[ $kernel_symlink = $dkms_tree/$module/$module_version/$kernelver/$arch ]] || die 5 \
3038
+       $"The module $module $module_version is not currently installed." \
3039
+       $"This module is not currently ACTIVE for kernel $kernelver ($arch)."
3040
+    do_uninstall "$kernelver" "$arch"
3041
 }
3042
 
3043
-function remove_module ()
3044
+# Unregister a DKMS module.  This uninstalls any installed modules along the way.
3045
+remove_module()
3046
 {
3047
-    # Check that the right arguments were passed (must be done before setup_kernels_arches)
3048
-    if [ -z "$module" ] || [ -z "$module_version" ] || $([ -z "${kernelver_array[0]}" ] && [ -z "$all" ]); then
3049
-        echo $"" >&2
3050
-        echo $"Error! Invalid number of parameters passed." >&2
3051
-        echo $"Usage: remove -m <module> -v <module-version> --all" >&2
3052
-        echo $"   or: remove -m <module> -v <module-version> -k <kernel-version>" >&2
3053
-        exit 1
3054
+    # Check that the right arguments were passed
3055
+    if [[ ! ($module && $module_version) || $kernels_arches_default  ]]; then
3056
+   die 1 $"Invalid number of parameters passed." \
3057
+       $"Usage: remove <module>/<module-version> --all" \
3058
+       $"   or: remove <module>/<module-version> -k <kernel-version>"
3059
     fi
3060
 
3061
-    setup_kernels_arches "remove"
3062
-
3063
     # Check that $module is in the dkms tree
3064
-    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
3065
-        echo $"" >&2
3066
-        echo $"Error! There are no instances of module: $module" >&2
3067
-        echo $"$module_version located in the DKMS tree." >&2
3068
-        exit 3
3069
-    fi
3070
-
3071
-    local i=0
3072
-    while [ $i -lt ${#kernelver_array[@]} ]; do
3073
-
3074
-        # make sure its there first before removing
3075
-        if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
3076
-            echo $"" >&2
3077
-            echo $"Error! There is no instance of $module $module_version" >&2
3078
-            echo $"for kernel ${kernelver_array[$i]} (${arch_array[$i]}) located in the DKMS tree." >&2
3079
-            exit 4
3080
-        fi
3081
-
3082
-        # Do --rpm_safe_upgrade check (exit out and don't do remove if inter-release RPM upgrade scenario occurs)
3083
-        if [ -n "$rpm_safe_upgrade" ]; then
3084
-            local pppid=`cat /proc/$PPID/status | grep PPid: | awk {'print $2'}`
3085
-            local time_stamp=`ps -o lstart --no-headers -p $pppid 2>/dev/null`
3086
-            for lock_file in `ls $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.* 2>/dev/null`; do
3087
-                lock_head=`head -n 1 $lock_file 2>/dev/null`
3088
-                lock_tail=`tail -n 1 $lock_file 2>/dev/null`
3089
-                if [ "$lock_head" == "$module-$module_version" ] && [ "$lock_tail" == "$time_stamp" ] && [ -n "$time_stamp" ]; then
3090
-                    echo $""
3091
-                    echo $"DKMS: Remove cancelled because --rpm_safe_upgrade scenario detected."
3092
-                    rm -f $lock_file
3093
-                    exit 0
3094
-                fi
3095
-            done
3096
-        fi
3097
-
3098
-        # Read the conf file
3099
-        read_conf "${kernelver_array[$i]}" "${arch_array[$i]}"
3100
-        if [ "$?" -ne 0 ]; then
3101
-            echo $"" >&2
3102
-            echo $"Error! Bad conf file." >&2
3103
-            echo $"File: $dkms_tree/$module/$module_version/source/dkms.conf does not represent" >&2
3104
-            echo $"a valid dkms.conf file." >&2
3105
-            exit 5
3106
-        fi
3107
-
3108
-        do_uninstall "${kernelver_array[$i]}" "${arch_array[$i]}"
3109
-
3110
-        # Delete the $kernel_version/$arch_used part of the tree
3111
-        rm -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}"
3112
-        [ -z "`find $dkms_tree/$module/$module_version/${kernelver_array[$i]}/* -maxdepth 0 -type d 2>/dev/null`" ] && rm -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}"
3113
-
3114
-        i=$(($i + 1))
3115
+    if ! [[ -d $dkms_tree/$module/$module_version ]]; then
3116
+   die 3 $"There are no instances of module: $module" \
3117
+       $"$module_version located in the DKMS tree."
3118
+    fi
3119
+
3120
+    local i
3121
+    for ((i=0; i < ${#kernelver[@]}; i++)); do
3122
+   # make sure its there first before removing
3123
+   if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
3124
+       die 4 $"There is no instance of $module $module_version" \
3125
+       $"for kernel ${kernelver[$i]} (${arch[$i]}) located in the DKMS tree."
3126
+   fi
3127
+
3128
+   # Do --rpm_safe_upgrade check (exit out and don't do remove if inter-release RPM upgrade scenario occurs)
3129
+   if [[ $rpm_safe_upgrade ]]; then
3130
+       local pppid=$(awk '/PPid:/ {print $2}' /proc/$PPID/status)
3131
+       local time_stamp=$(ps -o lstart --no-headers -p $pppid 2>/dev/null)
3132
+       for lock_file in $tmp_location/dkms_rpm_safe_upgrade_lock.$pppid.*; do
3133
+       [[ -f $lock_file ]] || continue
3134
+       lock_head=$(head -n 1 $lock_file 2>/dev/null)
3135
+       lock_tail=$(tail -n 1 $lock_file 2>/dev/null)
3136
+       [[ $lock_head = $module-$module_version && $time_stamp && $lock_tail = $time_stamp ]] || continue
3137
+       rm -f $lock_file
3138
+       die 0 $"DKMS: Remove cancelled because --rpm_safe_upgrade scenario detected."
3139
+       done
3140
+   fi
3141
+
3142
+   # Read the conf file
3143
+   read_conf_or_die "${kernelver[$i]}" "${arch[$i]}"
3144
+
3145
+   do_uninstall "${kernelver[$i]}" "${arch[$i]}"
3146
+
3147
+   # Delete the $kernel_version/$arch_used part of the tree
3148
+   rm -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}"
3149
+   [[ $(find $dkms_tree/$module/$module_version/${kernelver[$i]}/* \
3150
+       -maxdepth 0 -type d 2>/dev/null) ]] || \
3151
+       rm -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}"
3152
     done
3153
 
3154
     # Delete the $module_version part of the tree if no other $module_version/$kernel_version dirs exist
3155
-    if [ -z "$(find $dkms_tree/$module/$module_version/* -maxdepth 0 -type d 2>/dev/null | egrep -v "(build|tarball|driver_disk|rpm|deb|source)$")"  ]; then
3156
-        echo $""
3157
-        echo $"------------------------------"
3158
-        echo $"Deleting module version: $module_version"
3159
-        echo $"completely from the DKMS tree."
3160
-        echo $"------------------------------"
3161
-        rm -rf "$dkms_tree/$module/$module_version"
3162
-        echo $"Done."
3163
+    if ! find $dkms_tree/$module/$module_version/* -maxdepth 0 -type d 2>/dev/null | egrep -qv "(build|tarball|driver_disk|rpm|deb|source)$"; then
3164
+   echo $""
3165
+   echo $"------------------------------"
3166
+   echo $"Deleting module version: $module_version"
3167
+   echo $"completely from the DKMS tree."
3168
+   echo $"------------------------------"
3169
+   rm -rf "$dkms_tree/$module/$module_version"
3170
+   echo $"Done."
3171
     fi
3172
 
3173
     # Get rid of any remnant directories if necessary
3174
-    if [ `ls "$dkms_tree/$module" | wc -w | awk '{print $1}'` -eq 0 ]; then
3175
-        rm -rf "$dkms_tree/$module" 2>/dev/null
3176
+    if (($(ls "$dkms_tree/$module" | wc -w | awk '{print $1}') == 0)); then
3177
+   rm -rf "$dkms_tree/$module" 2>/dev/null
3178
 
3179
-        # Its now safe to completely remove references in /etc/sysconfig/kernel for SuSE
3180
-        etc_sysconfig_kernel_modify "delete"
3181
+   # Its now safe to completely remove references in /etc/sysconfig/kernel for SuSE
3182
+   etc_sysconfig_kernel_modify "delete"
3183
     fi
3184
 }
3185
 
3186
-function find_module_from_ko()
3187
+# Given a kernel object, figure out which DKMS module it is from.
3188
+find_module_from_ko()
3189
 {
3190
-    local depth="$1"
3191
-    local ko="$2"
3192
-    local basename_ko=$(basename "${ko}")
3193
+    local ko="$1"
3194
+    local basename_ko="${ko##*/}"
3195
     local module
3196
     local kernellink
3197
 
3198
-    for kernellink in $(find $dkms_tree -maxdepth $depth -mindepth $depth -name kernel-\* -type l); do
3199
-        module=$(echo "$kernellink" | awk -F / '{print $(NF-1)}')
3200
-        diff "$kernellink/module/${basename_ko}" "${ko}" >/dev/null 2>&1 && echo "$module" && break
3201
-    done
3202
-    echo ""
3203
-}
3204
-
3205
-# be careful.  string_array is global
3206
-declare -a string_array
3207
-function add_string_to_array_unique()
3208
-{
3209
-    # string="$1"
3210
-    local count=0
3211
-    local found=0
3212
-    while [ "$count" -lt "${#string_array[@]}" ]; do
3213
-        if [ "$1" == "${string_array[$count]}" ]; then
3214
-            found=1
3215
-            break
3216
-        fi
3217
-        count=$(($count + 1))
3218
-    done
3219
-    if [ "${found}" -eq 0 ]; then
3220
-        string_array[${#string_array[@]}]="$1"
3221
-    fi
3222
-}
3223
-
3224
-function print_string_array()
3225
-{
3226
-    local count=0
3227
-    while [ "$count" -lt "${#string_array[@]}" ]; do
3228
-        echo "${string_array[$count]}"
3229
-        count=$(($count + 1))
3230
+    for kernellink in "$dkms_tree"/*/kernel-*; do
3231
+   [[ -L $kernellink ]] || continue
3232
+   module=${kernellink#$dkms_tree/}
3233
+   module=${module%/kernel-*}
3234
+   diff "$kernellink/module/${basename_ko}" "${ko}" >/dev/null 2>&1 || continue
3235
+   rest=$(readlink $kernellink)
3236
+   echo "$module/$rest"
3237
+   return 0
3238
     done
3239
+    return 1
3240
 }
3241
 
3242
-function do_status_weak ()
3243
-{
3244
-    # these are the requested mod/ver/kern/arch fields
3245
-    local r_mod="$1"; shift
3246
-    local r_ver="$1"; shift
3247
-    local r_kern="$1"; shift
3248
-    local r_arch="$1"; shift
3249
-    local installedkern
3250
-    local ko
3251
-    local basename_ko
3252
-    local installed_ko
3253
-    local tree_ver
3254
-    local tree_kern
3255
-    local tree_arch
3256
-    local f
3257
-    local depth=1
3258
-    [ -z "$r_mod" ] && depth=2
3259
-    # recognize weak modules.  These are in $kern/weak-updates but are symlinks to another $kern/extra file.
3260
-
3261
-    for installedkern in $(find "$install_tree" -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
3262
-        for ko in $(find "$installedkern/weak-updates" -type l 2>/dev/null); do
3263
-            installedkernver=$(basename $installedkern)
3264
-            basename_ko=$(basename $ko)
3265
-            readlink $ko
3266
-            installed_ko="$read_link"
3267
-            if [ ! -e "$installed_ko" ]; then
3268
-                # dangling symlink, ouch, but is somebody else's problem so ignore it
3269
-                continue
3270
-            fi
3271
-            # remember, installed_ko is probably a relative path, so $kernelversion isn't present in its link
3272
-            # is $installed_ko in /var/lib/dkms as installed?  Find which module has it
3273
-            for f in $(find $dkms_tree/$r_mod -maxdepth $depth -mindepth $depth -name kernel-\* -type l 2>/dev/null); do
3274
-                if [ -z "$r_mod" ]; then
3275
-                    mod=$(find_module_from_ko "$depth" "$ko")
3276
-                else
3277
-                    mod="$r_mod"
3278
-                fi
3279
-                readlink "$f"
3280
-                tree_ver=$(echo "$read_link" | awk -F / '{print $1}')
3281
-                tree_kern=$(echo "$read_link" | awk -F / '{print $2}')
3282
-                tree_arch=$(echo "$read_link" | awk -F / '{print $3}')
3283
-                if diff $dkms_tree/$mod/$tree_ver/$tree_kern/$tree_arch/module/$basename_ko  \
3284
-                    $installed_ko >/dev/null 2>&1; then
3285
-                    if [ "$r_mod" == "$mod" -o -z "$r_mod" ] && \
3286
-                        [ "$r_ver" == "$tree_ver" -o -z "$r_ver" ] && \
3287
-                        [ "$r_kern" == "$installedkernver" -o -z "$r_kern" ] && \
3288
-                        [ "$r_arch" == "$tree_arch" -o -z "$r_arch" ]; then
3289
-                        add_string_to_array_unique "$mod, $tree_ver, $installedkernver, $tree_arch: installed-weak from $tree_kern"
3290
-                    fi
3291
-                fi
3292
-            done
3293
-        done
3294
-    done
3295
-    print_string_array
3296
-}
3297
-
3298
-do_status ()
3299
-{
3300
-    local mod="$1"; shift
3301
-    local ver="$1"; shift
3302
-    local kern="$1"; shift
3303
-    local arch="$1"; shift
3304
-    local tree_depth="$1"; shift
3305
-
3306
-    local next
3307
-    local working_dir
3308
-    [ $tree_depth -eq 0 ] && next="mod"  && working_dir="$dkms_tree"
3309
-    [ $tree_depth -eq 1 ] && next="ver"  && working_dir="$dkms_tree/$mod"
3310
-    [ $tree_depth -eq 2 ] && next="kern" && working_dir="$dkms_tree/$mod/$ver"
3311
-    [ $tree_depth -eq 3 ] && next="arch" && working_dir="$dkms_tree/$mod/$ver/$kern"
3312
-    [ $tree_depth -eq 4 ] && next="done" && working_dir="$dkms_tree/$mod/$ver/$kern/$arch"
3313
-
3314
-    if [ -n "${!next}" ] && [ "$next" != "done" ]; then
3315
-        do_status "$mod" "$ver" "$kern" "$arch" "$(($tree_depth + 1))"
3316
-    elif [ "$next" != "done" ]; then
3317
-        local keep_traversing="no"
3318
-        for directory in `find "$working_dir" -type d -maxdepth 1 -mindepth 1 2>/dev/null`; do
3319
-            local next_value=`echo $directory | sed "s#$working_dir/##"`
3320
-            if ! echo "build original_module tarball driver_disk rpm" | grep -q "$next_value\b"; then
3321
-                keep_traversing="yes"
3322
-                [ "$next" == "mod" ]  && mod=$next_value
3323
-                [ "$next" == "ver" ]  && ver=$next_value
3324
-                [ "$next" == "kern" ] && kern=$next_value
3325
-                [ "$next" == "arch" ] && arch=$next_value
3326
-                do_status "$mod" "$ver" "$kern" "$arch" "$(($tree_depth + 1))"
3327
-            fi
3328
-        done
3329
-    fi
3330
-
3331
-    if [ "$keep_traversing" == "no" ] && [ $tree_depth -eq 2 ] && [ -z "$arch" ] || [ "$next" == "done" ]; then
3332
-        local state="added" && stat_display="$mod, $ver:"
3333
-        [ -d "$working_dir/module" ] && state="built" && stat_display="$mod, $ver, $kern, $arch:"
3334
-        if [ -h "$dkms_tree/$mod/kernel-$kern-$arch" ]; then
3335
-            readlink "$dkms_tree/$mod/kernel-$kern-$arch"
3336
-            [ "$read_link" == "$ver/$kern/$arch" ] && state="installed"
3337
-        fi
3338
-
3339
-        if [ "$state" == "built" ] || [ "$state" == "installed" ]; then
3340
-            set_module_suffix "$kern"
3341
-            local extra_status=""
3342
-            conf="$dkms_tree/$mod/$ver/source/dkms.conf"
3343
-            read_conf "$kern" "$arch" "$conf"
3344
-            [ -d "$dkms_tree/$mod/original_module/$kern/$arch" ] && extra_status="(original_module exists)"
3345
-            local count=0
3346
-            local real_dest_module_location
3347
-            while [ "$count" -lt "${#dest_module_name[@]}" ]; do
3348
-                tree_mod="$dkms_tree/$mod/$ver/$kern/$arch/module/${dest_module_name[$count]}$module_suffix"
3349
-                if ! [ -e "$tree_mod" ]; then
3350
-                    extra_status="$extra_status (WARNING! Missing some built modules!)"
3351
-                elif [ "$state" == "installed" ]; then
3352
-                    real_dest_module_location="$(find_actual_dest_module_location $mod $count $kern $arch)"
3353
-                    if ! diff -q "$tree_mod" "$install_tree/$kern${real_dest_module_location}/${dest_module_name[$count]}$module_suffix" >/dev/null 2>&1; then
3354
-                        extra_status="$extra_status (WARNING! Diff between built and installed module!)"
3355
-                    fi
3356
-                fi
3357
-                count=$(($count+1))
3358
-            done
3359
-        fi
3360
-
3361
-        [ -d "$working_dir" ] && echo "$stat_display $state $extra_status"
3362
-    fi
3363
-}
3364
-
3365
-show_status ()
3366
-{
3367
-    setup_kernels_arches "status"
3368
-
3369
-    local j=0
3370
-    if [ ${#kernelver_array[@]} -eq 0 ]; then
3371
-        do_status "$module" "$module_version" "${kernelver_array[0]}" "${arch_array[0]}" 0
3372
-        do_status_weak "$module" "$module_version" "${kernelver_array[0]}" "${arch_array[0]}"
3373
-    else
3374
-        while [ $j -lt ${#kernelver_array[@]} ]; do
3375
-            do_status "$module" "$module_version" "${kernelver_array[$j]}" "${arch_array[$j]}" 0
3376
-            do_status_weak "$module" "$module_version" "${kernelver_array[$j]}" "${arch_array[$j]}"
3377
-            j=$(($j + 1))
3378
-        done
3379
+# Check to see if modules meeting the passed parameters are weak-installed.
3380
+# This function's calling convention is different from the usual DKMS status
3381
+# checking functions -- the kernel version we usually have is the one we are currently
3382
+# running on, not necessarily the one we compiled the module for.
3383
+module_status_weak() {
3384
+    # $1 = module, $2 = module version, $3 = kernel version weak installed to,
3385
+    # $4 = kernel arch, $5 = kernel version built for
3386
+    [[ $weak_modules ]] || return 1
3387
+    local weak_ko mod installed_ko f ret=1 oifs=$IFS
3388
+    local -a already_found
3389
+    for weak_ko in "$install_tree/"*/weak-updates/*; do
3390
+   [[ -e $weak_ko ]] || continue
3391
+   [[ -L $weak_ko ]] && installed_ko="$(readlink -f "$weak_ko")" || continue
3392
+   IFS=/ read m v k a < <(IFS=$oifs find_module_from_ko "$weak_ko") || continue
3393
+   kern=${weak_ko#$install_tree/}
3394
+   kern=${kern%/weak-updates/*}
3395
+   [[ $m = ${1:-*} && $v = ${2:-*} && $k = ${5:-*} && \
3396
+       $a = ${4:-*} && $kern = ${3:-*} ]] || \
3397
+       continue
3398
+   ret=0
3399
+   for f in "${already_found[@]}"; do
3400
+       [[ $f = $m/$v/$kern/$a/$k ]] && continue 2
3401
+   done
3402
+   already_found[${#already_found[@]}]="$m/$v/$kern/$a/$k"
3403
+   echo "installed-weak $m/$v/$kern/$a/$k"
3404
+    done
3405
+    return $ret
3406
+}
3407
+
3408
+# Print the requested status lines for weak-installed modules.
3409
+do_status_weak()
3410
+{
3411
+    local mvka m v k a kern status
3412
+    while read status mvka; do
3413
+   IFS=/ read m v k a kern <<< "$mvka"
3414
+   echo "$m, $v, $k, $a: installed-weak from $kern"
3415
+    done < <(module_status_weak "$@")
3416
+}
3417
+
3418
+# Spit out all the extra status information that people running DKMS are
3419
+# interested in, but that the DKMS internals do not usually care about.
3420
+module_status_built_extra() (
3421
+    set_module_suffix "$3"
3422
+    read_conf "$3" "$4" "$dkms_tree/$1/$2/source/dkms.conf"
3423
+    [[ -d $dkms_tree/$1/original_module/$3/$4 ]] && echo -n " (original_module exists)"
3424
+    for ((count=0; count < ${#dest_module_name[@]}; count++)); do
3425
+   tree_mod="$dkms_tree/$1/$2/$3/$4/module/${dest_module_name[$count]}$module_suffix"
3426
+   if ! [[ -e $tree_mod ]]; then
3427
+       echo -n " (WARNING! Missing some built modules!)"
3428
+   elif _is_module_installed "$@"; then
3429
+       real_dest="$(find_actual_dest_module_location "$1" $count "$3" "$4")"
3430
+       if ! diff -q "$tree_mod" "$install_tree/$3${real_dest}/${dest_module_name[$count]}$module_suffix" >/dev/null 2>&1; then
3431
+       echo -n " (WARNING! Diff between built and installed module!)"
3432
+       fi
3433
+   fi
3434
+    done
3435
+)
3436
+
3437
+# Return a list of all the modules that are either built or installed.
3438
+# This and module_status do some juggling of $IFS to ensure that
3439
+# we do not get word splitting where it would be inconvienent.
3440
+module_status_built() {
3441
+    local ret=1 directory ka k a state oifs="$IFS" IFS=''
3442
+    for directory in "$dkms_tree/$1/$2/"${3:-[0-9].*}/${4:-*}; do
3443
+   IFS="$oifs"
3444
+   ka="${directory#$dkms_tree/$1/$2/}"
3445
+   k="${ka%/*}"
3446
+   a="${ka#*/}"
3447
+   is_module_built "$1" "$2" "$k" "$a" || continue
3448
+   ret=0
3449
+   state="built"
3450
+   _is_module_installed "$1" "$2" "$k" "$a" && \
3451
+       state="installed"
3452
+   echo "$state $1/$2/$k/$a"
3453
+   IFS=''
3454
+    done
3455
+    IFS="$oifs"
3456
+    return $ret
3457
+}
3458
+
3459
+# Return the status of all modules that have been added, built, or installed.
3460
+module_status() {
3461
+    local oifs="$IFS" IFS='' mv m v directory ret=1
3462
+    for directory in "$dkms_tree/"${1:-*}/${2:-*}; do
3463
+   IFS="$oifs"
3464
+   mv="${directory#$dkms_tree/}"
3465
+   m="${mv%/*}"
3466
+   v="${mv#*/}"
3467
+   is_module_added "$m" "$v" || continue
3468
+   ret=0
3469
+   module_status_built "$m" "$v" "$3" "$4" || echo "added $m/$v"
3470
+   IFS=''
3471
+    done
3472
+    IFS="$oifs"
3473
+    return $ret
3474
+}
3475
+
3476
+# Print out the status in the format that people who call DKMS expect.
3477
+# Internal callers should use the module_status functions, as their output
3478
+# is easier to parse.
3479
+do_status() {
3480
+    local status mvka m v k a
3481
+    while read status mvka; do
3482
+   IFS=/ read m v k a <<< "$mvka"
3483
+   case $status in
3484
+       added) echo "$m, $v: $status";;
3485
+       built|installed) echo -n "$m, $v, $k, $a: $status"
3486
+       module_status_built_extra "$m" "$v" "$k" "$a"
3487
+       echo;;
3488
+   esac
3489
+    done < <(module_status "$@")
3490
+}
3491
+
3492
+# Show all our status in the format that external callers expect, even
3493
+# though it is slightly harder to parse.
3494
+show_status()
3495
+{
3496
+    local j state_array
3497
+    if ((${#kernelver[@]} == 0)); then
3498
+   do_status "$module" "$module_version" "$kernelver" "$arch"
3499
+   do_status_weak "$module" "$module_version" "$kernelver" "$arch"
3500
+    else
3501
+   for ((j=0; j < ${#kernelver[@]}; j++)); do
3502
+       do_status "$module" "$module_version" "${kernelver[$j]}" "${arch[$j]}"
3503
+       do_status_weak "$module" "$module_version" "${kernelver[$j]}" "${arch[$j]}"
3504
+   done
3505
     fi
3506
 }
3507
 
3508
-function create_temporary_trees ()
3509
+create_temporary_trees()
3510
 {
3511
-    if [ -n "$module" ] || [ -n "$module_version" ]; then
3512
-        return
3513
-    fi
3514
-
3515
-    [ -r dkms.conf ] || return
3516
+    [[ $module || $module_version || ! -r dkms.conf ]] && return 0
3517
 
3518
     . dkms.conf
3519
     module="$PACKAGE_NAME"
3520
     module_version="$PACKAGE_VERSION"
3521
 
3522
-    source_tree=`mktemp -d`
3523
-    dkms_tree=`mktemp -d`
3524
+    source_tree=$(mktemp_or_die -d)
3525
+    dkms_tree=$(mktemp_or_die -d)
3526
 
3527
     local source_tree_dir="$source_tree/$PACKAGE_NAME-$PACKAGE_VERSION"
3528
     mkdir -p "$source_tree_dir"
3529
@@ -2110,131 +1908,46 @@
3530
     temporary_trees_del_command="rm -rf $source_tree $dkms_tree"
3531
 }
3532
 
3533
-function delete_temporary_trees ()
3534
+delete_temporary_trees()
3535
 {
3536
+    [[ $temporary_trees_del_command ]] || return 0
3537
     $temporary_trees_del_command
3538
-    if [ -n "$temporary_trees_del_command" ]; then
3539
-        module=
3540
-        module_version=
3541
-        source_tree=
3542
-        dkms_tree=
3543
-        temporary_trees_del_command=
3544
-    fi
3545
+    module=
3546
+    module_version=
3547
+    source_tree=
3548
+    dkms_tree=
3549
+    temporary_trees_del_command=
3550
 }
3551
 
3552
-function in_temporary_trees ()
3553
-{
3554
-    [ -n "$temporary_trees_del_command" ]
3555
-    return $?
3556
-}
3557
+in_temporary_trees() { [[ $temporary_trees_del_command ]] ;}
3558
 
3559
 media_valid()
3560
 {
3561
-    if [ "$media" == "floppy" ] ||
3562
-        [ "$media" == "iso"   ] ||
3563
-        [ "$media" == "tar" ]; then
3564
-        return 0
3565
-    fi
3566
-    return 1
3567
-}
3568
-
3569
-make_driver_disk ()
3570
-{
3571
-    setup_kernels_arches "mkdriverdisk"
3572
-
3573
-    # Check that the right arguments were passed
3574
-    if [ -z "$module" ] || [ -z "$module_version" ] || [ -z "$distro" ] || [ -z "${kernelver_array[0]}" ]; then
3575
-        echo $"" >&2
3576
-        echo $"Error! Invalid number of parameters passed." >&2
3577
-        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver> [--media floppy|iso|tar]" >&2
3578
-        exit 1
3579
-    fi
3580
-
3581
-    # default to floppy media
3582
-    [ -z "$media" ] && media="floppy"
3583
-    media_valid
3584
-    if [ $? -eq 1 ]; then
3585
-        echo $"" >&2
3586
-        echo "$Error! Media $media is invalid." >&2
3587
-        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver> [--media floppy|iso|tar]" >&2
3588
-        exit 1
3589
-    fi
3590
-
3591
-    # Check that source symlink works
3592
-    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
3593
-        echo $"" >&2
3594
-        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
3595
-        echo $"Build cannot continue without the proper tree." >&2
3596
-        exit 2
3597
-    fi
3598
-
3599
-    # Confirm that distro is supported
3600
-    case "$distro" in
3601
-    redhat | redhat[12] | suse | UnitedLinux | ubuntu)
3602
-        ;;
3603
-    *)
3604
-        echo $"" >&2
3605
-        echo $"Error! Invalid distro argument. Currently, the distros" >&2
3606
-        echo $"supported are: redhat, redhat1, redhat2, suse, UnitedLinux" >&2
3607
-        echo $"               ubuntu" >&2
3608
-        exit 3
3609
-        ;;
3610
-    esac
3611
-
3612
-    # Read the conf file
3613
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
3614
-    if [ "$?" -ne 0 ]; then
3615
-        echo $"" >&2
3616
-        echo $"Error! Bad conf file." >&2
3617
-        echo $"Your dkms.conf is not valid." >&2
3618
-        exit 4
3619
-    fi
3620
-
3621
-    case "$distro" in
3622
-    redhat*)
3623
-        make_redhat_driver_disk
3624
-        ;;
3625
-    ubuntu)
3626
-        make_ubuntu_driver_disk
3627
-        ;;
3628
-    *)
3629
-        make_suse_driver_disk
3630
-        ;;
3631
-    esac
3632
+    local mrx='^(floppy|iso|tar)$'
3633
+    [[ $media =~ $mrx ]]
3634
 }
3635
 
3636
-
3637
 make_driver_disk_floppy()
3638
 {
3639
     local image_name="$1"
3640
     local source_dir="$2"
3641
     local file
3642
     local fs='ext2'
3643
-    case "$distro" in
3644
-    redhat*)
3645
-        fs='vfat'
3646
-        ;;
3647
-    esac
3648
+    [[ $distro = redhat* ]] && fs='vfat'
3649
 
3650
     rm -f "$image_name"
3651
     invoke_command "dd if=/dev/zero of=$image_name bs=$(($size/20))k count=20" "making a blank floppy image" background
3652
-    if [ "$fs" == 'vfat' ]; then
3653
-        invoke_command "mkdosfs $image_name" "mkdosfs" background
3654
-    elif [ "$fs" == 'ext2' ]; then
3655
-        invoke_command "mke2fs -F $image_name" "mke2fs" background
3656
-    fi
3657
+    case $fs in
3658
+   vfat) invoke_command "mkdosfs $image_name" "mkdosfs" background;;
3659
+   ext2) invoke_command "mke2fs -F $image_name" "mke2fs" background;;
3660
+    esac
3661
 
3662
-    local mntdir=`mktemp -d $tmp_location/dkms.XXXXXX`
3663
-    if [ -z "$mntdir" ]; then
3664
-        echo $""
3665
-        echo $"Error: Could not create a temporary directory, failing."
3666
-        return
3667
-    fi
3668
+    local mntdir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
3669
     invoke_command "mount -o loop -t $fs $image_name $mntdir >/dev/null 2>&1" "loopback mounting disk image"
3670
-    [ -d "$mntdir/lost+found" ] && rmdir "$mntdir/lost+found"
3671
+    [[ -d $mntdir/lost+found ]] && rmdir "$mntdir/lost+found"
3672
     invoke_command "cp -r $source_dir/* $mntdir/" "  copying files to floppy disk image"
3673
     invoke_command "umount $mntdir" "unmounting disk image"
3674
-    rm -rf $mntdir
3675
+    rm -rf "$mntdir"
3676
 }
3677
 
3678
 make_driver_disk_isotar()
3679
@@ -2243,129 +1956,95 @@
3680
     local image_name="$2"
3681
     local source_dir="$3"
3682
     local file
3683
-    if [ "$type" == "iso" ]; then
3684
-        invoke_command "mkisofs -v -r -J -pad -V $module -o $image_name ." "mkisofs" background
3685
-    elif [ "$type" == "tar" ]; then
3686
-        invoke_command "tar cvf $image_name ." "tar" background
3687
-    fi
3688
+    case $type in
3689
+   iso) invoke_command "mkisofs -v -r -J -pad -V $module -o $image_name ." "mkisofs" background;;
3690
+   tar) invoke_command "tar cvf $image_name ." "tar" background;;
3691
+    esac
3692
 }
3693
 
3694
 make_driver_disk_media()
3695
 {
3696
     echo "Copying files $2"
3697
 
3698
-    case "$media" in
3699
-    floppy*)
3700
-        make_driver_disk_floppy "$1" "$2"
3701
-        ;;
3702
-    iso*)
3703
-        make_driver_disk_isotar "iso" "$1" "$2"
3704
-        ;;
3705
-    tar*)
3706
-        make_driver_disk_isotar "tar" "$1" "$2"
3707
-        ;;
3708
+    case $media in
3709
+   floppy*) make_driver_disk_floppy "$1" "$2";;
3710
+   iso*) make_driver_disk_isotar "iso" "$1" "$2";;
3711
+   tar*) make_driver_disk_isotar "tar" "$1" "$2";;
3712
     esac
3713
 }
3714
 
3715
 driver_disk_suffix()
3716
 {
3717
-    local suffix
3718
-    case "$media" in
3719
-    floppy*)
3720
-        suffix="img"
3721
-        ;;
3722
-    iso*)
3723
-        suffix="iso"
3724
-        ;;
3725
-    tar*)
3726
-        suffix="tar"
3727
-        ;;
3728
+    case $media in
3729
+   floppy*) echo "img";;
3730
+   iso*) echo "iso";;
3731
+   tar*) echo "tar";;
3732
     esac
3733
-    echo $suffix
3734
 }
3735
 
3736
 make_redhat_driver_disk()
3737
 {
3738
+    local i count
3739
     # kludge to allow redhat1 driver disks with BOOT kernel modules (arch i386)
3740
-    if [ "$distro" == "redhat1" ] && [ "$multi_arch" == "true" ]; then
3741
-        local i=0
3742
-        local redhat1_okay="true"
3743
-        local other_arch=""
3744
-        while [ $i -lt ${#kernelver_array[@]} ]; do
3745
-            if [ "${arch_array[$i]}" != "i386" ] && [ "$other_arch" != "${arch_array[$i]}" ] && [ -n "$other_arch" ]; then
3746
-                redhat1_okay="false"
3747
-            elif [ "${arch_array[$i]}" != "i386" ] && [ "$other_arch" != "${arch_array[$i]}" ] && [ -z "$other_arch" ]; then
3748
-                other_arch="${arch_array[$i]}"
3749
-            fi
3750
-            i=$(($i+1))
3751
-        done
3752
-        if [ "$redhat1_okay" == "false" ]; then
3753
-            echo $"" >&2
3754
-            echo $"Error! You have specified a Red Hat version 1 driver disk, but have also"  >&2
3755
-            echo $"specified multiple architectures.  Version 1 does not support this." >&2
3756
-            echo $"Use 'redhat2' instead (only OSes >= RHEL3, FC1 support version 2)." >&2
3757
-            exit 3
3758
-        fi
3759
-    fi
3760
-
3761
-    if [ "$distro" == "redhat2" ] || [ "$multi_arch" == "true" ] && [ -z "$redhat1_okay" ]; then
3762
-        echo $"Creating Red Hat v2 driver disk (arch support)."
3763
-        echo $""
3764
-        local rhdd_filename="rhdd"
3765
-    else
3766
-        echo $"Creating Red Hat v1 driver disk."
3767
-        echo $""
3768
-        local rhdd_filename="rhdd-6.1"
3769
-    fi
3770
-
3771
-    cpioarchive_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
3772
-    if [ -z "$cpioarchive_dir_name" ]; then
3773
-        echo $""
3774
-        echo $"Error: Could not create a temporary directory, failing."
3775
-        return
3776
-    fi
3777
-
3778
-    local i=0
3779
-    while [ $i -lt ${#kernelver_array[@]} ]; do
3780
-        set_module_suffix "${kernelver_array[$i]}"
3781
-        local count=0
3782
-
3783
-        local dd_prefix="${kernelver_array[$i]}"
3784
-        [ "$distro" == "redhat2" ] && dd_prefix="${kernelver_array[$i]}/${arch_array[$i]}"
3785
-        [ "$multi_arch" == "true" ] && [ -z "$redhat1_okay" ] && dd_prefix="${kernelver_array[$i]}/${arch_array[$i]}"
3786
-
3787
-        while [ "$count" -lt "${#dest_module_name[@]}" ]; do
3788
-            if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
3789
-                echo $"" >&2
3790
-                echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
3791
-                echo $"Module/version must be in built state before making a driver disk." >&2
3792
-                rm -rf $cpioarchive_dir_name
3793
-                exit 5
3794
-            fi
3795
-            # FIXME: add check for KMP binary RPMs to include in the driver disk
3796
-            if [ -z "$kernel_version_list" ]; then
3797
-                kernel_version_list="kernel${kernelver_array[$i]}-${arch_array[$i]}"
3798
-            else
3799
-                kernel_version_list="$kernel_version_list-kernel${kernelver_array[$i]}-${arch_array[$i]}"
3800
-            fi
3801
-            mkdir -p $cpioarchive_dir_name/$dd_prefix
3802
-            echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix..."
3803
-            cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$cpioarchive_dir_name/$dd_prefix/"
3804
-
3805
-            modules_cgz_list="$dd_prefix/${dest_module_name[$count]}$module_suffix\n${modules_cgz_list}"
3806
-            count=$(($count+1))
3807
-        done
3808
+    if [[ $distro = redhat1 && $multi_arch = true ]]; then
3809
+   local redhat1_okay="true"
3810
+   local other_arch=""
3811
+   for ((i=0; i < ${#kernelver[@]}; i++)); do
3812
+       if [[ ${arch[$i]} != i386 && $other_arch != ${arch[$i]} && $other_arch ]]; then
3813
+       die 3 $"You have specified a Red Hat version 1 driver disk, but have also" \
3814
+           $"specified multiple architectures.  Version 1 does not support this." \
3815
+           $"Use 'redhat2' instead (only OSes >= RHEL3, FC1 support version 2)."
3816
+       elif [[ ${arch[$i]} != i386 && $other_arch != ${arch[$i]} && ! $other_arch ]]; then
3817
+       other_arch="${arch[$i]}"
3818
+       fi
3819
+   done
3820
+    fi
3821
+    if [ "$distro" == "redhat2" ]  && [ -z "$redhat1_okay" ]; then
3822
+   echo $"Creating Red Hat v2 driver disk (arch support)."
3823
+   echo $""
3824
+   local rhdd_filename="rhdd"
3825
+    elif [ "$distro" == "redhat3" ] && [ -z "$redhat1_okay" ]; then
3826
+        echo $"Creating Red Hat v3 driver disk."
3827
+   echo $""
3828
+   make_redhat3_driver_disk
3829
+   return
3830
+    else
3831
+   echo $"Creating Red Hat v1 driver disk."
3832
+   echo $""
3833
+   local rhdd_filename="rhdd-6.1"
3834
+    fi
3835
+
3836
+    cpioarchive_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
3837
+
3838
+    for ((i=0; i < ${#kernelver[@]}; i++)); do
3839
+   set_module_suffix "${kernelver[$i]}"
3840
+
3841
+   local dd_prefix="${kernelver[$i]}"
3842
+   [[ $distro = redhat2 ]] && dd_prefix="${kernelver[$i]}/${arch[$i]}"
3843
+   [[ $multi_arch = true && -z $redhat1_okay ]] && dd_prefix="${kernelver[$i]}/${arch[$i]}"
3844
+   maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}" || {
3845
+       rm -rf "$cpioarchive_dir_name"
3846
+       die 5 $"Cannot build $module/$module_version for redhat driver disk."
3847
+   }
3848
+   
3849
+   # FIXME: add check for KMP binary RPMs to include in the driver disk
3850
+   if [[ ! $kernel_version_list ]]; then
3851
+       kernel_version_list="kernel${kernelver[$i]}-${arch[$i]}"
3852
+   else
3853
+       kernel_version_list="$kernel_version_list-kernel${kernelver[$i]}-${arch[$i]}"
3854
+   fi
3855
+   mkdir -p $cpioarchive_dir_name/$dd_prefix
3856
+   for f in "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/"*"$module_suffix"; do
3857
+       [[ -f $f ]] || continue
3858
+       echo "Marking ${f#$dkms_tree/$module/$module_version/}..."
3859
+       cp "$f" "$cpioarchive_dir_name/$dd_prefix/"
3860
+       modules_cgz_list="$dd_prefix/${f##*/} ${modules_cgz_list}"
3861
+   done
3862
 
3863
-        i=$(($i + 1))
3864
     done
3865
 
3866
     # Create directory and necessary files
3867
-    driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
3868
-    if [ -z "$driver_disk_dir" ]; then
3869
-        echo $""
3870
-        echo $"Error: Could not create a temporary directory, failing."
3871
-        return
3872
-    fi
3873
+    driver_disk_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
3874
 
3875
     # Copy files for the driver disk (or warn if not present)
3876
     local files_for_driverdisk="modinfo disk-info modules.dep pcitable modules.pcimap pci.ids"
3877
@@ -2375,18 +2054,18 @@
3878
 
3879
     local files_into_driverdisk="modules.cgz $rhdd_filename modules.alias"
3880
     for file in $files_for_driverdisk; do
3881
-        if ! [ -e "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" ]; then
3882
-            echo $"Warning! File: $file not found in $dkms_tree/$module/$module_version/source/redhat_driver_disk/" >&2
3883
-        else
3884
-            files_into_driverdisk="$file $files_into_driverdisk"
3885
-            cp -f "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" "$driver_disk_dir/" 2>/dev/null
3886
-        fi
3887
+   if [[ -e $dkms_tree/$module/$module_version/source/redhat_driver_disk/$file ]]; then
3888
+       files_into_driverdisk="$file $files_into_driverdisk"
3889
+       cp -f "$dkms_tree/$module/$module_version/source/redhat_driver_disk/$file" "$driver_disk_dir/" 2>/dev/null
3890
+   else
3891
+       warn $"File: $file not found in $dkms_tree/$module/$module_version/source/redhat_driver_disk/"
3892
+   fi
3893
     done
3894
     echo "$module-$module_version driver disk" > "$driver_disk_dir/$rhdd_filename"
3895
 
3896
     # Make sure the kernel_version_list is not too long
3897
-    if [ `echo $kernel_version_list | wc -m | awk {'print $1'}` -gt 200 ]; then
3898
-        kernel_version_list="manykernels"
3899
+    if (( $(echo $kernel_version_list | wc -m | awk {'print $1'}) > 200 )); then
3900
+   kernel_version_list="manykernels"
3901
     fi
3902
 
3903
     local suffix="$(driver_disk_suffix)"
3904
@@ -2395,23 +2074,22 @@
3905
     echo $""
3906
     echo $"Creating driver disk on $media media:"
3907
     cd "$cpioarchive_dir_name"
3908
-    invoke_command "echo -e '$modules_cgz_list' | cpio -oH crc 2>/dev/null | gzip -9 > ./modules.cgz" "compressing modules.cgz" background
3909
+    invoke_command "echo '$modules_cgz_list' | cpio -oH crc 2>/dev/null | gzip -9 > ./modules.cgz" "compressing modules.cgz" background
3910
     cp -f ./modules.cgz "$driver_disk_dir/"
3911
 
3912
     # generate modules.alias file
3913
     # On 2.4 kernels and kernels with no aliases. this won't yield anything.
3914
     touch ./modules.alias
3915
-    for f in $(echo -e ${modules_cgz_list}); do
3916
-        module_wo_suffix=$(basename ${f} ${module_suffix})
3917
-        tmp_alias="./modules.alias.${module_wo_suffix}"
3918
-        f="./${f}"
3919
-        depmod -n ${f} 2>/dev/null | grep ^alias > ${tmp_alias}
3920
-        if [ -s ${tmp_alias} ]; then
3921
-            cat ${tmp_alias} >> ./modules.alias
3922
-        fi
3923
+    for f in ${modules_cgz_list}; do
3924
+   module_wo_suffix=$(basename ${f} ${module_suffix})
3925
+   tmp_alias="./modules.alias.${module_wo_suffix}"
3926
+   f="./${f}"
3927
+   depmod -n ${f} 2>/dev/null | grep ^alias > ${tmp_alias}
3928
+   if [[ -s ${tmp_alias} ]]; then
3929
+       cat "${tmp_alias}" >> ./modules.alias
3930
+   fi
3931
     done
3932
-    [ -e ./modules.alias ] && cp -f ./modules.alias "$driver_disk_dir/"
3933
-
3934
+    [[ -e ./modules.alias ]] && cp -f ./modules.alias "$driver_disk_dir/"
3935
     # FIXME: add rpms/ directory, copy in KMP RPMs, run createrepo --pretty
3936
 
3937
     cd - >/dev/null
3938
@@ -2428,59 +2106,80 @@
3939
     echo $""
3940
     echo $"Disk image location: $image_dir/$image_name"
3941
     echo $""
3942
-    echo $"DKMS: mkdriverdisk Completed."
3943
+    echo $"DKMS: mkdriverdisk completed."
3944
+}
3945
+
3946
+make_driver_disk()
3947
+{
3948
+    # Check that the right arguments were passed
3949
+    if ! [[ $module && $module_version && $distro && $kernelver ]]; then
3950
+   die 1 $"Invalid number of parameters passed." \
3951
+   $"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver> [--media floppy|iso|tar]"
3952
+    fi
3953
+
3954
+    # default to floppy media
3955
+    [[ $media ]] || media="floppy"
3956
+    if ! media_valid; then
3957
+   die 1 $"Media $media is invalid." \
3958
+       $"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver> [--media floppy|iso|tar]"
3959
+    fi
3960
+
3961
+    # Check that source symlink works
3962
+    check_module_exists
3963
+
3964
+    # Confirm that distro is supported
3965
+    case $distro in
3966
+   redhat | redhat[123] | suse | UnitedLinux | ubuntu) ;;
3967
+   *) die 3 $"Invalid distro argument. Currently, the distros" \
3968
+       $"supported are: redhat, redhat1, redhat2, redhat3, suse, UnitedLinux" \
3969
+       $"               ubuntu";;
3970
+    esac
3971
+
3972
+    # Read the conf file
3973
+    read_conf_or_die "$kernelver" "$arch"
3974
+
3975
+    case $distro in
3976
+   redhat*) make_redhat_driver_disk;;
3977
+   ubuntu) make_ubuntu_driver_disk;;
3978
+   *) make_suse_driver_disk;;
3979
+    esac
3980
 }
3981
 
3982
 find_external_dependencies()
3983
 {
3984
-    local mod deps
3985
-    local count=0
3986
-    local i=0
3987
+    local mod count i
3988
+    local -a deps
3989
 
3990
     # find all module dependencies
3991
-    while [ "$count" -lt "${#dest_module_name[@]}" ]; do
3992
-        i=0
3993
-        while [ "$i" -lt "${#kernelver_array[@]}" ]; do
3994
-            set_module_suffix "${kernelver_array[$i]}"
3995
-            mod="$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix"
3996
-            deps=(${deps[@]} $(modinfo "$mod" | sed -n 's/,/ /g; s/^depends: *//p'))
3997
-            i=$(($i+1))
3998
-        done
3999
-        count=$(($count+1))
4000
+    for ((count=0; count < ${#dest_module_name[@]}; count++)); do
4001
+   for ((i=0; i < ${#kernelver[@]}; i++)); do
4002
+       set_module_suffix "${kernelver[$i]}"
4003
+       mod="$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix"
4004
+       deps=(${deps[@]} $(modinfo "$mod" | sed -n 's/,/ /g; s/^depends: *//p'))
4005
+   done
4006
     done
4007
 
4008
     # prune internally satisfied dependencies
4009
-    i=0
4010
-    while [ "$i" -lt "${#deps[@]}" ]; do
4011
-        for mod in ${dest_module_name[@]}; do
4012
-            [ "${deps[i]}" == "$mod" ] && deps[i]=
4013
-        done
4014
-        i=$(($i+1))
4015
+
4016
+    for ((i=0; i < ${#deps[@]}; i++)); do
4017
+   for mod in ${dest_module_name[@]}; do
4018
+       [[ ${deps[i]} = $mod ]] && deps[i]=
4019
+   done
4020
     done
4021
 
4022
-    i=0
4023
-    while [ "$i" -lt "${#deps[@]}" ]; do
4024
-        echo "${deps[i]}"
4025
-        i=$(($i+1))
4026
+    for dep in "${deps[@]}"; do
4027
+   echo $dep
4028
     done | sort -u
4029
 }
4030
 
4031
 make_suse_driver_disk()
4032
 {
4033
-    if [ -z "$release" ]; then
4034
-        echo $"" >&2
4035
-        echo $"Error! Invalid number of parameters passed for suse/UnitedLinux driver disk." >&2
4036
-        echo $"Usage: mkdriverdisk -d <distro> -m <module> -v <module-version> -k <kernelver>" >&2
4037
-        echo $"                    -r <release-number>" >&2
4038
-        exit 3
4039
-    fi
4040
+    [[ $release ]] || die 3 \
4041
+   $"Invalid number of parameters passed for suse/UnitedLinux driver disk." \
4042
+   $"Usage: mkdriverdisk <module>/<module-version> -d <distro> -k <kernelver>" \
4043
+   $"                    -r <release-number>"
4044
 
4045
-    local driver_disk_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
4046
-    if [ -z "$driver_disk_dir" ]; then
4047
-        echo $""
4048
-        echo $"Error: Could not create a temporary directory, failing."
4049
-        return
4050
-    fi
4051
+    local driver_disk_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
4052
     local suffix="$(driver_disk_suffix)"
4053
     local image_dir="$dkms_tree/$module/$module_version/driver_disk"
4054
     local image_name="$module-$module_version-$distro-$release-dd.$suffix"
4055
@@ -2491,112 +2190,100 @@
4056
     local deps="$(find_external_dependencies)"
4057
 
4058
     local offset=0
4059
-    if [ -n "${deps[*]}" ]; then
4060
-        # reserve a place for dependencies
4061
-        local offset=1
4062
-    fi
4063
-
4064
-    local count=0
4065
-    while [ "$count" -lt "${#dest_module_name[@]}" ]; do
4066
-
4067
-        local i=0
4068
-        local topdir=`printf "%02d" $(($count+1+offset))`
4069
-        while [ "$i" -lt "${#kernelver_array[@]}" ]; do
4070
-            set_module_suffix "${kernelver_array[$i]}"
4071
-
4072
-            if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
4073
-                echo $"" >&2
4074
-                echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
4075
-                echo $"Module/version must be in built state before making a driver disk." >&2
4076
-                rm -rf $temp_dir_name
4077
-                exit 5
4078
-            fi
4079
-                        # FIXME: add check for KMP binary RPMs to include in the driver disk
4080
-            suse_arch=${arch_array[$i]}
4081
-            case $suse_arch in
4082
-            i?86)
4083
-                    suse_arch=i386
4084
-                    ;;
4085
-            esac
4086
-
4087
-            echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/modules/${dest_module_name[$count]}$module_suffix..."
4088
-            mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver_array[$i]}${dest_module_location[$count]}"
4089
-            cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver_array[$i]}${dest_module_location[$count]}/"
4090
-
4091
-            case ${kernelver_array[$i]} in
4092
-                *-default)
4093
-                    mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
4094
-                    cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
4095
-                    ;;
4096
-            esac
4097
-
4098
-            # create directory for dependency information
4099
-            [ -n "${deps[*]}" ] && mkdir -p "$driver_disk_dir/01/linux/$distro/$suse_arch-$release/modules"
4100
-
4101
-            i=$(($i+1))
4102
-        done
4103
-
4104
-        # ---
4105
-        for arch_release in `find $driver_disk_dir/$topdir -maxdepth 1 -mindepth 1 -type d | sed "s#$driver_disk_dir\/$topdir\/##"`; do
4106
-            cd "$driver_disk_dir/$topdir/$arch_release/install/"
4107
-            invoke_command "tar cvzf update.tar.gz lib/" "making update.tar.gz for $arch_release" background
4108
-            cd - >/dev/null
4109
-
4110
-            mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install"
4111
-            mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/modules"
4112
-
4113
-            echo $"  copying update.tar.gz for $arch_release to disk image..."
4114
-            cp -f "$driver_disk_dir/$topdir/$arch_release/install/update.tar.gz" "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/"
4115
-
4116
-            i=0
4117
-            postkernels=
4118
-            archtest=`echo ${arch_release} | sed 's/-.*//'`
4119
-            while [ "$i" -lt "${#kernelver_array[@]}" ]; do
4120
-                if [ "${arch_array[$i]}" = "${archtest}" ]; then
4121
-                    postkernels="${postkernels} ${kernelver_array[$i]}"
4122
-                fi
4123
-                i=$(($i+1))
4124
-            done
4125
-
4126
-            if [ -n "${postkernels}" ]; then
4127
-                dstfile="$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/update.post"
4128
-                echo $"  creating update.post for $arch_release..."
4129
-                (cat << EOF
4130
+    # reserve a place for dependencies
4131
+    [[ ${deps[@]} ]] && offset=1
4132
+    
4133
+    local count
4134
+    for ((count=0; count < ${#dest_module_name[@]}; count++)); do
4135
+   local i
4136
+   local topdir=$(printf "%02d" $(($count+1+offset)))
4137
+   for ((i=0; i < ${#kernelver[@]}; i++)); do
4138
+       set_module_suffix "${kernelver[$i]}"
4139
+
4140
+       if ! [[ -e $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/${dest_module_name[$count]}$module_suffix ]]; then
4141
+       rm -rf $temp_dir_name
4142
+       die 5 \
4143
+           $"Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver[$i]} (${arch[$i]})." \
4144
+           $"Module/version must be in built state before making a driver disk."
4145
+       fi
4146
+       # FIXME: add check for KMP binary RPMs to include in the driver disk
4147
+       suse_arch=${arch[$i]}
4148
+       case $suse_arch in
4149
+       i?86) suse_arch=i386;;
4150
+       esac
4151
+
4152
+       echo "Marking ${kernelver[$i]}/${arch[$i]}/modules/${dest_module_name[$count]}$module_suffix..."
4153
+       mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/install/lib/modules/${kernelver[$i]}${dest_module_location[$count]}"
4154
+       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]}/"
4155
+
4156
+       case ${kernelver[$i]} in
4157
+       *-default)
4158
+           mkdir -p "$driver_disk_dir/$topdir/$suse_arch-$release/modules/"
4159
+           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/"
4160
+           ;;
4161
+       esac
4162
+
4163
+       # create directory for dependency information
4164
+       [[ ${deps[@]} ]] && mkdir -p "$driver_disk_dir/01/linux/$distro/$suse_arch-$release/modules"
4165
+
4166
+   done
4167
+
4168
+   # ---
4169
+   for arch_release in $(find $driver_disk_dir/$topdir -maxdepth 1 -mindepth 1 -type d | sed "s#$driver_disk_dir\/$topdir\/##"); do
4170
+       cd "$driver_disk_dir/$topdir/$arch_release/install/"
4171
+       invoke_command "tar cvzf update.tar.gz lib/" "making update.tar.gz for $arch_release" background
4172
+       cd - >/dev/null
4173
+
4174
+       mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install"
4175
+       mkdir -p "$driver_disk_dir/$topdir/linux/$distro/$arch_release/modules"
4176
+
4177
+       echo $"  copying update.tar.gz for $arch_release to disk image..."
4178
+       cp -f "$driver_disk_dir/$topdir/$arch_release/install/update.tar.gz" "$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/"
4179
+
4180
+       postkernels=
4181
+       archtest=${arch_release/-*}
4182
+       for ((i=0; i<${#kernelver[@]}; i++)); do
4183
+       [[ ${arch[$i]} = ${archtest} ]] && \
4184
+           postkernels="${postkernels} ${kernelver[$i]}"
4185
+       done
4186
+
4187
+       if [[ ${postkernels} ]]; then
4188
+       dstfile="$driver_disk_dir/$topdir/linux/$distro/$arch_release/install/update.post"
4189
+       echo $"  creating update.post for $arch_release..."
4190
+       (cat << EOF
4191
 #!/bin/sh
4192
 
4193
-EOF
4194
-                 echo "kernlist=\"${postkernels}\""
4195
-                 echo
4196
-                 echo 'for kernel in ${kernlist}; do'
4197
-                 echo '    if [ -e /boot/System.map-${kernel} ]; then'
4198
-                 echo '        depmod -a -F /boot/System.map-${kernel} ${kernel}'
4199
-                 echo '    fi'
4200
-                 echo 'done'
4201
-                ) > ${dstfile}
4202
-                chmod a+x ${dstfile}
4203
-            fi
4204
+kernlist="${postkernels}"
4205
 
4206
-            if [ -d "$driver_disk_dir/$topdir/$arch_release/modules/" ]; then
4207
-                echo $"  copying kernel modules for installation kernel to disk image..."
4208
-                cp -f $driver_disk_dir/$topdir/$arch_release/modules/* $driver_disk_dir/$topdir/linux/$distro/$arch_release/modules/ 2>/dev/null
4209
-            else
4210
-                echo $"  Warning! No kernel modules found for -default kernel."
4211
-            fi
4212
+for kernel in \${kernlist}; do
4213
+    if [ -e /boot/System.map-\${kernel} ]; then
4214
+   depmod -a -F /boot/System.map-\${kernel} \${kernel}
4215
+    fi
4216
+done
4217
 
4218
-            rm -fr "$driver_disk_dir/$topdir/$arch_release"
4219
-        done
4220
+EOF
4221
+       ) > ${dstfile}
4222
+       chmod a+x ${dstfile}
4223
+       fi
4224
+
4225
+       if [[ -d $driver_disk_dir/$topdir/$arch_release/modules/ ]]; then
4226
+       echo $"  copying kernel modules for installation kernel to disk image..."
4227
+       cp -f $driver_disk_dir/$topdir/$arch_release/modules/* $driver_disk_dir/$topdir/linux/$distro/$arch_release/modules/ 2>/dev/null
4228
+       else
4229
+       warn $"No kernel modules found for -default kernel."
4230
+       fi
4231
 
4232
-        # ---
4233
-        count=$(($count+1))
4234
+       rm -fr "$driver_disk_dir/$topdir/$arch_release"
4235
+   done
4236
     done
4237
 
4238
     local dir
4239
-    if [ -n "${deps[*]}" ]; then
4240
-        for dir in "$driver_disk_dir/01/linux/$distro/"*"/modules"; do
4241
-            for dep in ${deps[@]}; do
4242
-                echo $dep >> "$dir/module.order"
4243
-            done
4244
-        done
4245
+    if [[ ${deps[@]} ]]; then
4246
+   for dir in "$driver_disk_dir/01/linux/$distro/"*"/modules"; do
4247
+       for dep in "${deps[@]}"; do
4248
+       echo $dep >> "$dir/module.order"
4249
+       done
4250
+   done
4251
     fi
4252
 
4253
     # FIXME: add suse-equivalent rpms/ directory, copy in KMP RPMs, run createrepo --pretty
4254
@@ -2611,7 +2298,7 @@
4255
     echo $""
4256
     echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
4257
     echo $""
4258
-    echo $"DKMS: mkdriverdisk Completed."
4259
+    echo $"DKMS: mkdriverdisk completed."
4260
 }
4261
 
4262
 make_ubuntu_driver_disk()
4263
@@ -2620,58 +2307,40 @@
4264
     local image_dir="$dkms_tree/$module/$module_version/driver_disk"
4265
     local image_name="$module-$module_version-$distro-dd.$suffix"
4266
 
4267
-    local tempdir=`mktemp -d $tmp_location/dkms.XXXXXX`
4268
-    if [ -z "$tempdir" ]; then
4269
-        echo $""
4270
-        echo $"Error: Could not create a temporary directory, failing."
4271
-        return
4272
-    fi
4273
+    local tempdir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
4274
 
4275
    # Check that the dh_make command is present
4276
    if ! which dpkg-deb >/dev/null 2>&1 ; then
4277
-        echo $"" >&2
4278
-        echo $"Error! dpkg-deb not present." >&2
4279
-        echo $"Install the dpkg-dev package." >&2
4280
-        exit 1
4281
+   die 1 $"dpkg-deb not present." \
4282
+       $"Install the dpkg-dev package."
4283
    fi
4284
 
4285
-   local i=0
4286
-   while [ $i -lt ${#kernelver_array[@]} ]; do
4287
-      set_module_suffix "${kernelver_array[$i]}"
4288
+   local i
4289
+   for ((i=0; i < ${#kernelver[@]}; i++)); do
4290
+      set_module_suffix "${kernelver[$i]}"
4291
       # Driver disks only recognize i386 as package arch
4292
-      local arch=$(echo ${arch_array[$i]} | sed -e 's/i.86/i386/')
4293
-      local kvers=$(echo ${kernelver_array[$i]} | sed -e 's/[-_].*//')
4294
+      local karch=${arch[$i]/i?86/i386}
4295
+      local kvers=${kernelver[$i]/-/_}; kvers=${kvers%%_*}
4296
        # ubuntu-drivers/<kver>/*_<debarch>.deb
4297
       local dd_prefix="ubuntu-drivers/$kvers"
4298
-      local dd_suffix="_${arch}.deb"
4299
-      local count=0
4300
-      while [ "$count" -lt "${#dest_module_name[@]}" ]; do
4301
-        if ! [ -e "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" ]; then
4302
-            echo $"" >&2
4303
-            echo $"Error! Cannot find module ${dest_module_name[$count]}$module_suffix for kernel ${kernelver_array[$i]} (${arch_array[$i]})." >&2
4304
-            echo $"Module/version must be in built state before making a driver disk." >&2
4305
-            rm -rf "$tempdir"
4306
-            exit 5
4307
-         fi
4308
-
4309
-         mkdir -p "$tempdir/$dd_prefix"
4310
-         echo "Marking ${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix..."
4311
-
4312
-         local deb_dir="$tempdir/$dd_prefix/debian"
4313
-         local deb_lib_dir="$deb_dir/lib/modules/${kernelver_array[$i]}/updates/dkms"
4314
-         mkdir -p "$deb_lib_dir"
4315
-         cp "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}/module/${dest_module_name[$count]}$module_suffix" "$deb_lib_dir"
4316
-         count=$(($count+1))
4317
-       done
4318
-
4319
-       pushd "$deb_dir" > /dev/null 2>&1
4320
-       mkdir DEBIAN
4321
-       cat > DEBIAN/control <<EOF
4322
-Package: ${module}-modules-${kernelver_array[$i]}
4323
+      local dd_suffix="_${karch}.deb"
4324
+      maybe_build_module "$module" "$module_version" "${kernelver[$i]}" "${arch[$i]}" || {
4325
+     rm -rf "$tempdir"
4326
+     die 5 $"Unable to build $module/$module_version for Ubuntu driver disk."
4327
+      }
4328
+      mkdir -p "$tempdir/$dd_prefix"
4329
+      local deb_dir="$tempdir/$dd_prefix/debian"
4330
+      local deb_lib_dir="$deb_dir/lib/modules/${kernelver[$i]}/updates/dkms"
4331
+      mkdir -p "$deb_lib_dir"
4332
+      cp "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}/module/"*"$module_suffix" "$deb_lib_dir"
4333
+      pushd "$deb_dir" > /dev/null 2>&1
4334
+      mkdir DEBIAN
4335
+      cat > DEBIAN/control <<EOF
4336
+Package: ${module}-modules-${kernelver[$i]}
4337
 Version: ${module_version}-1
4338
 Section: misc
4339
 Priority: optional
4340
-Architecture: $arch
4341
+Architecture: $karch
4342
 Depends:
4343
 Maintainer: DKMS <dkms-devel@dell.com>
4344
 Description: DKMS packaged binary driver update
4345
@@ -2683,19 +2352,17 @@
4346
        # Generate the DEBIAN/preinst file.
4347
        # This is tricky as we need some parts evaluated now
4348
        # and some parts evaluated at runtime
4349
-       echo '#!/bin/bash' > DEBIAN/preinst
4350
-       echo -n '[ "$(uname -r)" == ' >> DEBIAN/preinst
4351
-       echo -n "\"${kernelver_array[$i]}\"" >> DEBIAN/preinst
4352
-       echo  ' ] || exit 1' >> DEBIAN/preinst
4353
-       echo 'exit 0' >> DEBIAN/preinst
4354
-
4355
+cat >DEBIAN/preinst <<EOF
4356
+#!/bin/bash
4357
+[[ \$(uname -r) = ${kernelver[$i]} ]] || exit 1
4358
+exit 0
4359
+EOF
4360
        chmod 0775 DEBIAN/preinst
4361
        cd "$tempdir/$dd_prefix"
4362
        dpkg-deb --build debian
4363
-       mv debian.deb "${module}_${module_version}-${kernelver_array[$i]}${dd_suffix}"
4364
+       mv debian.deb "${module}_${module_version}-${kernelver[$i]}${dd_suffix}"
4365
        rm -rf debian
4366
        popd > /dev/null 2>&1
4367
-       i=$(($i+1))
4368
    done
4369
 
4370
    echo "Copying source..."
4371
@@ -2711,79 +2378,48 @@
4372
    echo $""
4373
    echo $"Disk image location: $dkms_tree/$module/$module_version/driver_disk/$image_name"
4374
    echo $""
4375
-   echo $"DKMS: mkdriverdisk Completed."
4376
+   echo $"DKMS: mkdriverdisk completed."
4377
 }
4378
 
4379
 make_tarball()
4380
 {
4381
-    setup_kernels_arches "mktarball"
4382
-
4383
     make_common_test "mktarball"
4384
 
4385
     # Check for dkms_dbversion
4386
-    if ! [ -e "$dkms_tree/dkms_dbversion" ]; then
4387
-        echo $"" >&2
4388
-        echo $"Could not find the file $dkms_tree/dkms_dbversion." >&2
4389
-        echo $"Creating w/ default contents." >&2
4390
-        echo "2.0.0" > $dkms_tree/dkms_dbversion
4391
-    fi
4392
-
4393
-    # Error out if archive_location is set and contains a "/" in it
4394
-    case "$archive_location" in
4395
-        */*)
4396
-        echo $"" >&2
4397
-        echo $"Error!  The name you have specified for your tarball contains a '/'." >&2
4398
-        echo $"You may only specify a simple filename with no preceding path."
4399
-        exit 7
4400
-        ;;
4401
-    esac
4402
-
4403
-    # Error out if binaries-only is set and source-only is set
4404
-    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
4405
-        echo $"" >&2
4406
-        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
4407
-        echo $"You cannot do this." >&2
4408
-        exit 8
4409
+    if ! [[ -e $dkms_tree/dkms_dbversion ]]; then
4410
+   echo $"" >&2
4411
+   echo $"Could not find the file $dkms_tree/dkms_dbversion." >&2
4412
+   echo $"Creating w/ default contents." >&2
4413
+   echo "2.0.0" > $dkms_tree/dkms_dbversion
4414
     fi
4415
 
4416
     # Read the conf file
4417
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
4418
-    if [ "$?" -ne 0 ]; then
4419
-        echo $"" >&2
4420
-        echo $"Error! Bad conf file." >&2
4421
-        echo $"Your dkms.conf is not valid." >&2
4422
-        exit 5
4423
-    fi
4424
+    read_conf_or_die "$kernelver" "$arch"
4425
 
4426
-    temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
4427
+    temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
4428
     mkdir -p $temp_dir_name/dkms_main_tree
4429
 
4430
-    if [ -n "$source_only" ]; then
4431
-    kernel_version_list="source-only"
4432
+    if [[ $source_only ]]; then
4433
+   kernel_version_list="source-only"
4434
     else
4435
-    local i=0
4436
-    while [ $i -lt ${#kernelver_array[@]} ]; do
4437
-
4438
-        if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
4439
-            echo $"" >&2
4440
-            echo $"Error! No modules built for ${kernelver_array[$i]} (${arch_array[$i]})." >&2
4441
-            echo $"Modules must already be in the built state before using mktarball." >&2
4442
-            rm -rf "$temp_dir_name" 2>/dev/null
4443
-            exit 6
4444
-        fi
4445
-
4446
-        set_module_suffix "${kernelver_array[$i]}"
4447
-
4448
-        echo "Marking modules for ${kernelver_array[$i]} (${arch_array[$i]}) for archiving..."
4449
-        if [ -z "$kernel_version_list" ]; then
4450
-            kernel_version_list="kernel${kernelver_array[$i]}-${arch_array[$i]}"
4451
-        else
4452
-            kernel_version_list="${kernel_version_list}-kernel${kernelver_array[$i]}-${arch_array[$i]}"
4453
-        fi
4454
-        mkdir -p "$temp_dir_name/dkms_main_tree/${kernelver_array[$i]}/${arch_array[$i]}"
4455
-        cp -rf "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" "$temp_dir_name/dkms_main_tree/${kernelver_array[$i]}"
4456
-
4457
-        i=$(($i + 1))
4458
+   local i
4459
+   for ((i=0; i<${#kernelver[@]}; i++)); do
4460
+       if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
4461
+       rm -rf "$temp_dir_name" 2>/dev/null
4462
+       die 6  $"No modules built for ${kernelver[$i]} (${arch[$i]})." \
4463
+           $"Modules must already be in the built state before using mktarball."
4464
+       fi
4465
+
4466
+       set_module_suffix "${kernelver[$i]}"
4467
+
4468
+       echo "Marking modules for ${kernelver[$i]} (${arch[$i]}) for archiving..."
4469
+       if [[ ! $kernel_version_list ]]; then
4470
+       kernel_version_list="kernel${kernelver[$i]}-${arch[$i]}"
4471
+       else
4472
+       kernel_version_list="${kernel_version_list}-kernel${kernelver[$i]}-${arch[$i]}"
4473
+       fi
4474
+       mkdir -p "$temp_dir_name/dkms_main_tree/${kernelver[$i]}/${arch[$i]}"
4475
+       cp -rf "$dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]}" "$temp_dir_name/dkms_main_tree/${kernelver[$i]}"
4476
     done
4477
     fi
4478
 
4479
@@ -2791,469 +2427,431 @@
4480
     cp -f "$dkms_tree/dkms_dbversion" "$temp_dir_name/dkms_main_tree/"
4481
 
4482
     # Copy the source_tree or make special binaries-only structure
4483
-    if [ -z "$binaries_only" ]; then
4484
-        echo $""
4485
-        echo $"Marking $dkms_tree/$module/$module_version/source for archiving..."
4486
-        mkdir -p $temp_dir_name/dkms_source_tree
4487
-        cp -rf $dkms_tree/$module/$module_version/source/* $temp_dir_name/dkms_source_tree
4488
-    else
4489
-        echo $""
4490
-        echo $"Creating special tarball structure to accomodate only binaries."
4491
-        mkdir $temp_dir_name/dkms_binaries_only
4492
-        echo "$module" > $temp_dir_name/dkms_binaries_only/PACKAGE_NAME
4493
-        echo "$module_version" > $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION
4494
-        [ -z "$conf" ] && conf="$dkms_tree/$module/$module_version/source/dkms.conf"
4495
-        cp -f $conf $temp_dir_name/dkms_binaries_only/ 2>/dev/null
4496
+    if [[ $binaries_only ]]; then
4497
+   echo $""
4498
+   echo $"Creating tarball structure to specifically accomodate binaries."
4499
+   mkdir $temp_dir_name/dkms_binaries_only
4500
+   echo "$module" > $temp_dir_name/dkms_binaries_only/PACKAGE_NAME
4501
+   echo "$module_version" > $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION
4502
+   [[ ! $conf ]] && conf="$dkms_tree/$module/$module_version/source/dkms.conf"
4503
+   cp -f $conf $temp_dir_name/dkms_binaries_only/ 2>/dev/null
4504
+    else
4505
+   echo $""
4506
+   echo $"Marking $dkms_tree/$module/$module_version/source for archiving..."
4507
+   mkdir -p $temp_dir_name/dkms_source_tree
4508
+   cp -rf $dkms_tree/$module/$module_version/source/* $temp_dir_name/dkms_source_tree
4509
     fi
4510
 
4511
-    # Make the tarball
4512
-    cd $temp_dir_name
4513
-    if [ `echo $kernel_version_list | wc -m | awk {'print $1'}` -gt 200 ]; then
4514
-        kernel_version_list="manykernels"
4515
+    if (( $(echo $kernel_version_list | wc -m | awk {'print $1'}) > 200 )); then
4516
+   kernel_version_list="manykernels"
4517
     fi
4518
+
4519
     local tarball_name="$module-$module_version-$kernel_version_list.dkms.tar.gz"
4520
-    [ -n "$archive_location" ] && tarball_name="$archive_location"
4521
-    tar -czf $temp_dir_name/$tarball_name ./* 2>/dev/null
4522
-    cd - >/dev/null
4523
-    if [ "$?" -eq 0 ]; then
4524
-        echo $""
4525
-        mkdir -p $dkms_tree/$module/$module_version/tarball 2>/dev/null
4526
-        mv -f $temp_dir_name/$tarball_name $dkms_tree/$module/$module_version/tarball/
4527
-        echo $""
4528
-        echo $"Tarball location: $dkms_tree/$module/$module_version/tarball/$tarball_name"
4529
-        echo $""
4530
-        echo $"DKMS: mktarball Completed."
4531
-        rm -rf $temp_dir_name
4532
-    else
4533
-        echo $"" >&2
4534
-        echo $"Error! Failed to make tarball." >&2
4535
-        rm -rf $temp_dir_name
4536
-        exit 6
4537
+    local tarball_dest="$dkms_tree/$module/$module_version/tarball/"
4538
+
4539
+    # Die if we will not be able to create the tarball due to permissions.
4540
+    if [[ $archive_location ]]; then
4541
+   tarball_name="${archive_location##*/}"
4542
+        if [[ ${archive_location%/*} != $archive_location && \
4543
+            -d ${archive_location%/*} && -w ${archive_location%/*} ]]; then
4544
+            tarball_dest="${archive_location%/*}"
4545
+        elif [[ ${archive_location%/*} != $archive_location ]] && ! mkdir -p $tarball_dest; then
4546
+       die 9 $"Will not be able to create $archive_location due to a permissions problem."
4547
+   fi
4548
     fi
4549
+    if [ ! -d $tarball_dest ]; then
4550
+   mkdir -p "$dkms_tree/$module/$module_version/tarball/"
4551
+    fi
4552
+
4553
+    echo $""
4554
+    echo $"Tarball location: $tarball_dest/$tarball_name"
4555
+
4556
+    local tarball_ext=${tarball_name##*.}
4557
+    [[ $tarball_ext = tar ]] || tarball_name=${tarball_name%.$tarball_ext}
4558
+
4559
+    # Make the tarball
4560
+    cd $temp_dir_name
4561
+    if tar -cf $temp_dir_name/$tarball_name ./* 2>/dev/null; then
4562
+   cd - >/dev/null
4563
+   echo $""
4564
+   mv -f "$temp_dir_name/$tarball_name" "$tarball_dest/$tarball_name"
4565
+   rm -rf $temp_dir_name
4566
+    else
4567
+   cd - >/dev/null
4568
+   rm -rf $temp_dir_name
4569
+   die 6 $"Failed to make tarball."
4570
+    fi
4571
+    case $tarball_ext in
4572
+   gz) gzip -9 "$tarball_dest/$tarball_name";;
4573
+   bz2) bzip2 -9 "$tarball_dest/$tarball_name";;
4574
+   xz) xz -9 "$tarball_dest/$tarball_name";;
4575
+    esac
4576
+    echo $""
4577
+    echo $"DKMS: mktarball completed."
4578
+}
4579
+
4580
+# A tiny helper function to make sure dkms.conf describes a valid package.
4581
+get_pkginfo_from_conf() {
4582
+    [[ -f $1 && $1 = *dkms.conf ]] || return
4583
+    read_conf_or_die "$kernelver" "$arch" "$1"
4584
+    [[ $PACKAGE_NAME && $PACKAGE_VERSION ]]
4585
 }
4586
 
4587
+# Unpack a DKMS tarball from a few different supported formats.
4588
+# We expect $archive_location to have been passed either as a raw argument or
4589
+# with --archive.
4590
 load_tarball()
4591
 {
4592
-    setup_kernels_arches "mktarball"
4593
-
4594
-    # Error out of --archive was not set with the tarball location
4595
-    if [ -z "$archive_location" ]; then
4596
-        echo $"" >&2
4597
-        echo $"Error! Invalid number of parameters passed." >&2
4598
-        echo $"Usage: ldtarball --archive=<tarball-location>" >&2
4599
-        exit 1
4600
+    # Error out if $archive_location does not exist
4601
+    if [[ ! -e $archive_location ]]; then
4602
+   die 2 $"$archive_location does not exist."
4603
     fi
4604
 
4605
-    # Error out if $archive_location does not exist
4606
-    if ! [ -e "$archive_location" ]; then
4607
-        echo $"" >&2
4608
-        echo $"Error! Cannot locate $archive_location." >&2
4609
-        echo $"File does not exist." >&2
4610
-        exit 2
4611
+    # If it is an .rpm file. install it with rpm, run an autoinstall, and then exit.
4612
+    if [[ $archive_location = *.rpm ]]; then
4613
+       if rpm -Uvh "$archive_location"; then
4614
+           autoinstall
4615
+           exit $?
4616
+       else
4617
+           die 9 $"Unable to install $archive_location using rpm." \
4618
+               $"Check to ensure that your system can install .rpm files."
4619
+       fi
4620
     fi
4621
 
4622
     # Figure out what kind of archive it is (tar.gz, tar, tar.bz, etc)
4623
+    # Note that this does not depend on the extensions being correct.
4624
     local tar_options=""
4625
-    if `gzip -t $archive_location 2>/dev/null`; then
4626
-        tar_options="${tar_options}z"
4627
-    fi
4628
-    if `bzip2 -t $archive_location 2>/dev/null`; then
4629
-        tar_options="${tar_options}j"
4630
-    fi
4631
+    for xpand in gzip bzip xz; do
4632
+   $xpand -t $archive_location 2>/dev/null || continue
4633
+   case $xpand in
4634
+       gzip) tar_options=z;;
4635
+       bzip2) tar_options=j;;
4636
+       xz) tar_options=J;;
4637
+   esac
4638
+   break
4639
+    done
4640
 
4641
     # Untar it into $tmp_location
4642
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
4643
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
4644
+    trap 'rm -rf $temp_dir_name' EXIT
4645
     tar -${tar_options}xf $archive_location -C $temp_dir_name
4646
 
4647
-    # Check that dkms_dbversion is not a future version
4648
-    db_from_tarball="`cat $temp_dir_name/dkms_main_tree/dkms_dbversion 2>/dev/null`"
4649
-    db_from_dkms="`cat $dkms_tree/dkms_dbversion 2>/dev/null`"
4650
-    if [ -n "$db_from_tarball" ] && [ -n "$db_from_dkms" ]; then
4651
-        if [[ $(VER "$db_from_tarball") > $(VER "$db_from_dkms") ]]; then
4652
-            echo $"" >&2
4653
-            echo $"Error! The tarball you are trying to load indicates it is database version" >&2
4654
-            echo $"$db_from_tarball.  This version of DKMS only supports $db_from_dkms or lower.">&2
4655
-            rm -rf $temp_dir_name
4656
-            exit 9
4657
-        fi
4658
+    if [[ ! $temp_dir_name/dkms_main_tree ]]; then
4659
+   # Tarball was not generated from mktarball.
4660
+   # Just find the dkms.conf file and load the source.
4661
+   conf=$(find $temp_dir_name/ -name dkms.conf 2>/dev/null | head -n 1)
4662
+   if [[ ! $conf ]]; then
4663
+       rm -rf $temp_dir_name
4664
+       die 3 $"Tarball does not appear to be a correctly formed" \
4665
+       $"DKMS archive. No dkms.conf found within it."
4666
+   fi
4667
+   add_source_tree "${conf%dkms.conf}"
4668
+   return
4669
     fi
4670
 
4671
-    # Make sure its a sane tarball
4672
-    PACKAGE_NAME=""
4673
-    PACKAGE_VERSION=""
4674
-    local is_from_mktarball=""
4675
-    local is_binaries_only=""
4676
-    local is_not_arch_aware=""
4677
-    if ! [ -d "$temp_dir_name/dkms_main_tree" ]; then
4678
-        conf=`find $temp_dir_name/ -name dkms.conf 2>/dev/null | head -n 1`
4679
-        if [ -z "$conf" ]; then
4680
-            echo $"" >&2
4681
-            echo $"Error! Tarball does not appear to be a correctly formed" >&2
4682
-            echo $"DKMS archive. No dkms.conf found within it." >&2
4683
-            rm -rf $temp_dir_name
4684
-            exit 3
4685
-        fi
4686
-        read_conf "${kernelver_array[0]}" "${arch_array[0]}" "$conf"
4687
-        if [ "$?" -ne 0 ]; then
4688
-            echo $"" >&2
4689
-            echo $"Error! Bad conf file." >&2
4690
-            echo $"File: $conf does not represent a valid dkms.conf file" >&2
4691
-            rm -rf $temp_dir_name
4692
-            exit 4
4693
-        fi
4694
-        tarball_source_tree_name=`echo $conf | sed "s#$temp_dir_name\/##" | sed 's/dkms.conf//' | sed 's/\/$//'`
4695
-    elif ! [ -d "$temp_dir_name/dkms_source_tree" ] && [ -d "$temp_dir_name/dkms_binaries_only" ]; then
4696
-        PACKAGE_NAME=`cat $temp_dir_name/dkms_binaries_only/PACKAGE_NAME 2>/dev/null`
4697
-        PACKAGE_VERSION=`cat $temp_dir_name/dkms_binaries_only/PACKAGE_VERSION 2>/dev/null`
4698
-        if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
4699
-            echo $"" >&2
4700
-            echo $"Error! Tarball does not appear to be a correctly formed" >&2
4701
-            echo $"DKMS archive." >&2
4702
-            rm -rf $temp_dir_name
4703
-            exit 5
4704
-        fi
4705
-        if [ "`$0 status -m $PACKAGE_NAME -v $PACKAGE_VERSION 2>/dev/null`" == "" ]; then
4706
-            if [ -e "$temp_dir_name/dkms_binaries_only/dkms.conf" ]; then
4707
-            echo $""
4708
-            echo $"Binaries-only DKMS tarball to be loaded for $PACKAGE_NAME-$PACKAGE_VERSION"
4709
-            echo $"even though source for this module is not added to the DKMS tree.  "
4710
-                    echo $"<<<<WARNING>>>>"
4711
-            echo $"This will allow you to install the pre-built binaries contained within this"
4712
-            echo $"tarball, but will prevent you from building new modules for other kernels."
4713
-            echo $""
4714
-            . $temp_dir_name/dkms_binaries_only/dkms.conf 2>/dev/null
4715
-            else
4716
-            echo $"" >&2
4717
-            echo $"Binaries-only DKMS tarball does not seem to contain a dkms.conf file for" >&2
4718
-            echo $"this module.  Unable to load this tarball into the DKMS tree." >&2
4719
-            exit 7
4720
-            fi
4721
-        fi
4722
-        is_from_mktarball="true"
4723
-        is_binaries_only="true"
4724
-    elif [ -d "$temp_dir_name/dkms_source_tree" ]; then
4725
-        . $temp_dir_name/dkms_source_tree/dkms.conf 2>/dev/null
4726
-        if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
4727
-            echo $"" >&2
4728
-            echo $"Error! Tarball does not appear to be a correctly formed" >&2
4729
-            echo $"DKMS archive." >&2
4730
-            rm -rf $temp_dir_name
4731
-            exit 8
4732
-        fi
4733
-        is_from_mktarball="true"
4734
-        tarball_source_tree_name="dkms_source_tree"
4735
-    else
4736
-        echo $"" >&2
4737
-        echo $"Error! Tarball does not appear to be a correctly formed" >&2
4738
-        echo $"DKMS archive." >&2
4739
-        rm -rf $temp_dir_name
4740
-        exit 8
4741
-    fi
4742
+    # Check that dkms_dbversion is not a future version
4743
+    # As far as I can tell, the only reason we bother with this is for detecting
4744
+    # whether we have arch support or not, which we can also determine by examining
4745
+    # the structure of the tarball.
4746
+    db_from_tarball=$(cat $temp_dir_name/dkms_main_tree/dkms_dbversion 2>/dev/null)
4747
+    db_from_dkms=$(cat $dkms_tree/dkms_dbversion 2>/dev/null)
4748
+    if [[ $db_from_tarball && $db_from_dkms && \
4749
+   $(VER "$db_from_tarball") > $(VER "$db_from_dkms") ]]; then
4750
+   die 9 \
4751
+       $"The tarball you are trying to load indicates it is database version" \
4752
+       $"$db_from_tarball.  This version of DKMS only supports $db_from_dkms or lower."
4753
+    fi
4754
+
4755
+    # Make sure its a sane tarball. Sane ones will have one of the two
4756
+    # directories we test for.
4757
+    for loc in dkms_source_tree dkms_binaries_only ''; do
4758
+   if [[ ! $loc ]]; then
4759
+       die 7 $"No valid dkms.conf in dkms_source_tree or dkms_binaries_only." \
4760
+       $"$archive_location is not a valid DKMS tarball."
4761
+   fi
4762
+   local conf="$temp_dir_name/$loc/dkms.conf"
4763
+   [[ -f $conf ]] || continue
4764
+   if ! get_pkginfo_from_conf "$conf"; then
4765
+       echo >&2
4766
+       echo $"Malformed dkms.conf, refusing to load." >&2
4767
+       continue
4768
+   fi
4769
+   if is_module_added "$PACKAGE_NAME" "$PACKAGE_VERSION" && \
4770
+       [[ ! $force ]]; then
4771
+       die 8  $"$PACKAGE_NAME-$PACKAGE_VERSION is already added!" \
4772
+       $"Aborting."
4773
+   fi
4774
+   module="$PACKAGE_NAME"; module_version="$PACKAGE_VERSION"
4775
+   echo $""
4776
+   echo $"Loading tarball for $module-$module_version"
4777
+   case $loc in
4778
+       dkms_source_tree)
4779
+       add_source_tree "$temp_dir_name/dkms_source_tree";;
4780
+       dkms_binaries_only)
4781
+       #if there is a source tree on the system already, don't build a binaries stub
4782
+       if [[ ! -d $source_tree/$module-$module_version ]]; then
4783
+           echo $"Creating $dkms_tree/$module/$module_version/source"
4784
+           mkdir -p "$dkms_tree/$module/$module_version/source"
4785
+           echo $"Copying dkms.conf to $dkms_tree/$module/$module_version/source..."
4786
+           cp -rf "$temp_dir_name/dkms_binaries_only/dkms.conf" "$dkms_tree/$module/$module_version/source"
4787
+       fi;;
4788
+       *)  die 8 $"$FUNCNAME:$LINENO: Cannot happen." \
4789
+       $"Report this error to dkms-devel@dell.com";;
4790
+   esac
4791
+   break
4792
+    done
4793
+
4794
+    # at this point, the source has been copied to the appropriate location
4795
+    # and registered with dkms, or a binary-only config has been noted.
4796
+    # Now, add any included precompiled modules.
4797
 
4798
     # Is tarball from before DKMS 2.0 (prior to arch support)
4799
-    if [ "$is_from_mktarball" == "true" ] && ! [ -e "$temp_dir_name/dkms_main_tree/dkms_dbversion" ]; then
4800
-        is_not_arch_aware="true"
4801
-        echo $"" >&2
4802
-        echo $"Warning!  This tarball was created with dkms < 2.0 and contains" >&2
4803
-        echo $"no arch info. DKMS will assume the arch: ${arch_array[0]}" >&2
4804
+    if [[ ! -e $temp_dir_name/dkms_main_tree/dkms_dbversion ]]; then
4805
+   [[ $loc = dkms_binaries_only ]] && rm -rf "$dkms_tree/$module/$module_version/source"
4806
+   die 10 $" This tarball was created with dkms < 2.0 and contains" \
4807
+       $"no arch info. DKMS is refusing to install precompiled modules."
4808
     fi
4809
 
4810
-    # Make sure we got what we needed from the tarball
4811
-    module="$PACKAGE_NAME"
4812
-    module_version="$PACKAGE_VERSION"
4813
-
4814
-    echo $""
4815
-    echo $"Loading tarball for module: $module / version: $module_version"
4816
-    echo $""
4817
-
4818
-    # Load the source from the tarball or build it's structure (for binaries only)
4819
-    if [ -z "$is_binaries_only" ]; then
4820
-        if [ "`$0 status -m $module -v $module_version 2>/dev/null`" != "" ] && [ -z "$force" ]; then
4821
-            echo $"Warning! Source for $module-$module_version already exists.  Skipping..." >&2
4822
-        else
4823
-            echo $"Loading $source_tree/$module-$module_version..."
4824
-            rm -rf $source_tree/$module-$module_version
4825
-            mkdir -p $source_tree/$module-$module_version
4826
-            cp -rf $temp_dir_name/$tarball_source_tree_name/* $source_tree/$module-$module_version
4827
-        fi
4828
-
4829
-        mkdir -p $dkms_tree/$module/$module_version
4830
-    else
4831
-        echo $"Creating $dkms_tree/$module/$module_version/source"
4832
-        mkdir -p $dkms_tree/$module/$module_version/source
4833
-        echo $"Copying dkms.conf to $dkms_tree/$module/$module_version/source..."
4834
-        cp -rf $temp_dir_name/dkms_binaries_only/dkms.conf $dkms_tree/$module/$module_version/source
4835
-    fi
4836
-
4837
-    # Load kernel directories
4838
-    [ -n "$is_not_arch_aware" ] && dirs_to_load=`find $temp_dir_name/dkms_main_tree -type d -maxdepth 1 -mindepth 1 2>/dev/null`
4839
-    [ -z "$is_not_arch_aware" ] && dirs_to_load=`find $temp_dir_name/dkms_main_tree -type d -maxdepth 2 -mindepth 2 2>/dev/null`
4840
-    for directory in $dirs_to_load; do
4841
-        dirs_to_parse=`echo $directory | sed "s#.*dkms_main_tree/##"`
4842
-        kernel_to_load=`echo $dirs_to_parse | sed "s#/.*##"`
4843
-        # arch_to_load="${arch_array[0]##*/}"
4844
-        [ `echo $dirs_to_parse | grep -c "/"` -gt 0 ] && arch_to_load=`echo $dirs_to_parse | sed "s#.*/##"` || arch_to_load="${arch_array[0]}"
4845
-
4846
-        dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_to_load/$arch_to_load"
4847
-
4848
-
4849
-        dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_to_load/$arch_to_load"
4850
-        if [ -d "$dkms_dir_location" ] && [ -z "$force" ]; then
4851
-            echo $"Warning! $dkms_dir_location already exists.  Skipping..." >&2
4852
-        else
4853
-            echo $"Loading $dkms_dir_location..."
4854
-            rm -rf $dkms_dir_location
4855
-            mkdir -p $dkms_dir_location
4856
-            cp -rf $directory/* $dkms_dir_location/
4857
-        fi
4858
+    # Load precompiled modules.
4859
+    for directory in "$temp_dir_name/dkms_main_tree"/*/*; do
4860
+   [[ -d $directory ]] || continue
4861
+   kernel_arch_to_load=${directory/*dkms_main_tree\/}
4862
+   dkms_dir_location="$dkms_tree/$module/$module_version/$kernel_arch_to_load"
4863
+   if [[ -d $dkms_dir_location && ! $force ]]; then
4864
+       warn $"$dkms_dir_location already exists.  Skipping..."
4865
+   else
4866
+       echo $"Loading $dkms_dir_location..."
4867
+       rm -rf $dkms_dir_location
4868
+       mkdir -p $dkms_dir_location
4869
+       cp -rf $directory/* $dkms_dir_location/
4870
+   fi
4871
     done
4872
 
4873
-    # Create source symlink (if there isn't a real directory there)
4874
-    if [ ! -h "$dkms_tree/$module/$module_version/source" ] && \
4875
-       [ ! -d "$dkms_tree/$module/$module_version/source" ] || [ ! -z "$force" ]; then
4876
-        echo $"Creating $dkms_tree/$module/$module_version/source symlink..."
4877
-        rm -f "$dkms_tree/$module/$module_version/source"
4878
-        ln -s "$source_tree/$module-$module_version" "$dkms_tree/$module/$module_version/source"
4879
-    fi
4880
-
4881
-    # Clean up /tmp
4882
-    rm -rf $temp_dir_name
4883
-
4884
     echo $""
4885
-    echo $"DKMS: ldtarball Completed."
4886
+    echo $"DKMS: ldtarball completed."
4887
+    [[ $loc != dkms_binaries_only ]] || [[ -d $source_tree/$module-$module_version ]]
4888
 }
4889
 
4890
-run_match ()
4891
+run_match()
4892
 {
4893
-    setup_kernels_arches "match"
4894
-    set_kernel_source_dir "${kernelver_array[0]}"
4895
+    set_kernel_source_dir "$kernelver"
4896
 
4897
     # Error if $template_kernel is unset
4898
-    if [ -z "$template_kernel" ]; then
4899
-        echo $"" >&2
4900
-        echo $"Error! Invalid number of parameters passed." >&2
4901
-        echo $"Usage: match --templatekernel=<kernel-version> -k <kernel-version>" >&2
4902
-        echo $"   or: match --templatekernel=<kernel-version> -k <kernel-version> -m <module>" >&2
4903
-        exit 1
4904
+    if [[ ! $template_kernel ]]; then
4905
+   die 1 $"Invalid number of parameters passed." \
4906
+       $"Usage: match --templatekernel=<kernel-version> -k <kernel-version>" \
4907
+       $"   or: match --templatekernel=<kernel-version> -k <kernel-version> <module>"
4908
     fi
4909
 
4910
     # Error out if $template_kernel = $kernel_version
4911
-    if [ "$template_kernel" == "${kernelver_array[0]}" ]; then
4912
-        echo $"" >&2
4913
-        echo $"Error! The templatekernel and the specified kernel version are the same." >&2
4914
-        exit 2
4915
+    if [[ $template_kernel = $kernelver ]]; then
4916
+   die 2 $"The templatekernel and the specified kernel version are the same."
4917
     fi
4918
 
4919
     # Read in the status of template_kernel
4920
-    local template_kernel_status=`$0 status -k $template_kernel -a ${arch_array[0]} | grep ": installed"`
4921
+    local template_kernel_status=$(do_status '' '' $template_kernel $arch | grep ": installed")
4922
 
4923
     # If $module is set, grep the status only for that module
4924
-    if [ -n "$module" ]; then
4925
-
4926
-        # Make sure that its installed in the first place
4927
-        if ! [ -d "$dkms_tree/$module/" ]; then
4928
-            echo $"" >&2
4929
-            echo $"Error! The module: $module is not located in the DKMS tree." >&2
4930
-            exit 3
4931
-        fi
4932
-
4933
-        template_kernel_status=`echo "$template_kernel_status" | grep "^$module,"`
4934
+    if [[ $module ]]; then
4935
+   # Make sure that its installed in the first place
4936
+   if ! [[ -d $dkms_tree/$module/ ]]; then
4937
+       die 3 $"The module: $module is not located in the DKMS tree."
4938
+   fi
4939
+   template_kernel_status=$(echo "$template_kernel_status" | grep "^$module,")
4940
     fi
4941
 
4942
     echo $""
4943
-    echo $"Matching modules in kernel: ${kernelver_array[0]} (${arch_array[0]})"
4944
-    echo $"to the configuration of kernel: $template_kernel (${arch_array[0]})"
4945
+    echo $"Matching modules in kernel: $kernelver ($arch)"
4946
+    echo $"to the configuration of kernel: $template_kernel ($arch)"
4947
 
4948
     # Prepare the kernel just once but only if there is actual work to do
4949
-    if [ -z "$template_kernel_status" ]; then
4950
-        echo $""
4951
-        echo $"There is nothing to be done for this match."
4952
-    else
4953
-        prepare_kernel "${kernelver_array[0]}" "${arch_array[0]}"
4954
-
4955
-        # Iterate over the kernel_status and match kernel to the template_kernel
4956
-        while read template_line; do
4957
-            template_module=`echo "$template_line" | awk {'print $1'} | sed 's/,$//'`
4958
-            template_version=`echo "$template_line" | awk {'print $2'} | sed 's/,$//'`
4959
-
4960
-            # Print out a match header
4961
-            echo $""
4962
-            echo $"---- Match Beginning ----"
4963
-            echo $"Module:  $template_module"
4964
-            echo $"Version: $template_version"
4965
-            echo $"-------------------------"
4966
-
4967
-            # Figure out what to do from here
4968
-            if $0 status -m "$template_module" -v "$template_version" -k "${kernelver_array[0]}" -a "${arch_array[0]}" 2>/dev/null | grep -q ": installed"; then
4969
-                echo $""
4970
-                echo $"This module/version combo is already installed.  Nothing to be done."
4971
-            elif $0 status -m "$template_module" -v "$template_version" -k "${kernelver_array[0]}" -a "${arch_array[0]}" 2>/dev/null | grep -q ": built"; then
4972
-                echo $""
4973
-                echo $"This module/version combo is built.  Installing it:"
4974
-                module="$template_module"
4975
-                module_version="$template_version"
4976
-                install_module
4977
-            else
4978
-                echo $""
4979
-                echo $"Building & Installing this module/version:"
4980
-                module="$template_module"
4981
-                module_version="$template_version"
4982
-                build_module
4983
-                install_module
4984
-            fi
4985
-        done < <(echo "$template_kernel_status")
4986
-
4987
-        # Clean up the kernel tree
4988
-        if [[ ! ( $(VER ${kernelver_array[0]}) < $(VER 2.6.6) ) && \
4989
-            -d "$kernel_source_dir" && \
4990
-            ! -h "$kernel_source_dir" && \
4991
-            -z "$ksourcedir_fromcli" ]]; then
4992
-            echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
4993
-        elif [ -z "$no_clean_kernel" ]; then
4994
-            cd "$kernel_source_dir"
4995
-            [ -z "$kerneldoth_contents" ] && invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
4996
-            [ -n "$config_contents" ] && echo "$config_contents" > .config
4997
-            [ -n "$kerneldoth_contents" ] && echo "$kerneldoth_contents" > /boot/kernel.h
4998
-            cd - >/dev/null
4999
-        fi
5000
+    if [[ ! $template_kernel_status ]]; then
5001
+   echo $""
5002
+   echo $"There is nothing to be done for this match."
5003
+    else
5004
+   prepare_kernel "$kernelver" "$arch"
5005
+
5006
+   # Iterate over the kernel_status and match kernel to the template_kernel
5007
+   while read template_line; do
5008
+       template_module=`echo "$template_line" | awk {'print $1'} | sed 's/,$//'`
5009
+       template_version=`echo "$template_line" | awk {'print $2'} | sed 's/,$//'`
5010
+
5011
+       # Print out a match header
5012
+       echo $""
5013
+       echo $"---- Match Beginning ----"
5014
+       echo $"Module:  $template_module"
5015
+       echo $"Version: $template_version"
5016
+       echo $"-------------------------"
5017
+
5018
+       # Figure out what to do from here
5019
+       if show_status "$template_module" "$template_version" "$kernelver" "$arch" 2>/dev/null | grep -q ": installed"; then
5020
+       echo $""
5021
+       echo $"This module/version combo is already installed.  Nothing to be done."
5022
+       elif show_status "$template_module" "$template_version" "$kernelver" "$arch" 2>/dev/null | grep -q ": built"; then
5023
+       echo $""
5024
+       echo $"This module/version combo is built.  Installing it:"
5025
+       module="$template_module"
5026
+       module_version="$template_version"
5027
+       install_module
5028
+       else
5029
+       echo $""
5030
+       echo $"Building & Installing this module/version:"
5031
+       module="$template_module"
5032
+       module_version="$template_version"
5033
+       build_module
5034
+       install_module
5035
+       fi
5036
+   done < <(echo "$template_kernel_status")
5037
+
5038
+   # Clean up the kernel tree
5039
+   if [[ ! ( $(VER $kernelver) < $(VER 2.6.6) ) && \
5040
+       -d "$kernel_source_dir" && \
5041
+       ! -h "$kernel_source_dir" && \
5042
+       -z "$ksourcedir_fromcli" ]]; then
5043
+       echo $"Kernel cleanup unnecessary for this kernel.  Skipping..."
5044
+   elif [[ ! $no_clean_kernel ]]; then
5045
+       cd "$kernel_source_dir"
5046
+       [[ $kerneldoth_contents ]] || invoke_command "make mrproper" "cleaning kernel tree (make mrproper)" background
5047
+       [[ $config_contents ]] && echo "$config_contents" > .config
5048
+       [[ $kerneldoth_contents ]] && echo "$kerneldoth_contents" > /boot/kernel.h
5049
+       cd - >/dev/null
5050
+   fi
5051
     fi
5052
 
5053
     # Done
5054
     echo $""
5055
-    echo $"DKMS: match Completed."
5056
+    echo $"DKMS: match completed."
5057
 }
5058
 
5059
 make_rpm()
5060
 {
5061
-    setup_kernels_arches "mkrpm"
5062
-
5063
     make_common_test "mkrpm"
5064
 
5065
     # Check that the rpmbuild command is present
5066
     if ! which rpmbuild >/dev/null 2>&1 ; then
5067
-        echo $"" >&2
5068
-        echo $"Error! rpmbuild not present." >&2
5069
-        echo $"Install the rpm-build package." >&2
5070
-        exit 1
5071
+   die 1 $"rpmbuild not present." \
5072
+       $"Install the rpm-build package."
5073
     fi
5074
 
5075
     # Read the conf file
5076
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
5077
-    if [ "$?" -ne 0 ]; then
5078
-        echo $"" >&2
5079
-        echo $"Error! Bad conf file." >&2
5080
-        echo $"Your dkms.conf is not valid." >&2
5081
-        exit 4
5082
-    fi
5083
+    read_conf_or_die "$kernelver" "$arch"
5084
 
5085
     local rpm_basedir="$dkms_tree/$module/$module_version/rpm"
5086
 
5087
     echo $""
5088
-    if [ -e "$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec" ]; then
5089
-        echo $"Using $dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec"
5090
-        SPECFILE="$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec"
5091
-    elif [ -e "/etc/dkms/template-dkms-mkrpm.spec" ]; then
5092
-        echo $"Using /etc/dkms/template-dkms-mkrpm.spec"
5093
-        SPECFILE="/etc/dkms/template-dkms-mkrpm.spec"
5094
-    else
5095
-        echo $"" >&2
5096
-        echo $"Cannot find /etc/dkms/template-dkms-mkrpm.spec which is needed by" >&2
5097
-        echo $"DKMS in order use mkrpm." >&2
5098
-        exit 5
5099
-    fi
5100
-
5101
-    # Error out if binaries-only is set and source-only is set
5102
-    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
5103
-        echo $"" >&2
5104
-        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
5105
-        echo $"You cannot do this." >&2
5106
-        exit 8
5107
+    local sp
5108
+    for sp in "$dkms_tree/$module/$module_version/source/$module-dkms-mkrpm.spec" \
5109
+   "/etc/dkms/template-dkms-mkrpm.spec"; do
5110
+   [[ -e $sp ]] || continue
5111
+   SPECFILE="$sp"
5112
+   break
5113
+    done
5114
+    if [[ ! $SPECFILE ]]; then
5115
+   die 5 $"Cannot find $sp which is needed by" \
5116
+       $"DKMS in order use mkrpm."
5117
     fi
5118
 
5119
     # Run a dkms mktarball for use in the rpm
5120
     local mktarball_line
5121
-    if [ ! -n "$source_only" ] || [ -n "$binaries_only" ]; then
5122
-        mktarball_line="--binaries-only"
5123
-        local i=0
5124
-        echo $""
5125
-        while [ $i -lt ${#kernelver_array[@]} ]; do
5126
-            if ! [ -d "$dkms_tree/$module/$module_version/${kernelver_array[$i]}/${arch_array[$i]}" ]; then
5127
-            echo $"" >&2
5128
-            echo $"You do not seem to have $module $module_version built for" >&2
5129
-            echo $"${kernelver_array[$i]} (${arch_array[$i]}).  All modules must be in" >&2
5130
-            echo $"the built state before you can use mkrpm." >&2
5131
-            exit 5
5132
-            fi
5133
-            echo $"Marking ${kernelver_array[$i]} (${arch_array[$i]}) for RPM..."
5134
-            mktarball_line="-k ${kernelver_array[$i]} -a ${arch_array[$i]} $mktarball_line"
5135
-            i=$(($i + 1))
5136
-        done
5137
+    if [[ ! $source_only || $binaries_only ]]; then
5138
+   mktarball_line="--binaries-only"
5139
+   local i
5140
+   echo $""
5141
+   for ((i=0; i<${#kernelver[@]}; i++)); do
5142
+       if ! [[ -d $dkms_tree/$module/$module_version/${kernelver[$i]}/${arch[$i]} ]]; then
5143
+       die 5 $"You do not seem to have $module $module_version built for" \
5144
+       $"${kernelver[$i]} (${arch[$i]}).  All modules must be in" \
5145
+       $"the built state before you can use mkrpm."
5146
+       fi
5147
+       echo $"Marking ${kernelver[$i]} (${arch[$i]}) for RPM..."
5148
+       mktarball_line="-k ${kernelver[$i]} -a ${arch[$i]} $mktarball_line"
5149
+   done
5150
     else
5151
-        mktarball_line="none"
5152
+   mktarball_line="none"
5153
     fi
5154
 
5155
-    local RC=0
5156
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
5157
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
5158
     trap 'rm -rf $temp_dir_name' EXIT HUP TERM
5159
     mkdir -p ${temp_dir_name}/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
5160
     cp ${SPECFILE} ${temp_dir_name}/SPECS/dkms_mkrpm.spec
5161
 
5162
     #if using legacy mode, install common postinst
5163
-    if [ "$legacy_postinst" != "0" ]; then
5164
-        invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '${temp_dir_name}/SOURCES'" "copying legacy postinstall template"
5165
+    if ((legacy_postinst != 0)); then
5166
+   invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '${temp_dir_name}/SOURCES'" "copying legacy postinstall template"
5167
     fi
5168
 
5169
     #Copy in the source tree
5170
-    if [ ! -n "$binaries_only" ]; then
5171
-        invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '${temp_dir_name}/SOURCES/$module-$module_version'" "Copying source tree"
5172
+    if [[ ! $binaries_only ]]; then
5173
+   invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '${temp_dir_name}/SOURCES/$module-$module_version'" "Copying source tree"
5174
     fi
5175
 
5176
-    invoke_command "LC_ALL=C rpmbuild --define \"_topdir ${temp_dir_name}\" --define \"version $module_version\" --define \"module_name $module\" --define \"kernel_versions ${kernelver_array[*]}\" --define \"mktarball_line $mktarball_line\" --define \"__find_provides  /usr/lib/dkms/find-provides\" --define \"_use_internal_dependency_generator 0\" -ba ${temp_dir_name}/SPECS/dkms_mkrpm.spec > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
5177
-    if [ "$?" -eq 0 ]; then
5178
-        mkdir -p ${rpm_basedir}
5179
-        cp -a ${temp_dir_name}/SRPMS/* ${temp_dir_name}/RPMS/*/* ${rpm_basedir}/
5180
-        echo $""
5181
-        cat ${temp_dir_name}/rpmbuild.log | grep ^Wrote | sed -e "s:${temp_dir_name}/:${rpm_basedir}/:" -e 's:SRPMS/::' -e 's:RPMS/.*/::'
5182
-        echo $""
5183
-        echo $"DKMS: mkrpm Completed."
5184
+    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
5185
+   mkdir -p ${rpm_basedir}
5186
+   cp -a ${temp_dir_name}/SRPMS/* ${temp_dir_name}/RPMS/*/* ${rpm_basedir}/
5187
+   echo $""
5188
+   cat ${temp_dir_name}/rpmbuild.log | grep ^Wrote | sed -e "s:${temp_dir_name}/:${rpm_basedir}/:" -e 's:SRPMS/::' -e 's:RPMS/.*/::'
5189
+   echo $""
5190
+   echo $"DKMS: mkrpm completed."
5191
     else
5192
-        echo $"" >&2
5193
-        echo $"Error! There was a problem creating your rpm." >&2
5194
-        cat ${temp_dir_name}/rpmbuild.log >&2
5195
-        RC=7
5196
+   cat ${temp_dir_name}/rpmbuild.log >&2
5197
+   die 7 $"There was a problem creating your rpm."
5198
     fi
5199
     rm -rf $temp_dir_name
5200
     trap > /dev/null 2>&1
5201
-    [ ${RC} -ne 0 ] && exit ${RC}
5202
 }
5203
 
5204
-function preproc_file()
5205
+preproc_file()
5206
 {
5207
     local date_str="$(date -R)"
5208
     echo "modifying $1..."
5209
     sed -e "s/DEBIAN_PACKAGE/$debian_package/g" \
5210
-        -e "s/MODULE_NAME/$module/g" \
5211
-        -e "s/MODULE_VERSION/$module_version/g" \
5212
-        -e "s/DATE_STAMP/$date_str/" "$1" > "$1.dkms-pp"
5213
+   -e "s/MODULE_NAME/$module/g" \
5214
+   -e "s/MODULE_VERSION/$module_version/g" \
5215
+   -e "s/DATE_STAMP/$date_str/" "$1" > "$1.dkms-pp"
5216
     mv "$1.dkms-pp" "$1"
5217
 }
5218
 
5219
-function make_debian_test_depends()
5220
+# Install a package on a debian system.
5221
+debian_install()
5222
 {
5223
-    INSTALL_PACKAGES=""
5224
-    # Check that the fakeroot command is present
5225
-    if ! which fakeroot >/dev/null 2>&1 ; then
5226
-        INSTALL_PACKAGES="fakeroot $INSTALL_PACKAGES"
5227
-    fi
5228
-
5229
-    # Check that the dh_make command is present
5230
-    if ! which dpkg-buildpackage >/dev/null 2>&1 ; then
5231
-        INSTALL_PACKAGES="dpkg-dev $INSTALL_PACKAGES"
5232
+    local getroot  tmpfile i
5233
+    local -a packages=("$@")
5234
+    for ((i=0; i < ${#packages[@]}; i++)); do
5235
+   dpkg-query -s "${packages[$i]}"| egrep -q '^Status:.* installed$' || continue
5236
+   unset package[$i]
5237
+    done
5238
+    # if they are already installed, we are OK.
5239
+    [[ ${package[@]} ]] || return
5240
+    if ((UID != 0)); then
5241
+   # figure out how to get root
5242
+   for getroot in su-to-root gksudo kdesu sudo; do
5243
+       which $getroot >/dev/null 2>&1 || continue
5244
+       case $getroot in
5245
+       su-to-root) getroot="$getroot -c";;
5246
+       gksudo) [[ $DISPLAY ]] || continue
5247
+           getroot="$getroot --description 'DKMS Debian package builder' ";;
5248
+       kdesu) [[ $DISPLAY ]] || continue;;
5249
+       esac
5250
+       break
5251
+   done
5252
+    fi
5253
+    if [[ -x /usr/sbin/synaptic && $DISPLAY ]] && tmpfile=$(mktemp_or_die); then
5254
+   # Pretty GUI install.
5255
+   trap 'rm -f "$tmpfile"' EXIT
5256
+   for ((i=0; i=${#packages[@]}; i++)); do
5257
+       [[ ${packages[$i]} ]] && echo "install ${packages[$i]}" >>$tmpfile
5258
+   done
5259
+   $getroot "sh -c '/usr/sbin/synaptic --set-selections --non-interactive --hide-main-window < $tmpfile'"
5260
+    else
5261
+   $getroot apt-get -y install "${packages[@]}"
5262
+    fi
5263
+    if (( $? != 0)); then
5264
+   die 4 $"Missing ${packages[@]}" \
5265
+       $"and unable to install.  Please ask an admin to install for you."
5266
     fi
5267
-    echo "$INSTALL_PACKAGES"
5268
 }
5269
 
5270
-function make_debian()
5271
+make_debian()
5272
 {
5273
     create_type="$1"
5274
 
5275
@@ -3262,115 +2860,58 @@
5276
 
5277
     make_common_test "mk${create_type}"
5278
 
5279
-    debian_package=$(echo $module | sed s/_/-/g)
5280
-
5281
-    SYNAPTIC=""
5282
-    #Synaptic availablity
5283
-    if [ -x /usr/sbin/synaptic ]; then
5284
-        SYNAPTIC="TRUE"
5285
-    fi
5286
-
5287
-    #test who we are
5288
-    ROOT=""
5289
-    if [ "$USER" != "root" ]; then
5290
-        if [ -x /usr/sbin/su-to-root ]; then
5291
-            ROOT="/usr/sbin/su-to-root -c"
5292
-        elif [ -x /usr/bin/gksudo ] && [ ! -z "$DISPLAY" ]; then
5293
-            ROOT="/usr/bin/gksudo --description 'DKMS Debian package builder' "
5294
-        elif [ -x /usr/bin/kdesu ] && [ ! -z "$DISPLAY" ]; then
5295
-            ROOT="/usr/bin/kdesu"
5296
-        elif [ -x /usr/bin/sudo ]; then
5297
-            ROOT="/usr/bin/sudo"
5298
-        fi
5299
-    fi
5300
+    debian_package=${module//_/-}
5301
 
5302
     # Read the conf file
5303
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
5304
-    if [ "$?" -ne 0 ]; then
5305
-        echo $"" >&2
5306
-        echo $"Error! Bad conf file." >&2
5307
-        echo $"Your dkms.conf is not valid." >&2
5308
-        exit 4
5309
-    fi
5310
-
5311
-    #test if we are missing dependencies that are needed during package build
5312
-    INSTALL_PACKAGES="`make_debian_test_depends`"
5313
-    if [ ! -z "$INSTALL_PACKAGES" ]; then
5314
-        if [ -z "$ROOT" ]; then
5315
-            echo $"" >&2
5316
-            echo $"Error! Missing $INSTALL_PACKAGES" >&2
5317
-            echo $"and unable to install.  Please ask an admin to install for you." >&2
5318
-            exit 4
5319
-        fi
5320
-        if [ ! -z "$SYNAPTIC" ] && [ ! -z "$DISPLAY" ]; then
5321
-            local TEMPFILE=`/bin/tempfile`
5322
-            echo $INSTALL_PACKAGES | sed 's/|/\ install\/g' > $TEMPFILE
5323
-            $ROOT "sh -c '/usr/sbin/synaptic --set-selections --non-interactive --hide-main-window < $TEMPFILE'"
5324
-            trap "rm -f $TEMPFILE; delete_temporary_trees" EXIT HUP TERM
5325
-        else
5326
-            $ROOT apt-get -y install $INSTALL_PACKAGES
5327
-        fi
5328
-
5329
-        INSTALL_PACKAGES="`make_debian_test_depends`"
5330
-        #Retest packages
5331
-        if [ ! -z "$INSTALL_PACKAGES" ]; then
5332
-            echo $"" >&2
5333
-            echo $"Error! Missing $INSTALL_PACKAGES" >&2
5334
-            echo $"and unable to install.  Please ask an admin to install for you." >&2
5335
-            exit 4
5336
-        fi
5337
-    fi
5338
+    read_conf_or_die "$kernelver" "$arch"
5339
+    debian_install fakeroot dpkg-dev debhelper
5340
 
5341
     #skeleton to load templates from
5342
     local system_mk="$dkms_tree/$module/$module_version/source/$module-dkms-mk${create_type}"
5343
     local local_mk="/etc/dkms/template-dkms-mk${create_type}"
5344
-    if [ -e "${system_mk}" ]; then
5345
-        echo $"Using ${system_mk}"
5346
-        DEBDIR=${system_mk}
5347
-    elif [ -e "${local_mk}" ]; then
5348
-        echo $"Using ${local_mk}"
5349
-        DEBDIR=${local_mk}
5350
+    if [[ -e ${system_mk} ]]; then
5351
+   echo $"Using ${system_mk}"
5352
+   DEBDIR=${system_mk}
5353
+    elif [[ -e ${local_mk} ]]; then
5354
+   echo $"Using ${local_mk}"
5355
+   DEBDIR=${local_mk}
5356
     else
5357
-        echo $"" >&2
5358
-        echo $"Cannot find ${local_mk} which is needed by" >&2
5359
-        echo $"DKMS in order to use mk${create_type}." >&2
5360
-        exit 5
5361
+   die 5 $"Cannot find ${local_mk} which is needed by" \
5362
+       $"DKMS in order to use mk${create_type}."
5363
     fi
5364
 
5365
     #prepare build directory and copy template
5366
-    local temp_dir=`mktemp -d $tmp_location/dkms.XXXXXX`
5367
+    local temp_dir=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
5368
     trap "rm -rf $temp_dir; delete_temporary_trees" EXIT HUP TERM
5369
     local temp_dir_debian="$temp_dir/$debian_package-dkms-$module_version"
5370
     invoke_command "cp -ar '$DEBDIR/' '$temp_dir_debian'" "copying template"
5371
     pushd "$temp_dir_debian" > /dev/null 2>&1
5372
     for file in debian/*; do
5373
-        preproc_file "$file"
5374
-        chmod 755 "$file"
5375
+   preproc_file "$file"
5376
+   chmod 755 "$file"
5377
     done
5378
     popd > /dev/null 2>&1
5379
 
5380
-    #if using legacy mode, install common postinst
5381
-    if [ "$legacy_postinst" != "0" ]; then
5382
-        invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '$temp_dir_debian'" "copying legacy postinstall template"
5383
+     #if using legacy mode, install common postinst
5384
+    if ((legacy_postinst != 0)); then
5385
+   invoke_command "cp '$PREFIX/usr/lib/dkms/common.postinst' '$temp_dir_debian'" "copying legacy postinstall template"
5386
     fi
5387
 
5388
     #Copy in the source tree
5389
-    if [ ! -n "$binaries_only" ]; then
5390
-        invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '$temp_dir_debian/$module-$module_version'" "Copying source tree"
5391
+    if [[ ! $binaries_only ]]; then
5392
+   invoke_command "cp -Lpr '$dkms_tree/$module/$module_version/source' '$temp_dir_debian/$module-$module_version'" "Copying source tree"
5393
     fi
5394
 
5395
     #Only if we are shipping binary modules, make a .tgz for the deb
5396
-    local archive_location="$module-$module_version.dkms.tar.gz"
5397
-    if [ ! -n "$source_only" ]; then
5398
-        binaries_only="binaries-only"
5399
-        invoke_command "make_tarball" "Gathering binaries"
5400
-        if [ -f $dkms_tree/$module/$module_version/tarball/$archive_location ]; then
5401
-            invoke_command "cp '$dkms_tree/$module/$module_version/tarball/$archive_location' '$temp_dir_debian'" "Copying DKMS tarball into DKMS tree"
5402
-        else
5403
-            echo $"" >&2
5404
-            echo $"Error! Unable to find created tarball." >&2
5405
-            exit 12
5406
-        fi
5407
+    local archive_location="$dkms_tree/$module/$module_version/tarball/$module-$module_version.dkms.tar.gz"
5408
+    if [[ ! $source_only ]]; then
5409
+   binaries_only="binaries-only"
5410
+   invoke_command "make_tarball" "Gathering binaries"
5411
+   if [[ -f $archive_location ]]; then
5412
+       invoke_command "cp '$archive_location' '$temp_dir_debian'" "Copying DKMS tarball into DKMS tree"
5413
+   else
5414
+       die 12 $"Unable to find created tarball."
5415
+   fi
5416
     fi
5417
 
5418
     #calculate destination directory
5419
@@ -3380,100 +2921,52 @@
5420
     #create deb
5421
     pushd "$temp_dir_debian" > /dev/null 2>&1
5422
     case "$create_type" in
5423
-        dsc)
5424
-            invoke_command "dpkg-buildpackage -S -us -uc 1>/dev/null" "Building source package"
5425
-            if [ "$?" -eq 0 ]; then
5426
-                echo $""
5427
-                echo $"DKMS: mk${create_type} Completed."
5428
-            else
5429
-                echo $"" >&2
5430
-                echo $"Error! There was a problem creating your ${create_type}." >&2
5431
-                exit 7
5432
-            fi
5433
-            invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}.dsc' '$temp_dir/${debian_package}-dkms_${module_version}.tar.gz' '$deb_basedir'" "Moving built files to $deb_basedir"
5434
-            ;;
5435
-        deb)
5436
-            invoke_command "dpkg-buildpackage -rfakeroot -d -b -us -uc 1>/dev/null" "Building binary package"
5437
-            if [ "$?" -eq 0 ]; then
5438
-                echo $""
5439
-                echo $"DKMS: mk${create_type} Completed."
5440
-            else
5441
-                echo $"" >&2
5442
-                echo $"Error! There was a problem creating your ${create_type}." >&2
5443
-                exit 7
5444
-            fi
5445
-
5446
-            invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_all.deb' '$deb_basedir'" "Moving built files to $deb_basedir"
5447
-            ;;
5448
+   dsc)
5449
+       invoke_command "dpkg-buildpackage -S -us -uc 1>/dev/null" "Building source package" || \
5450
+       die 7 $"There was a problem creating your ${create_type}."
5451
+       echo $""
5452
+       echo $"DKMS: mk${create_type} completed."
5453
+       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"
5454
+       ;;
5455
+   deb)
5456
+       invoke_command "dpkg-buildpackage -rfakeroot -d -b -us -uc 1>/dev/null" "Building binary package" || \
5457
+       die 7 $"There was a problem creating your ${create_type}."
5458
+       echo $""
5459
+       echo $"DKMS: mk${create_type} completed."
5460
+       invoke_command "mv '$temp_dir/${debian_package}-dkms_${module_version}_all.deb' '$deb_basedir'" "Moving built files to $deb_basedir"
5461
+       ;;
5462
     esac
5463
     popd > /dev/null 2>&1
5464
 
5465
     if in_temporary_trees; then
5466
-        echo "Copying built files to "`pwd`"/.." >&2
5467
-        cp "$dkms_tree/$module/$module_version/deb/"* ..
5468
+   echo "Copying built files to "`pwd`"/.." >&2
5469
+   cp "${deb_basedir}/"* ..
5470
     fi
5471
 
5472
     #cleanup
5473
     invoke_command "rm $temp_dir -fr" "Cleaning up temporary files"
5474
-    delete_temporary_trees
5475
-
5476
-    #done
5477
-    if [ "$?" -ne 0 ]; then
5478
-        echo $"" >&2
5479
-        echo $"Error! There was a problem cleaning up temporary files." >&2
5480
-        exit 7
5481
-    fi
5482
+    delete_temporary_trees || \
5483
+   die 7 $"There was a problem cleaning up temporary files."
5484
 }
5485
 
5486
-function make_common_test()
5487
+make_common_test()
5488
 {
5489
     local create_type=$1
5490
     # Error if $module_version is set but $module is not
5491
-    if [ -z "$module" ] || [ -z "$module_version" ]; then
5492
-        echo $"" >&2
5493
-        echo $"Error! Invalid number of parameters passed." >&2
5494
-        echo $"Usage: $create_type -m <module> -v <module-version>" >&2
5495
-        exit 1
5496
-    fi
5497
+    check_module_args $create_type
5498
 
5499
     # Check that source symlink works
5500
-    if ! [ -d "$dkms_tree/$module/$module_version/source" ]; then
5501
-        echo $"" >&2
5502
-        echo $"Error! DKMS tree does not contain: $module-$module_version" >&2
5503
-        echo $"Build cannot continue without the proper tree." >&2
5504
-        exit 2
5505
-    fi
5506
+    check_module_exists
5507
 
5508
     # Make sure that its installed in the first place
5509
-    if ! [ -d "$dkms_tree/$module/$module_version" ]; then
5510
-        echo $"" >&2
5511
-        echo $"Error! The module/version combo: $module-$module_version" >&2
5512
-        echo $"is not located in the DKMS tree." >&2
5513
-        exit 3
5514
-    fi
5515
-
5516
-    # Error out if archive_location is set and contains a "/" in it
5517
-    case "$archive_location" in
5518
-        */*)
5519
-        echo $"" >&2
5520
-        echo $"Error!  The name you have specified for your archive contains a '/'." >&2
5521
-        echo $"You may only specify a simple filename with no preceding path."
5522
-        exit 7
5523
-        ;;
5524
-    esac
5525
-
5526
-    # Error out if binaries-only is set and source-only is set
5527
-    if [ -n "$binaries_only" ] && [ -n "$source_only" ]; then
5528
-        echo $"" >&2
5529
-        echo $"Error!  You have specified both --binaries-only and --source-only." >&2
5530
-        echo $"You cannot do this." >&2
5531
-        exit 8
5532
-    fi
5533
+    [[ -d $dkms_tree/$module/$module_version ]] ||
5534
+   die 3 $"The module/version combo: $module-$module_version" \
5535
+       $"is not located in the DKMS tree."
5536
 }
5537
 
5538
-function make_kmp_srpm()
5539
+make_kmp_srpm()
5540
 {
5541
-    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
5542
+    local temp_dir_name=$(mktemp_or_die -d $tmp_location/dkms.XXXXXX)
5543
     trap 'rm -rf $temp_dir_name' EXIT HUP TERM
5544
     mkdir -p $temp_dir_name/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
5545
     pushd "$dkms_tree/$module/$module_version" > /dev/null 2>&1
5546
@@ -3484,16 +2977,16 @@
5547
     rm -rf ${module}-${module_version}
5548
     popd > /dev/null 2>&1
5549
     pushd "$temp_dir_name" > /dev/null 2>&1
5550
-    invoke_command "rpmbuild --define \"_topdir ${temp_dir_name}\" --target=${arch_array[0]} -bs ${SPECFILE} > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
5551
+    invoke_command "rpmbuild --define \"_topdir ${temp_dir_name}\" --target=$arch -bs ${SPECFILE} > ${temp_dir_name}/rpmbuild.log 2>&1" "rpmbuild"
5552
     grep ^Wrote $temp_dir_name/rpmbuild.log > /dev/null 2>&1
5553
     local RC="$?"
5554
-    if [ "${RC}" -eq 0 ]; then
5555
-        local kmp_basedir="$dkms_tree/$module/$module_version/rpm"
5556
-        mkdir -p $kmp_basedir
5557
-        RPMS=`LANG=C cp -va ${temp_dir_name}/SRPMS/* $kmp_basedir | awk '{print $NF}'`
5558
+    if ((RC == 0)); then
5559
+   local kmp_basedir="$dkms_tree/$module/$module_version/rpm"
5560
+   mkdir -p $kmp_basedir
5561
+   RPMS=$(LANG=C cp -va ${temp_dir_name}/SRPMS/* $kmp_basedir | awk '{print $NF}')
5562
     else
5563
-        echo $"rpmbuild error log:"
5564
-        cat $temp_dir_name/rpmbuild.log
5565
+   echo $"rpmbuild error log:"
5566
+   cat $temp_dir_name/rpmbuild.log
5567
     fi
5568
     popd > /dev/null 2>&1
5569
     rm -rf $temp_dir_name
5570
@@ -3501,60 +2994,335 @@
5571
     return ${RC}
5572
 }
5573
 
5574
-function report_build_problem()
5575
+report_build_problem()
5576
 {
5577
     #If apport is on the system, files a build problem
5578
     if [ -x /usr/share/apport/apport ] && which python>/dev/null; then
5579
-        python /usr/share/apport/package-hooks/dkms.py -m $module -v $module_version
5580
+   python /usr/share/apport/package-hooks/dkms_packages.py -m $module -v $module_version -k ${kernelver[0]}
5581
     fi
5582
+    die "$@"
5583
 }
5584
 
5585
+# Little helper function for reading args from the commandline.
5586
+# it automatically handles -a b and -a=b variants, and returns 1 if
5587
+# we need to shift $3.
5588
+read_arg() {
5589
+    # $1 = arg name
5590
+    # $2 = arg value
5591
+    # $3 = arg parameter
5592
+    local rematch='^[^=]*=(.*)$'
5593
+    if [[ $2 =~ $rematch ]]; then
5594
+   read "$1" <<< "${BASH_REMATCH[1]}"
5595
+    else
5596
+   read "$1" <<< "$3"
5597
+   # There is no way to shift our callers args, so
5598
+   # return 1 to indicate they should do it instead.
5599
+   return 1
5600
+    fi
5601
+}
5602
 
5603
-function make_kmp()
5604
-{
5605
-    setup_kernels_arches "mkkmp"
5606
+# A couple of helper functions for parsing out our most common arguments.
5607
+# This one allows you to pass -k kernel.version-extra/arch instead of
5608
+# -k kernel-version.extra -a arch.
5609
+# This makes it harder to pass mismatching numbers of kernel/arch pairs, because
5610
+# they are all passed at the same time.
5611
+parse_kernelarch(){
5612
+    if [[ $1 =~ $mv_re ]]; then
5613
+   kernelver[${#kernelver[@]}]="${BASH_REMATCH[1]}"
5614
+   arch[${#arch[@]}]="${BASH_REMATCH[2]}"
5615
+    else
5616
+   kernelver[${#kernelver[@]}]="$1"
5617
+    fi
5618
+}
5619
+
5620
+# This allows you to pass module and module_version information on the commandline
5621
+# in a more convienent form.  Instead of the mostly mandatory and annoying
5622
+# -m module -v module_version, you can use either -m module/module_version, 
5623
+# or just a raw module/module_version with no -m parameter.  
5624
+# This vastly improves readability and discoverability of
5625
+# commands on the commandline.
5626
+parse_moduleversion(){
5627
+    if [[ $1 =~ $mv_re ]]; then
5628
+   module="${BASH_REMATCH[1]}"
5629
+   module_version="${BASH_REMATCH[2]}"
5630
+    else
5631
+   module="$1"
5632
+    fi
5633
+}
5634
+
5635
+check_root() {
5636
+    ((UID == 0)) && return
5637
+    die 1 $"You must be root to use this command."
5638
+}
5639
+
5640
+# Add a passed source tree to the default source location.
5641
+# We will check the dkms.conf file to make sure it is valid
5642
+# beforehand.
5643
+add_source_tree() {
5644
+    local from=$(readlink -f $1)
5645
+    if ! [[ $from && -f $from/dkms.conf ]]; then
5646
+   die 9 $"$1 must contain a dkms.conf file!"
5647
+    fi
5648
+    check_root
5649
+    setup_kernels_arches
5650
+    if ! get_pkginfo_from_conf "$from/dkms.conf" ; then
5651
+   die 10 $"Malformed dkms.conf file. Cannot load source tree."
5652
+    fi
5653
+    module="$PACKAGE_NAME"
5654
+    module_version="$PACKAGE_VERSION"
5655
+    if [[ $force && -d $source_tree/$module-$module_version ]]; then
5656
+   echo >&2
5657
+   echo $"Forcing install of $module-$module_version"
5658
+   rm -rf "$source_tree/$module-$module_version"
5659
+    fi
5660
 
5661
+    # We are already installed, just return.
5662
+    case $from in
5663
+   "$source_tree/$module-$module_version") return;;
5664
+   "$dkms_tree/$module/$version/source") return;;
5665
+   "$dkms_tree/$module/$version/build") return;;
5666
+    esac
5667
+    mkdir -p "$source_tree/$module-$module_version"
5668
+    cp -fr "$from"/* "$source_tree/$module-$module_version"
5669
+}
5670
+
5671
+make_kmp()
5672
+{
5673
     make_common_test "mkkmp"
5674
 
5675
     # Read the conf file
5676
-    read_conf "${kernelver_array[0]}" "${arch_array[0]}"
5677
-    if [ "$?" -ne 0 ]; then
5678
+    read_conf_or_die "$kernelver" "$arch"
5679
+
5680
+    echo $""
5681
+    if [[ $specfile && -e $dkms_tree/$module/$module_version/source/$specfile ]]; then
5682
+   echo $"Using $dkms_tree/$module/$module_version/source/$specfile"
5683
+   SPECFILE="$dkms_tree/$module/$module_version/source/$specfile"
5684
+    elif [[ -e $dkms_tree/$module/$module_version/source/$module-kmp.spec ]]; then
5685
+   echo $"Using $dkms_tree/$module/$module_version/source/$module-kmp.spec"
5686
+   SPECFILE="$dkms_tree/$module/$module_version/source/$module-kmp.spec"
5687
+    else
5688
+   die 5 $"Cannot find a suitable spec file which is needed by" \
5689
+       $"DKMS in order use mkkmp.  Please specify --spec=specfile."
5690
+    fi
5691
+
5692
+    prepare_build
5693
+    make_kmp_srpm
5694
+    RC=$?
5695
+    clean_build
5696
+
5697
+    if ((RC == 0)); then
5698
+   echo $""
5699
+   echo $"KMP SRPM location: $RPMS"
5700
+   echo $""
5701
+   echo $"DKMS: mkkmp completed."
5702
+    else
5703
+   die 7 $"There was a problem creating your KMP source rpm."
5704
+    fi
5705
+    # FIXME: hand SRPM to mock or build system to build
5706
+}
5707
+
5708
+# This code used to be in dkms_autoinstaller.
5709
+# Moving it into the main dkms script gets rid of a fair amount of duplicate
5710
+# functionality, and makes it much easier to reinstall DKMS kernel modules
5711
+# by hand if dkms_autoinstaller is not used.
5712
+autoinstall() {
5713
+    local status mv mvka m v k a last_v last_m tenative
5714
+    local -a to_install=()
5715
+    # Walk through our list of installed and built modules, and create
5716
+    # a list of modules that need to be reinstalled.
5717
+    while read status mvka; do
5718
+        IFS='/' read m v k a <<< "$mvka"
5719
+        [[ ! $last_m ]] && last_m="$m"
5720
+        # If the module is already installed or weak-installed, skip it.
5721
+        _is_module_installed "$m" "$v" "$kernelver" "$arch" && continue
5722
+        module_status_weak "$m" "$v" "$kernelver" "$arch" >/dev/null && continue
5723
+        # if the module does not want to be autoinstalled, skip it.
5724
+        read_conf_or_die "$k" "$a" "$dkms_tree/$m/$v/source/dkms.conf"
5725
+        if [[ ! $AUTOINSTALL ]]; then
5726
+            continue
5727
+        # otherwise, only autoinstall the latest version we have hanging around.
5728
+        elif [[ $last_m != $m ]]; then
5729
+            last_m="$m"
5730
+            last_v='0'
5731
+            [[ $tenative ]] && to_install[${#to_install[@]}]="$tenative"
5732
+            tenative=''
5733
+        fi
5734
+        if [[ ($(VER $v) > $(VER $last_v)) ]]; then
5735
+            last_v="$v"
5736
+            tenative="$m/$v"
5737
+        fi
5738
+    done < <(module_status)
5739
+    # We may have exited the loop with $tenative set.  If it is,
5740
+    # it contains something that should be updated.
5741
+    [[ $tenative ]] && to_install[${#to_install[@]}]="$tenative"
5742
+    [[ $to_install ]] || return 0
5743
+    # Install modules that need to be updated in parallel.
5744
+    for mv in "${to_install[@]}"; do
5745
+        IFS=/ read m v <<< "$mv"
5746
+        (module="$m"; module_version="$v"; install_module) &
5747
+    done
5748
+    wait
5749
+}
5750
+
5751
+function make_redhat3_driver_disk ()
5752
+{
5753
+    # Check that the rpmbuild command is present
5754
+    if ! which rpmbuild >/dev/null 2>&1 ; then
5755
+        echo $"" >&2
5756
+        echo $"Error! rpmbuild not present." >&2
5757
+        echo $"Install the rpm-build package." >&2
5758
+        exit 1
5759
+    fi
5760
+
5761
+    local kmodtool=$(rpm -ql redhat-rpm-config | grep kmodtool)
5762
+    #Check that the kmodtool is present
5763
+    if [ -z "$kmodtool" ]; then
5764
+        echo $"Error! kmodtool not present." >&2
5765
+        echo $"Install redhat-rpm-config package." >&2
5766
+        exit 1
5767
+    fi
5768
+
5769
+    # Check that the createrepo command is present
5770
+    if ! which createrepo >/dev/null 2>&1 ; then
5771
         echo $"" >&2
5772
-        echo $"Error! Bad conf file." >&2
5773
-        echo $"Your dkms.conf is not valid." >&2
5774
-        exit 4
5775
+        echo $"Error! createrepo not present." >&2
5776
+        echo $"Install the createrepo package." >&2
5777
+        exit 1
5778
     fi
5779
 
5780
     echo $""
5781
     if [ -n "$specfile" -a -e "$dkms_tree/$module/$module_version/source/$specfile" ]; then
5782
         echo $"Using $dkms_tree/$module/$module_version/source/$specfile"
5783
         SPECFILE="$dkms_tree/$module/$module_version/source/$specfile"
5784
-    elif [ -e "$dkms_tree/$module/$module_version/source/$module-kmp.spec" ]; then
5785
-        echo $"Using $dkms_tree/$module/$module_version/source/$module-kmp.spec"
5786
-        SPECFILE="$dkms_tree/$module/$module_version/source/$module-kmp.spec"
5787
+    elif [ -e "/etc/dkms/template-dkms-redhat-kmod.spec" ]; then
5788
+        echo $"Using /etc/dkms/template-dkms-redhat-kmod.spec"
5789
+        SPECFILE="/etc/dkms/template-dkms-redhat-kmod.spec"
5790
     else
5791
         echo $"" >&2
5792
-        echo $"Cannot find a suitable spec file which is needed by" >&2
5793
-        echo $"DKMS in order use mkkmp.  Please specify --spec=specfile." >&2
5794
+        echo $"Cannot find /etc/dkms/template-dkms-redhat-kmod.spec which is needed by" >&2
5795
+        echo $"DKMS in order to make Redhat driver disk v3." >&2
5796
         exit 5
5797
     fi
5798
+    # Set up temporary build directory for build
5799
+    rm -rf "$dkms_tree/$module/$module_version/build"
5800
+    cp -rf "$dkms_tree/$module/$module_version/source/" "$dkms_tree/$module/$module_version/build"
5801
 
5802
-    prepare_build
5803
-    make_kmp_srpm
5804
-    RC=$?
5805
-    clean_build
5806
+    cd "$dkms_tree/$module/$module_version/build"
5807
 
5808
-    if [ "$RC" -eq 0 ]; then
5809
-        echo $""
5810
-        echo $"KMP SRPM location: $RPMS"
5811
+    # Run the pre_build script
5812
+    if [ -n "$pre_build" ] && [ -x `echo "$dkms_tree/$module/$module_version/source/$pre_build" | sed 's/ .*//'` ]; then
5813
         echo $""
5814
-        echo $"DKMS: mkkmp Completed."
5815
-    else
5816
-        echo $"" >&2
5817
-        echo $"Error! There was a problem creating your KMP source rpm." >&2
5818
-        exit 7
5819
+        echo $"Running the pre_build script:"
5820
+        $dkms_tree/$module/$module_version/build/$pre_build
5821
     fi
5822
-    # FIXME: hand SRPM to mock or build system to build
5823
+
5824
+    # Apply any patches
5825
+    local index=0
5826
+    while [ $index -lt ${#patch_array[@]} ]; do
5827
+        if ! [ -e "$dkms_tree/$module/$module_version/build/patches/${patch_array[$index]}" ]; then
5828
+            echo $"" >&2
5829
+            echo $"Error!  Patch ${patch_array[$index]} as specified in dkms.conf cannot be" >&2
5830
+            echo $"found in $dkms_tree/$module/$module_version/build/patches/." >&2
5831
+            exit 5
5832
+        fi
5833
+        invoke_command "patch -p1 < ./patches/${patch_array[$index]}" "applying patch ${patch_array[$index]}"
5834
+        if [ "$?" -ne 0 ]; then
5835
+            echo $"" >&2
5836
+            echo $"Error! Application of patch ${patch_array[$index]} failed." >&2
5837
+            echo $"Check $dkms_tree/$module/$module_version/build/ for more information." >&2
5838
+                report_build_problem
5839
+            exit 6
5840
+        fi
5841
+        index=$(($index+1))
5842
+    done
5843
+    # Create temp dirs and copy files for build
5844
+    local temp_dir_name=`mktemp -d $tmp_location/dkms.XXXXXX`
5845
+    trap 'rm -rf $temp_dir_name' EXIT HUP TERM
5846
+    mkdir -p ${temp_dir_name}/{disk,BUILD,RPMS,SRPMS,SPECS,SOURCES}
5847
+    cp ${SPECFILE} ${temp_dir_name}/SPECS/$module.spec
5848
+    cp -rax $dkms_tree/$module/$module_version/build/ $temp_dir_name/SOURCES/$module-$module_version/
5849
+    # Clean the build directory
5850
+    rm -rf "$dkms_tree/$module/$module_version/build/*"
5851
+    cd $temp_dir_name/SOURCES
5852
+    invoke_command "tar -jcvf $temp_dir_name/SOURCES/$module-$module_version.tar.bz2 $module-$module_version/" "creating source tarball"
5853
+    local i=0
5854
+    #Build RPMS
5855
+    while [ $i -lt ${#kernelver[@]} ]; do
5856
+        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"
5857
+        if [ "$?" -ne 0 ]; then
5858
+            echo $"" >&2
5859
+            echo $"Error! There was a problem creating your kmod." >&2
5860
+            cat ${temp_dir_name}/rpmbuild.log >&2
5861
+            exit 7
5862
+        fi
5863
+        local kabi_whitelist=`rpm -ql kabi-whitelists | grep ${arch[$i]}`
5864
+        if [ $kabi_whitelist ]; then
5865
+            local module_file=`rpm -qlp ${temp_dir_name}/RPMS/${arch[$i]}/kmod-${module}-${module_version}* | grep ${module}.ko`
5866
+            cd ${temp_dir_name}/
5867
+            rpm2cpio ${temp_dir_name}/RPMS/${arch[$i]}/kmod-${module}-${module_version}* | cpio -id --quiet .${module_file}
5868
+            cd - > /dev/null
5869
+            local mod_symbols=( $(modprobe --dump-modversions ${temp_dir_name}/${module_file} | cut -f2) )
5870
+            local miss_sym_count=0
5871
+            local missing_symbols
5872
+            for ((i=0; i < "${#mod_symbols[@]}"; i++))
5873
+            do
5874
+               if [ -z "`grep -o ${mod_symbols[${i}]} ${kabi_whitelist}`" ]; then
5875
+                   missing_symbols[$miss_sym_count]="${mod_symbols[${i}]}"
5876
+                   miss_sym_count=$(($miss_sym_count+1))
5877
+               fi
5878
+            done
5879
+            if [ $miss_sym_count -ne 0 ]; then
5880
+                echo $"" >&2
5881
+                echo $"WARNING: ${module}-${module_version} is using following kernel symbols that are not in the ABI whitelist:"
5882
+                echo $"----------------------------------"
5883
+                for missing_symbol in ${missing_symbols[*]}
5884
+                do
5885
+                    echo "$missing_symbol"
5886
+                done
5887
+                echo $"----------------------------------"
5888
+                echo $"" >&2
5889
+            else
5890
+                echo $"NOTICE: ${module}-${module_version} module seems to use only official Red Hat ABI."
5891
+            fi
5892
+        else
5893
+            echo $"WARNING:${module}-${module_version} module is not checked against Red Hat ABI whitelist."
5894
+            echo $"Install 'kabi-whitelists' package and build driver disk again to run the ABI compliance test."
5895
+        fi    
5896
+        i=$(($i + 1))
5897
+    done
5898
+
5899
+    i=0
5900
+    while [ $i -lt ${#arch[@]} ]; do
5901
+        invoke_command "createrepo --pretty ${temp_dir_name}/RPMS/${arch[$i]}" "creating repo"
5902
+        if [ "$?" -ne 0 ]; then
5903
+            echo $"" >&2
5904
+            echo $"Error! There was a problem creating repository." >&2
5905
+            exit 7
5906
+        fi
5907
+        i=$(($i + 1))
5908
+    done
5909
+
5910
+    echo "$module-$module_version driver disk" > "${temp_dir_name}/disk/rhdd3"
5911
+    mkdir ${temp_dir_name}/disk/rpms
5912
+    cp -rax ${temp_dir_name}/RPMS/* ${temp_dir_name}/disk/rpms/
5913
+
5914
+    local suffix="$(driver_disk_suffix)"
5915
+    local image_dir="$dkms_tree/$module/$module_version/driver_disk"
5916
+    local image_name="$module-$module_version-dd.$suffix"
5917
+    echo $""
5918
+    echo $"Creating driver disk on $media media:"
5919
+    cd "${temp_dir_name}/disk"
5920
+    mkdir -p "$image_dir"
5921
+    rm -f "$image_dir/$image_name"
5922
+    make_driver_disk_media "$image_dir/$image_name" "${temp_dir_name}/disk"
5923
+    rm -rf $temp_dir_name
5924
+
5925
+    echo $""
5926
+    echo $"Disk image location: $image_dir/$image_name"
5927
+    echo $""
5928
+    echo $"DKMS: mkdriverdisk completed."
5929
+    
5930
+    trap > /dev/null 2>&1
5931
 }
5932
 
5933
 #############################
5934
@@ -3563,22 +3331,8 @@
5935
 ####                     ####
5936
 #############################
5937
 
5938
-# Set Path
5939
-case ":$PATH:" in
5940
-:/usr/sbin:)
5941
-    ;;
5942
-*)
5943
-    PATH="$PATH:/usr/sbin"
5944
-    ;;
5945
-esac
5946
-case ":$PATH:" in
5947
-:/sbin:)
5948
-    ;;
5949
-*)
5950
-    PATH="$PATH:/sbin"
5951
-    ;;
5952
-esac
5953
-PATH="$PATH:/usr/lib/dkms"
5954
+# Set a standard path
5955
+PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/lib/dkms"
5956
 
5957
 # Ensure files and directories we create are readable to anyone,
5958
 # since we aim to build as a non-root user
5959
@@ -3588,22 +3342,23 @@
5960
 unset CC CXX CFLAGS CXXFLAGS LDFLAGS
5961
 
5962
 # Set important variables
5963
-current_kernel=`uname -r`
5964
+current_kernel=$(uname -r)
5965
+current_os=$(uname -s)
5966
 dkms_tree="/var/lib/dkms"
5967
 source_tree="/usr/src"
5968
 install_tree="/lib/modules"
5969
-tmp_location="/tmp"
5970
+tmp_location=${TMPDIR:-/tmp}
5971
 verbose=""
5972
 dkms_frameworkconf="/etc/dkms/framework.conf"
5973
 
5974
 # these can come from the environment or the config file
5975
-[ -z "${ADDON_MODULES_DIR}" -a -e /etc/sysconfig/module-init-tools ] && . /etc/sysconfig/module-init-tools
5976
+[[ ! ${ADDON_MODULES_DIR} && -e /etc/sysconfig/module-init-tools ]] && . /etc/sysconfig/module-init-tools
5977
 addon_modules_dir="${ADDON_MODULES_DIR}"
5978
-[ -z "${addon_modules_dir}" ] && running_distribution="$(distro_version)"
5979
+[[ ! ${addon_modules_dir} ]] && running_distribution="$(distro_version)"
5980
 weak_modules="${WEAK_MODULES_BIN}"
5981
 
5982
 # Source in /etc/dkms_framework.conf
5983
-. $dkms_frameworkconf 2>/dev/null
5984
+[ -e $dkms_frameworkconf ] && . $dkms_frameworkconf 2>/dev/null
5985
 
5986
 # Clear out command line argument variables
5987
 module=""
5988
@@ -3629,304 +3384,135 @@
5989
 size="1440";
5990
 specfile=""
5991
 legacy_postinst="1"
5992
-unset directive_array
5993
-unset kernelver_array
5994
-unset arch_array
5995
+declare -a directive_array=() kernelver=() arch=()
5996
+weak_modules=''
5997
+last_mvka=''
5998
+last_mvka_conf=''
5999
+try_source_tree=''
6000
+die_is_fatal="yes"
6001
+[ -x /sbin/weak-modules ] && weak_modules='/sbin/weak-modules'
6002
+[ -x /usr/lib/module-init-tools/weak-modules ] && weak_modules='/usr/lib/module-init-tools/weak-modules'
6003
+
6004
+action_re='^(remove|(auto|un)?install|match|mk(driverdisk|tarball|rpm|deb|dsc|kmp)|build|add|status|ldtarball)$'
6005
 
6006
 # Parse command line arguments
6007
-while [ $# -gt 0 ]; do
6008
+while (($# > 0)); do
6009
     case $1 in
6010
-    --dkmsframework*)
6011
-        if echo $1 | grep '=' >/dev/null ; then
6012
-            dkms_frameworkconf=`echo $1 | sed 's/^.*=//'`
6013
-        else
6014
-            dkms_frameworkconf="$2"
6015
-            shift
6016
-        fi
6017
-        #immediately load this config
6018
-        . $dkms_frameworkconf 2> /dev/null
6019
-        ;;
6020
-    --module*|-m)
6021
-        if echo $1 | grep '=' >/dev/null ; then
6022
-            module=`echo $1 | sed 's/^.*=//'`
6023
-        else
6024
-            module="$2"
6025
-            shift
6026
-        fi
6027
-        ;;
6028
-    -v)
6029
-        if echo $1 | grep '=' >/dev/null ; then
6030
-            module_version=`echo $1 | sed 's/^.*=//'`
6031
-        else
6032
-            module_version="$2"
6033
-            shift
6034
-        fi
6035
-        ;;
6036
-    --kernelver*|-k)
6037
-        if echo $1 | grep '=' >/dev/null ; then
6038
-            kernelver_array[${#kernelver_array[@]}]=`echo $1 | sed 's/^.*=//'`
6039
-        else
6040
-            kernelver_array[${#kernelver_array[@]}]="$2"
6041
-            shift
6042
-        fi
6043
-        ;;
6044
-    --distro*|-d)
6045
-        if echo $1 | grep '=' >/dev/null ; then
6046
-            distro=`echo $1 | sed 's/^.*=//'`
6047
-        else
6048
-            distro="$2"
6049
-            shift
6050
-        fi
6051
-        ;;
6052
-    --media*)
6053
-        if echo $1 | grep '=' >/dev/null ; then
6054
-            media=`echo $1 | sed 's/^.*=//'`
6055
-        else
6056
-            media="$2"
6057
-            shift
6058
-        fi
6059
-        ;;
6060
-    --release*|-r)
6061
-        if echo $1 | grep '=' >/dev/null ; then
6062
-            release=`echo $1 | sed 's/^.*=//'`
6063
-        else
6064
-            release="$2"
6065
-            shift
6066
-        fi
6067
-        ;;
6068
-    --templatekernel*)
6069
-        if echo $1 | grep '=' >/dev/null ; then
6070
-            template_kernel=`echo $1 | sed 's/^.*=//'`
6071
-        else
6072
-            template_kernel="$2"
6073
-            shift
6074
-        fi
6075
-        ;;
6076
-    -c)
6077
-        if echo $1 | grep '=' >/dev/null ; then
6078
-            conf=`echo $1 | sed 's/^.*=//'`
6079
-        else
6080
-            conf="$2"
6081
-            shift
6082
-        fi
6083
-        ;;
6084
-    --quiet|-q)
6085
-        exec >/dev/null 2>&1
6086
-        ;;
6087
-    --version|-V)
6088
-        echo $"dkms: 2.1.1.2"
6089
-        exit 0
6090
-        ;;
6091
-    --no-prepare-kernel)
6092
-        no_prepare_kernel="no-prepare-kernel"
6093
-        ;;
6094
-    --no-clean-kernel)
6095
-        no_clean_kernel="no-clean-kernel"
6096
-        ;;
6097
-    --binaries-only)
6098
-        binaries_only="binaries-only"
6099
-        ;;
6100
-    --source-only)
6101
-        source_only="source-only"
6102
-        ;;
6103
-    --force)
6104
-        force="true"
6105
-        ;;
6106
-    --all)
6107
-        all="true"
6108
-        ;;
6109
-    --verbose)
6110
-        verbose="true"
6111
-        ;;
6112
-    --rpm_safe_upgrade)
6113
-        rpm_safe_upgrade="true"
6114
-        ;;
6115
-    --dkmstree*)
6116
-        if echo $1 | grep '=' >/dev/null ; then
6117
-            dkms_tree=`echo $1 | sed 's/^.*=//'`
6118
-        else
6119
-            dkms_tree="$2"
6120
-            shift
6121
-        fi
6122
-        ;;
6123
-    --sourcetree*)
6124
-        if echo $1 | grep '=' >/dev/null ; then
6125
-            source_tree=`echo $1 | sed 's/^.*=//'`
6126
-        else
6127
-            source_tree="$2"
6128
-            shift
6129
-        fi
6130
-        ;;
6131
-    --installtree*)
6132
-        if echo $1 | grep '=' >/dev/null ; then
6133
-            install_tree=`echo $1 | sed 's/^.*=//'`
6134
-        else
6135
-            install_tree="$2"
6136
-            shift
6137
-        fi
6138
-        ;;
6139
-    --config*)
6140
-        if echo $1 | grep '=' >/dev/null ; then
6141
-            kernel_config=`echo $1 | sed 's/^.*=//'`
6142
-        else
6143
-            kernel_config="$2"
6144
-            shift
6145
-        fi
6146
-        ;;
6147
-    --archive*)
6148
-        if echo $1 | grep '=' >/dev/null ; then
6149
-            archive_location=`echo $1 | sed 's/^.*=//'`
6150
-        else
6151
-            archive_location="$2"
6152
-            shift
6153
-        fi
6154
-        ;;
6155
-    --legacy-postinst*)
6156
-        if echo $1 | grep "=" >/dev/null ; then
6157
-            legacy_postinst=`echo $1 | sed 's/^.*=//'`
6158
-        else
6159
-            legacy_postinst="$2"
6160
-            shift
6161
-        fi
6162
-        ;;
6163
-    --arch*|-a)
6164
-        if echo $1 | grep '=' >/dev/null ; then
6165
-            arch_array[${#arch_array[@]}]=`echo $1 | sed 's/^.*=//'`
6166
-        else
6167
-            arch_array[${#arch_array[@]}]="$2"
6168
-            shift
6169
-        fi
6170
-        ;;
6171
-    --size*)
6172
-        if echo $1 | grep '=' >/dev/null ; then
6173
-            size=`echo $1 | sed 's/^.*=//'`
6174
-        else
6175
-            size="$2"
6176
-            shift
6177
-        fi
6178
-        ;;
6179
-    --kernelsourcedir*)
6180
-        if echo $1 | grep '=' >/dev/null ; then
6181
-            kernel_source_dir=`echo $1 | sed 's/^.*=//'`
6182
-        else
6183
-            kernel_source_dir="$2"
6184
-            shift
6185
-        fi
6186
-        ksourcedir_fromcli="true"
6187
-        ;;
6188
-    --directive*)
6189
-        if echo $1 | grep '=' >/dev/null ; then
6190
-            directive_array[${#directive_array[@]}]=`echo $1 | sed 's/[^=]\+=//'`
6191
-        else
6192
-            directive_array[${#directive_array[@]}]="$2"
6193
-            shift
6194
-        fi
6195
-        ;;
6196
-    --spec*)
6197
-        if echo $1 | grep '=' >/dev/null ; then
6198
-            specfile=`echo $1 | sed 's/^.*=//'`
6199
-        else
6200
-            specfile="$2"
6201
-            shift
6202
-        fi
6203
-        ;;
6204
-    -*|--*)
6205
-        echo $"" >&2
6206
-        echo $"Error!  Unknown option: $1" >&2
6207
-        show_usage
6208
-        exit 2
6209
-        ;;
6210
-    *)
6211
-        action="$action $1"
6212
-        ;;
6213
+   --dkmsframework*)    read_arg dkms_frameworkconf "$1" "$2" || shift
6214
+                #immediately load this config
6215
+                . $dkms_frameworkconf 2> /dev/null;;
6216
+   --module*|-m)        read_arg _mv "$1" "$2" || shift
6217
+                parse_moduleversion "$_mv";;
6218
+   -v)                  read_arg module_version "$1" "$2" || shift;;
6219
+   --kernelver*|-k)     read_arg _ka "$1" "$2" || shift
6220
+                parse_kernelarch "$_ka";;
6221
+   --distro*|-d)        read_arg distro "$1" "$2" || shift;;
6222
+   --media*)            read_arg media "$1" "$2" ||shift;;
6223
+   --release*|-r)       read_arg release "$1" "$2" || shift;;
6224
+   --templatekernel*)   read_arg template_kernel "$1" "$2" || shift;;
6225
+   -c)                  read_arg conf "$1" "$2" || shift;;
6226
+   --quiet|-q)          exec >/dev/null 2>&1;;
6227
+   --version|-V)        echo $"dkms: 2.2.0.3"
6228
+                exit 0;;
6229
+   --no-prepare-kernel) no_prepare_kernel="no-prepare-kernel";;
6230
+   --no-clean-kernel)   no_clean_kernel="no-clean-kernel";;
6231
+   --no-initrd)         no_initrd="no-initrd";;
6232
+   --binaries-only)     binaries_only="binaries-only";;
6233
+   --source-only)       source_only="source-only";;
6234
+   --force)             force="true";;
6235
+   --all)               all="true";;
6236
+   --verbose)           verbose="true";;
6237
+   --rpm_safe_upgrade)  rpm_safe_upgrade="true";;
6238
+   --dkmstree*)         read_arg dkms_tree "$1" "$2" || shift;;
6239
+   --sourcetree*)       read_arg source_tree "$1" "$2" || shift;;
6240
+   --installtree*)      read_arg install_tree "$1" "$2" || shift;;
6241
+   --config*)           read_arg kernel_config "$1" "$2" || shift;;
6242
+   --archive*)          read_arg archive_location "$1" "$2" || shift;;
6243
+   --legacy-postinst*)  read_arg legacy_postinst "$1" "$2" || shift;;
6244
+   --arch*|-a)          read_arg _aa "$1" "$2" || shift
6245
+                arch[${#arch[@]}]="$_aa";;
6246
+   --size*)             read_arg size "$1" "$2" || shift;;
6247
+   --kernelsourcedir*)  read_arg kernel_source_dir "$1" "$2" || shift
6248
+                ksourcedir_fromcli="true";;
6249
+   --directive*)        read_arg _da "$1" "$2" || shift
6250
+                directive_array[${#directive_array[@]}]="$_da";;
6251
+   --spec*)             read_arg specfile "$1" "$2" || shift;;
6252
+   --debug)
6253
+       export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
6254
+       set -x;;
6255
+   -*|--*)              error $" Unknown option: $1"
6256
+                show_usage
6257
+                exit 2;;
6258
+   *) if [[ $1 =~ $action_re ]]; then
6259
+       action="$action $1" # Add actions to the action list
6260
+       elif [[ -f $1 && $1 = *dkms.conf ]]; then
6261
+       try_source_tree="${1%dkms.conf}./" # Flag as a source tree
6262
+       elif [[ -d $1 && -f $1/dkms.conf ]]; then
6263
+       try_source_tree="$1" # ditto
6264
+       elif [[ -f $1 ]]; then
6265
+       archive_location="$1" # It is a file, assume it is an archive.
6266
+       elif [[ ! $module ]]; then
6267
+       parse_moduleversion "$1" # Assume it is a module/version pair.
6268
+       else
6269
+       warn $"I do not know how to handle $1."
6270
+       fi;;
6271
     esac
6272
     shift
6273
 done
6274
 
6275
+# Sanity checking
6276
+
6277
+# Error out if binaries-only is set and source-only is set
6278
+if [[ $binaries_only && $source_only ]]; then
6279
+    die 8 $" You have specified both --binaries-only and --source-only." \
6280
+   $"You cannot do this."
6281
+fi
6282
+
6283
+# Error if # of arches doesn't match # of kernels
6284
+if (( ${#kernelver[@]} != ${#arch[@]} && \
6285
+    ${#arch[@]} > 1 )); then
6286
+    die 1 $" If more than one arch is specified on the command line, then there" \
6287
+   $"must be an equal number of kernel versions also specified (1:1 relationship)."
6288
+fi
6289
+
6290
+# Check that kernel version and all aren't both set simultaneously
6291
+if [[ $kernelver && $all ]]; then
6292
+    die 2 $" You cannot specify a kernel version and also specify" \
6293
+   $"--all on the command line."
6294
+fi
6295
+
6296
+# Check that arch and all aren't both set simultaneously
6297
+if [[ $arch && $all ]]; then
6298
+    die 3 $" You cannot specify an arch and also specify" \
6299
+   $"--all on the command line."
6300
+fi
6301
+
6302
 # Run the specified action
6303
 for action_to_run in $action; do
6304
+    setup_kernels_arches "$action_to_run"
6305
     case "$action_to_run" in
6306
-    add)
6307
-        add_module
6308
-        ;;
6309
-    remove)
6310
-        # Make sure they're root
6311
-        if [ `id -u` -ne 0 ]; then
6312
-        echo $"You must be root to use this command." >&2
6313
-        exit 1
6314
-        fi
6315
-        remove_module
6316
-        ;;
6317
-    build)
6318
-        build_module
6319
-        ;;
6320
-    install)
6321
-            # Make sure they're root
6322
-        if [ `id -u` -ne 0 ]; then
6323
-        echo $"You must be root to use this command." >&2
6324
-        exit 1
6325
-        fi
6326
-        install_module
6327
-        ;;
6328
-    match)
6329
-        # Make sure they're root
6330
-        if [ `id -u` -ne 0 ]; then
6331
-        echo $"You must be root to use this command." >&2
6332
-        exit 1
6333
-        fi
6334
-        run_match
6335
-        ;;
6336
-    uninstall)
6337
-        # Make sure they're root
6338
-        if [ `id -u` -ne 0 ]; then
6339
-        echo $"You must be root to use this command." >&2
6340
-        exit 1
6341
-        fi
6342
-        uninstall_module
6343
-        ;;
6344
-    mkdriverdisk)
6345
-        # Make sure they're root
6346
-        if [ `id -u` -ne 0 ]; then
6347
-        echo $"You must be root to use this command." >&2
6348
-        exit 1
6349
-        fi
6350
-        make_driver_disk
6351
-        ;;
6352
-    mktarball)
6353
-        make_tarball
6354
-        ;;
6355
-    mkrpm)
6356
-        make_rpm
6357
-        ;;
6358
-    mkdeb)
6359
-        make_debian "deb"
6360
-        ;;
6361
-    mkdsc)
6362
-        make_debian "dsc"
6363
-        ;;
6364
-    mkkmp)
6365
-        make_kmp
6366
-        ;;
6367
-    ldtarball)
6368
-        # Make sure they're root if we're using --force
6369
-        if [ `id -u` -ne 0 ] && [ "$force" == "true" ]; then
6370
-        echo $"You must be root to use this command with the --force option." >&2
6371
-        exit 1
6372
-        fi
6373
-        load_tarball
6374
-        ;;
6375
-    status)
6376
-        show_status
6377
-        ;;
6378
-    "")
6379
-        echo "" >&2
6380
-        echo $"Error! No action was specified.">&2
6381
-        show_usage
6382
-        ;;
6383
-    *)
6384
-        echo "" >&2
6385
-        echo $"Error! Unknown action specified: $action_to_run" >&2
6386
-        show_usage
6387
-        ;;
6388
+   remove)       check_root && remove_module;;
6389
+   install)      check_root && install_modules;;
6390
+   autoinstall)  check_root && autoinstall;;
6391
+   match)        check_root && have_one_kernel && run_match;;
6392
+   uninstall)    check_root && have_one_kernel && uninstall_module;;
6393
+   mkdriverdisk) check_root && make_driver_disk;;
6394
+   build)        build_modules;;
6395
+   add)          add_module;;
6396
+   mktarball)    make_tarball;;
6397
+   mkrpm)        make_rpm;;
6398
+   mkdeb)        make_debian "deb";;
6399
+   mkdsc)        make_debian "dsc";;
6400
+   mkkmp)        have_one_kernel && make_kmp;;
6401
+   status)       show_status;;
6402
+   ldtarball) # Make sure they're root if we're using --force
6403
+       if ((UID != 0)) && [[ $force = true ]]; then
6404
+       die 1 $"You must be root to use this command with the --force option."
6405
+       fi
6406
+       load_tarball && add_module;;
6407
+   '') error $"No action was specified."
6408
+       show_usage;;
6409
+   *)  error $"Unknown action specified: $action_to_run"
6410
+       show_usage;;
6411
     esac
6412
 done
6413
dkms-2.1.1.2.tar.bz2/dkms.8 -> dkms-2.2.0.3.tar.bz2/dkms.8 Changed
392
 
1
@@ -3,46 +3,108 @@
2
 .SH NAME
3
 dkms \- Dynamic Kernel Module Support
4
 .SH SYNOPSIS
5
-.B dkms
6
-.I [action] [options]
7
+.SY dkms
8
+.OP action 
9
+.OP options
10
+.OP module/module-version
11
+.OP /path/to/source-tree
12
+.OP /path/to/tarball.tar
13
+.OP /path/to/driver.rpm
14
+.YS
15
 .SH DESCRIPTION
16
 .B dkms
17
 is a framework which allows kernel modules to be dynamically built
18
 for each kernel on your system in a simplified and organized fashion.
19
 .SH ACTIONS
20
-.TP
21
-.B add
22
-Adds a module/version combination to the tree for builds and installs.
23
-Requires source in
24
+.SY add
25
+.OP module/module\-version
26
+.OP /path/to/source\-tree
27
+.OP /path/to/tarball.tar
28
+.YS
29
+.IP "" 4
30
+Adds a module/module\-version combination to the tree for builds and installs.
31
+If module/module\-version, \-m module/module\-version, or \-m module\ \-v version are passed as options, this command
32
+requires source in
33
 .I /usr/src/<module>\-<module\-version>/
34
 as well as a properly
35
 formatted
36
 .I dkms.conf
37
-file.
38
-.TP
39
-.B remove
40
-Removes a module/version or module/version/kernel combination from the
41
-tree.  If the modules is currently installed, it first uninstalls it
42
+file. If 
43
+.I /path/to/source\-tree
44
+is passed as an option, and source-tree contains a 
45
+.I dkms.conf
46
+file, it will copy 
47
+.I /path/to/source\-tree
48
+to
49
+.I /usr/src/module\-module\-version.
50
+If 
51
+.I /path/to/tarball.tar
52
+is passed, this command behaves like the
53
+.B ldtarball
54
+command.
55
+.SY remove
56
+.OP module/module\-version
57
+.OP -k kernel/arch
58
+.OP \-\-all
59
+.YS
60
+.IP "" 4
61
+Removes a module/version or module/version/kernel/arch combination from the
62
+tree.  If the module is currently installed, it first uninstalls it
63
 and if applicable, will replace it with its original_module.  Use the
64
 .B \-\-all
65
 option in order to remove all instances for every kernel at once.
66
-.TP
67
-.B build
68
-Builds the specified module/version combo for the specified kernel. If
69
-no kernel is specified it builds for the currently running kernel.  All builds
70
+.SY build
71
+.OP module/module\-version
72
+.OP -k kernel/arch
73
+.YS
74
+.IP "" 4
75
+Builds the specified module/version combo for the specified kernel/arch. If
76
+the
77
+.I \-k
78
+option is not specified it builds for the currently running kernel and arch..  All builds
79
 occur in the directory
80
-.I /var/lib/dkms/<module>/<module\-version>/build/.
81
-.TP
82
-.B install
83
+.I /var/lib/dkms/<module>/<module\-version>/build/. 
84
+If the module/module\-version combo has not been added, dkms will try to add it, and in that
85
+case 
86
+.B build 
87
+can take the same arguments that 
88
+.B add
89
+can.
90
+.SY install
91
+.OP module/module\-version
92
+.OP -k kernel/arch
93
+.OP /path/to/driver.rpm
94
+.YS
95
+.IP "" 4
96
 Installs a built module/version combo onto the kernel it was built for. If
97
 the kernel option is not specified it assumes the currently running kernel.
98
-.TP
99
-.B uninstall
100
-Uninstalls an installed module/version combo from the kernel it was installed
101
+If the module has not been built, dkms will try to build it.
102
+If the module has not been added, dkms will try to add it.  In both cases, the
103
+.B install
104
+command can then take the same arguments as the
105
+.B build
106
+or
107
+.B add
108
+commands.
109
+If you pass a .rpm file, dkms will try to install that file with
110
+.B rpm -Uvh
111
+, and it will perform an
112
+.B autoinstall
113
+action to mesure that everything is built for your kernel if the RPM installed sucessfully.
114
+.SY uninstall
115
+.OP module/module\-version
116
+.OP -k kernel/arch
117
+.YS
118
+.IP "" 4
119
+Uninstalls an installed module/module\-version combo from the kernel/arch passed in the -k option, or the
120
+current kernel if the -k option was not passed.
121
 upon.  After uninstall completion, the driver will be left in the built state.
122
 To completely remove a driver, the remove action should be utilized.
123
-.TP
124
-.B match
125
+.SY match
126
+.OP --templatekernel kernel/arch
127
+.OP -k kernel/arch
128
+.YS
129
+.IP "" 4
130
 Match installs modules onto the specified kernel by looking at the
131
 configuration of the specified
132
 .B templatekernel.
133
@@ -51,8 +113,14 @@
134
 within
135
 .B dkms
136
 is then installed on that specified kernel.
137
-.TP
138
-.B mkdriverdisk
139
+.SY mkdriverdisk
140
+.OP -d distro
141
+.OP -r release
142
+.OP --media mediatype
143
+.OP -k kernel/arch
144
+.OP module/version
145
+.YS
146
+.IP "" 4
147
 Creates a floppy driver disk image for use when updated drivers are needed
148
 to install an OS.  Currently, the supported distributions are redhat, suse
149
 and UnitedLinux. For Red Hat driver disks, necessary driver disk files are
150
@@ -61,7 +129,7 @@
151
 must specify the distro while using this action.  Driver disks can be made
152
 for single kernels or can be made to support multiple kernels.  To create
153
 a driver disk image with modules for multiple kernels, just specify multiple
154
-\-k parameters on the command line (\-k kernel1 \-k kernel2 \-a arch1 \-a arch2).
155
+\-k parameters on the command line (\-k kernel1/arch1 \-k kernel2/arch2).
156
 
157
 Red Hat began supporting multi-arched driver disks in RHEL3.  To force creation
158
 of a driver disk with arch information, specify
159
@@ -77,6 +145,13 @@
160
 allows for this, and as such you can create a redhat1 style driver disk if the
161
 only other arch is i386 and the kernel name ends in BOOT.
162
 
163
+Red Hat introduced DDv3 starting with RHEL6. To create Red Hat DDv3, specify
164
+.B \-d redhat3
165
+and specify the specfile to use with
166
+.I \-\-spec=specfile.
167
+If no specfile is specified, DKMS will use
168
+.I /etc/dkms/template\-dkms\-redhat\-kmod.spec
169
+
170
 See
171
 .I http://people.redhat.com/dledford
172
 for more information on the Red Hat driver
173
@@ -97,28 +172,32 @@
174
 
175
 You may have more content than will fit on a floppy.  Therefore, DKMS
176
 can now generate image files of different types.
177
-.B \-\-media=floppy (default)
178
+.B \-\-media floppy (default)
179
 to generate a floppy disk image, or
180
-.B \-\-media=iso
181
+.B \-\-media iso
182
 to generate a CD-ROM ISO file, or
183
-.B \-\-media=tar
184
+.B \-\-media tar
185
 to generate a tar file.
186
 
187
 You may copy the floppy or ISO image file to a USB key to be used with
188
 OS installer.
189
-
190
-
191
-.TP
192
-.B mktarball
193
+.SY mktarball
194
+.OP module/module\-version
195
+.OP -k kernel/arch
196
+.OP --archive /path/to/tarball.tar
197
+.OP --source-only
198
+.OP --binaries-only
199
+.YS
200
+.IP "" 4
201
 Creates a tarball archive for the specified module/version of all files
202
 in the DKMS tree for that module/version combination.  This includes
203
 the source and any built modules for kernels in the tree (as specified).
204
 Otherwise, you can specify
205
 a singular kernel to archive only, or multiple kernels to archive
206
-(\-k kernel1 \-k kernel2 \-a arch1 \-a arch2).  Optionally, you can use
207
+(\-k kernel1/arch1 \-k kernel2/arch2).  Optionally, you can use
208
 .B \-\-archive
209
-to specify the name (with no preceding path) that you would like this
210
-tarball to have.  You can also specify
211
+to specify the file that you would like to save this
212
+tarball to.  You can also specify
213
 .B \-\-binaries\-only
214
 if you want the resultant tarball not to include the module source.  Likewise,
215
 .B \-\-source-only
216
@@ -130,13 +209,14 @@
217
 .B ldtarball
218
 on all of your other systems to get the same built modules loaded
219
 without having to wait for anything to compile.
220
-.TP
221
-.B ldtarball
222
+.SY ldtarball
223
+.OS /path/to/tarball.tar
224
+.OS --force
225
+.YS
226
+.IP "" 4
227
 This takes a tarball made from the
228
-.B mktarball
229
-command and specified with the
230
-.B \-\-archive
231
-option and loads it into your DKMS tree.  This will leave any
232
+.B mktarball 
233
+command and loads it into your DKMS tree.  This will leave any
234
 newly added modules in the built state and
235
 .B dkms install
236
 should then be called to install any of them.  If files already
237
@@ -145,8 +225,13 @@
238
 is attempting to place them, it will warn and not copy over them.  The
239
 .B \-\-force
240
 option should be used to override this.
241
-.TP
242
-.B mkrpm
243
+.SY mkrpm
244
+.OP module/module\-version
245
+.OP -k kernel/arch
246
+.OP --source-only
247
+.OP --binaries-only
248
+.YS
249
+.IP "" 4
250
 This action allows you to create an RPM package for a specified module / version.
251
 It uses a template .spec file found in
252
 .I /etc/dkms/template\-dkms\-mkrpm.spec
253
@@ -159,7 +244,13 @@
254
 .B \-\-source\-only
255
 in the mkrpm command.
256
 .TP
257
-.B mkdeb
258
+.SY mkdeb
259
+.OP module/module\-version
260
+.OP -k kernel/arch
261
+.OP --binaries-only
262
+.OP --source-only
263
+.YS
264
+.IP "" 4
265
 This action allows you to create a debian binary package for a specified module / version.
266
 It uses a template debian directory found in
267
 .I /etc/dkms/template\-dkms\-mkdeb
268
@@ -171,8 +262,13 @@
269
 not want your debian package to contain any prebuilt binaries, be sure to specify
270
 .B \-\-source\-only
271
 in the mkdeb command.
272
-.TP
273
-.B mkdsc
274
+.SY mkdsc
275
+.OP module/module\-version
276
+.OP -k kernel/arch
277
+.OP --binaries-only
278
+.OP --source-only
279
+.YS
280
+.IP "" 4
281
 This action allows you to create a debian source package for a specified module / version.
282
 It will create a .tar.gz, and a .dsc.  All options supported by
283
 .B mkdeb
284
@@ -184,8 +280,11 @@
285
 contain any prebuilt binaries, be sure to specify
286
 .B \-\-source\-only
287
 in the mkdsc command.
288
-.TP
289
-.B mkkmp
290
+.SY mkkmp
291
+.OP module/module\-version
292
+.OP --spec specfile
293
+.YS
294
+.IP "" 4
295
 This action allows you to create an Kernel Module Package source RPM for a specified module / version.
296
 It uses the .spec file specified by
297
 .I \-\-spec=specfile
298
@@ -194,28 +293,45 @@
299
 as the basis for the RPM.  The generated source RPM may then be built using SuSE's build.rpm or
300
 Fedora/RHEL's mock chroot environments.  See http://kerneldrivers.org/ for
301
 more details on KMPs.
302
-.TP
303
-.B status
304
+.SY status
305
+.OP module/module\-version
306
+.OP -k kernel/arch
307
+.YS
308
+.IP "" 4
309
 Returns the current status of modules, versions and kernels within
310
 the tree as well as whether they have been added, built or installed.
311
 Status can be shown for just a certain module, a certain kernel,
312
 a module/version combination or a module/version/kernel combination.
313
+.SY autoinstall
314
+.YS
315
+.IP "" 4
316
+Attempt to install the latest revision of all modules that have been installed for other kernel revisions.
317
+dkms_autoinstaller is a stub that uses this action to perform its work.
318
 .SH OPTIONS
319
 .TP
320
-.B \-m <module>
321
-The name of the module.
322
+.B \-m <module>/<module\-version>
323
+The name of the module and module version you wnat to operate on. The
324
+.B \-m
325
+part of this option is optional, and can be omitted in virtually all circumstances.
326
 .TP
327
 .B \-v <module\-version>
328
-The version of the module to execute the specified action upon.
329
+The version of the module to execute the specified action upon.  This option only has to be specified 
330
+if you pass a 
331
+.B \-m
332
+option without a <module\-version> component of its own.
333
 .TP
334
-.B \-k <kernel\-version>
335
-The kernel to perform the action upon.  You can specify multiple kernel versions
336
-on the command line by repeating the \-k argument with a different kernel name.
337
+.B \-k <kernel\-version>/<arch>
338
+The kernel and arch to perform the action upon.  You can specify multiple kernel version/arch pairs
339
+on the command line by repeating the \-k argument with a different kernel version and arch.
340
 However, not all actions support multiple kernel versions (it will error out
341
 in this case).
342
+The arch part can be omitted, and DKMS will assume you want it to be the arch of the currently running
343
+system.
344
 .TP
345
 .B \-a, \-\-arch
346
-The system architecture to perform the action upon.  If not specified, it assumes
347
+The system architecture to perform the action upon.  It is optional if you pass it as part of the
348
+.B \-k
349
+option. If not specified, it assumes
350
 the arch of the currently running system (`uname \-m`).  You can specify multiple
351
 arch parameters on the same command line by repeating the \-a argument with a
352
 different arch name.  When multiple architectures are specified, there must
353
@@ -286,7 +402,9 @@
354
 This option is used during a
355
 .B ldtarball
356
 action to specify the location of the tarball you wish to load into
357
-your DKMS tree.
358
+your DKMS tree.  You only have to specify the
359
+.B --archive
360
+part of this option if <tarball\-location> does not already exist as a file.
361
 .TP
362
 .B \-\-templatekernel <kernel\-version>
363
 This option is required for the action:
364
@@ -477,6 +595,9 @@
365
 will be used to build your module. If no MAKE directive is specified or if no
366
 MAKE_MATCH matches the kernel being built for, DKMS
367
 will attempt to use a generic MAKE command to build your module.
368
+
369
+KERNELRELEASE will be automatically appended to MAKE[#].  If you want to
370
+suppress this behavior, you can quote the make command: 'make'.
371
 .TP
372
 .B MAKE_MATCH[#]=
373
 See the above entry on
374
@@ -783,6 +904,17 @@
375
 , unless otherwise specified with the
376
 .B \-\-kernelsourcedir
377
 option.
378
+.SH DKMS.CONF OVERRIDES
379
+You can override the module-provided
380
+.I dkms.conf
381
+files. Every time after a  dkms.conf file is read, dkms will look for and read the following files in order:
382
+
383
+.I /etc/dkms/<module>.conf\p
384
+.I /etc/dkms/<module>\-<module\-version>.conf\p
385
+.I /etc/dkms/<module>\-<module\-version>\-<kernel>.conf\p
386
+.I /etc/dkms/<module>\-<module\-version>\-<kernel>\-<arch>.conf
387
+
388
+You can use these files to override settings in the module-provided dkms.conf files.
389
 .SH /etc/dkms/framework.conf
390
 This configuration file controls how the overall DKMS framework handles.  It is sourced
391
 in every time the dkms command is run.  Mainly it can currently be used to set different
392
dkms-2.1.1.2.tar.bz2/dkms.bash-completion -> dkms-2.2.0.3.tar.bz2/dkms.bash-completion Changed
10
 
1
@@ -29,7 +29,7 @@
2
    cur=${COMP_WORDS[COMP_CWORD]}
3
 
4
    if [[ $COMP_CWORD -eq 1 ]] ; then
5
-       COMPREPLY=( $( compgen -W "add remove build install uninstall \
6
+       COMPREPLY=( $( compgen -W "add autoinstall remove build install uninstall \
7
            match mkdriverdisk mktarball ldtarball mkrpm mkdeb mkdsc mkkmp \
8
            status" -- $cur ) )
9
    else
10
dkms-2.1.1.2.tar.bz2/dkms.spec -> dkms-2.2.0.3.tar.bz2/dkms.spec Changed
22
 
1
@@ -1,6 +1,6 @@
2
 Summary: Dynamic Kernel Module Support Framework
3
 Name: dkms
4
-Version: 2.1.1.2
5
+Version: 2.2.0.3
6
 Release: 1%{?dist}
7
 License: GPLv2+
8
 Group: System Environment/Base
9
@@ -97,11 +97,10 @@
10
 %doc sample.spec sample.conf AUTHORS COPYING README.dkms
11
 %doc sample-suse-9-mkkmp.spec sample-suse-10-mkkmp.spec
12
 # these dirs are for plugins - owned by other packages
13
-%{_initrddir}/dkms_autoinstaller
14
+%{_initddir}/dkms_autoinstaller
15
 %{_sysconfdir}/kernel/postinst.d/%{name}
16
 %{_sysconfdir}/kernel/prerm.d/%{name}
17
 %{_sysconfdir}/bash_completion.d/%{name}
18
-%{_datadir}/apport/package-hooks/%{name}.py
19
 
20
 %if 0%{?suse_version}
21
 # suse doesnt yet support /etc/kernel/{prerm.d,postinst.d}, but will fail build
22
dkms-2.1.1.2.tar.bz2/dkms_apport.py -> dkms-2.2.0.3.tar.bz2/dkms_apport.py Changed
81
 
1
@@ -24,35 +24,72 @@
2
 import sys
3
 import subprocess, optparse
4
 
5
+from datetime import datetime
6
+
7
 optparser = optparse.OptionParser('%prog [options]')
8
 optparser.add_option('-m', help="Specify the DKMS module to find the package for",
9
                      action='store', type='string', dest='module')
10
 optparser.add_option('-v', help="Specify the DKMS version to find the package for",
11
                      action='store', type='string', dest='version')
12
+optparser.add_option('-k', help="Specify the kernel version",
13
+                     action='store', type='string', dest='kernel')
14
 options=optparser.parse_args()[0]
15
 
16
 if not options.module or not options.version:
17
-    print >> sys.stderr, 'ERROR, both -m and -v are required'
18
+    print >> sys.stderr, 'ERROR (dkms apport): both -m and -v are required'
19
     sys.exit(2)
20
 
21
 package=packaging.get_file_package('/usr/src/' + options.module + '-' + options.version)
22
 if package is None:
23
-    print >> sys.stderr, 'ERROR: binary package for %s: %s not found' % (options.module,options.version)
24
+    print >> sys.stderr, 'ERROR (dkms apport): binary package for %s: %s not found' % (options.module,options.version)
25
     sys.exit(1)
26
 
27
+if options.kernel:
28
+    # TODO: Ubuntu specific
29
+    kernel_package = "linux-headers-" + options.kernel
30
+
31
+    try:
32
+        apport.packaging.is_distro_package(kernel_package)
33
+    except ValueError, e:
34
+        if e == 'package does not exist':
35
+            print >> sys.stderr, 'ERROR (dkms apport): kernel package %s is not supported' % (kernel_package)
36
+            sys.exit(1)
37
+
38
 make_log=os.path.join('/var','lib','dkms',options.module,options.version,'build','make.log')
39
 
40
 report = apport.Report('Package')
41
 report['Package'] = package
42
-report['SourcePackage'] = apport.packaging.get_source(package)
43
-report['ErrorMessage'] = "%s kernel module failed to build" % options.module
44
+try:
45
+    report['SourcePackage'] = apport.packaging.get_source(package)
46
+except ValueError:
47
+    print >> sys.stderr, 'ERROR (dkms apport): unable to determine source package for %s' % package
48
+    sys.exit(3)
49
 try:
50
     version = packaging.get_version(package)
51
 except ValueError:
52
-    version = 'N/A'
53
+    version = '(not installed)'
54
 if version is None:
55
-    version = 'N/A'
56
+    version = '(not installed)'
57
+
58
+if report['SourcePackage'] == 'fglrx-installer':
59
+    fglrx_make_log = os.path.join('/var','lib','dkms',options.module,options.version,'build','make.sh.log')
60
+    attach_file_if_exists(report, fglrx_make_log, 'FglrxBuildLog')
61
+
62
 report['PackageVersion'] = version
63
+report['Title'] = "%s %s: %s kernel module failed to build" % (package, version, options.module)
64
 attach_file_if_exists(report, make_log, 'DKMSBuildLog')
65
-report.write(open(apport.fileutils.make_report_path(report), 'w'))
66
+if 'DKMSBuildLog' in report:
67
+    this_year = str(datetime.today().year)
68
+    if 'Segmentation fault' in report['DKMSBuildLog']:
69
+        print >> sys.stderr, 'ERROR (dkms apport): There was a segmentation fault when trying to build the module'
70
+        sys.exit(1)
71
+    dupe_sig = ''
72
+    for line in report['DKMSBuildLog'].split('\n'):
73
+        if line.endswith(this_year):
74
+            continue
75
+        dupe_sig += line + '\n'
76
+    report['DuplicateSignature'] = dupe_sig
77
 
78
+if options.kernel:
79
+    report['DKMSKernelVersion'] = options.kernel
80
+report.write(open(apport.fileutils.make_report_path(report), 'w'))
81
dkms-2.1.1.2.tar.bz2/dkms_autoinstaller -> dkms-2.2.0.3.tar.bz2/dkms_autoinstaller Changed
157
 
1
@@ -17,139 +17,30 @@
2
 
3
 test -f /usr/sbin/dkms || exit 0
4
 
5
-#We only have these functions on debian/ubuntu
6
-# so on other distros just stub them out
7
 if [ -f /lib/lsb/init-functions ]; then
8
     . /lib/lsb/init-functions
9
-    if [ ! -f /etc/debian_version ]; then
10
-        alias log_daemon_msg=echo
11
-        log_end_msg() { if [ "$1" = "0" ]; then echo " Done. "; else echo " Failed. "; fi }
12
-        alias log_action_begin_msg=log_daemon_msg
13
-        alias log_action_end_msg=log_end_msg
14
-    fi
15
+fi
16
+#We only have these functions on debian/ubuntu
17
+# so on other distros just stub them out
18
+if [ ! -f /etc/debian_version ]; then
19
+    alias log_daemon_msg=/bin/echo
20
+    log_end_msg() { if [ "$1" = "0" ]; then echo " Done. "; else echo " Failed. "; fi }
21
+    alias log_action_begin_msg=log_daemon_msg
22
+    alias log_action_end_msg=log_end_msg
23
 fi
24
 
25
-invoke_command ()
26
-{
27
-    local exitval=0
28
-    local exitval_file=`mktemp /tmp/dkms.XXXXXX`
29
-    if [ "$3" = background ] && [ -z "$verbose" ]; then
30
-        (eval $1 >/dev/null 2>&1; echo "exitval=$?" >> "$exitval_file") &
31
-        while [ -e "$exitval_file" ] && ! [ -s "$exitval_file" ]; do
32
-            sleep 3
33
-        done
34
-        . "$exitval_file"
35
-    else
36
-        eval $1; exitval=$?
37
-    fi
38
-    [ $exitval -gt 0 ] && logger -t dkms_autoinstaller "(bad exit status: $exitval)"
39
-    rm -f "$exitval_file"
40
-    return $exitval
41
-}
42
-
43
-# Set Variables
44
-uname=`uname -mr`
45
-[ -n "$2" ] && kernel=$2
46
-arch=${uname#* }
47
-kernel_preparation_done=""
48
-dkms_tree="/var/lib/dkms"
49
-. /etc/dkms/framework.conf 2>/dev/null
50
+if [ -n "$2" ]; then
51
+    kernel="$2"
52
+else
53
+    kernel=`uname -r`
54
+fi
55
 
56
 # See how we were called.
57
 case "$1" in
58
   start)
59
-    log_daemon_msg "Running DKMS auto installation service for kernel $kernel"
60
-
61
-    if [ -z "$kernel" ]; then
62
-        if [ -L /vmlinuz -a -e /vmlinuz ]; then
63
-            linktarget="$(basename "$(readlink /vmlinuz)")"
64
-            kernel="${linktarget##vmlinuz-}"
65
-        else
66
-            kernel=${uname% *}
67
-        fi
68
-    fi
69
-
70
-    # Iterate over the modules
71
-    for modulepath in $(find "$dkms_tree" -maxdepth 1 -mindepth 1 -type d); do
72
-
73
-        module_in_tree=${modulepath##*/}
74
-        # Determine which versions to show status for
75
-        do_autoinstall=""
76
-        version_count=0
77
-        already_installed=""
78
-        already_installed_version=""
79
-        for versioned_path in $(find "$modulepath" -maxdepth 1 -mindepth 1 -type d -a -not -name original_module); do
80
-            version_count=$(($version_count + 1))
81
-            version_in_tree="${versioned_path##*/}"
82
-
83
-            if [ -f $versioned_path/source/dkms.conf ]; then
84
-                do_autoinstall=$(sed -n -e 's/^\(str  *\)\?AUTOINSTALL=\(.*\)$/\2/gp;'  $versioned_path/source/dkms.conf)
85
-            else
86
-                current_state="broken"
87
-                continue
88
-            fi
89
-
90
-            # Get the current state
91
-            # a mod can be both built and installed-weak (stupid, but could be)
92
-            # but installed-weak comes last, so use tail
93
-            current_state=`dkms status -m $module_in_tree -v $version_in_tree -k $kernel -a $arch 2>/dev/null | awk {'print $5'} | tail -n 1`
94
-            [ "$current_state" = "installed" -o "$current_state" = "installed-weak" ] && already_installed="true" && already_installed_version=$version_in_tree
95
-        done
96
-
97
-        log_action_begin_msg " $module_in_tree ($version_in_tree)"
98
-
99
-        # Based on what we know, either do it or not
100
-        if [ "$current_state" = "broken" ]; then
101
-            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): Unable to locate $versioned_path/source/dkms.conf"
102
-            logger -t dkms_autoinstaller " DKMS tree must be manually fixed"
103
-            log_action_end_msg 1
104
-            continue
105
-        elif [ -n "$already_installed" ]; then
106
-            log_action_end_msg 0
107
-        elif [ -z "$do_autoinstall" ]; then
108
-            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): AUTOINSTALL not set in its dkms.conf."
109
-            log_action_end_msg 0
110
-        elif [ -n "$do_autoinstall" ] && [ "$version_count" -gt 1 ]; then
111
-            logger -t dkms_autoinstaller "$module_in_tree: Multiple versions in DKMS. Unsure what to do. Resolve manually."
112
-            log_action_end_msg 1
113
-        else
114
-            logger -t dkms_autoinstaller "$module_in_tree ($version_in_tree): Installing module on kernel $kernel."
115
-            if [ "$current_state" != "built" ] && ! [ -e /lib/modules/$kernel/build/include ]; then
116
-                logger -t dkms_autoinstaller "  Kernel headers for $kernel are not installed.  Cannot install this module."
117
-                logger -t dkms_autoinstaller "  Try installing linux-headers-$kernel or equivalent."
118
-                log_action_end_msg 1
119
-            elif [ "$current_state" != "built" ] && [ -e /lib/modules/$kernel/build/include ]; then
120
-                return_status=""
121
-                if [ -z "$kernel_preparation_done" ]; then
122
-                    invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q --no-clean-kernel" "." background
123
-                    return_status="$?"
124
-                    kernel_preparation_done="true"
125
-                else
126
-                    invoke_command "dkms build -m $module_in_tree -v $version_in_tree -k $kernel -a $arch --no-prepare-kernel --no-clean-kernel -q" "." background
127
-                    return_status="$?"
128
-                fi
129
-                if [ "$return_status" -eq 0 ]; then
130
-                    invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch" "." background
131
-                    log_action_end_msg 0
132
-                else
133
-                    logger -t dkms_autoinstaller "  Build failed.  Installation skipped."
134
-                    log_action_end_msg 1
135
-                fi
136
-            else
137
-                invoke_command "dkms install -m $module_in_tree -v $version_in_tree -k $kernel -a $arch -q" "." background
138
-                return_status=$?
139
-                if [ "$return_status" -eq 101 ]; then
140
-                    logger -t dkms_autoinstaller "  A newer module version than this already exists in kernel."
141
-                    logger -t dkms_autoinstaller "  Skipping install... (you can manually install later with --force)"
142
-                elif [ "$return_status" -ne 0 ]; then
143
-                    logger -t dkms_autoinstaller "  Installation failed!"
144
-                fi
145
-            fi
146
-        fi
147
-    done
148
-    if [ -z "$modules_needing_status" ]; then
149
-        log_end_msg 0
150
-    fi
151
+    log_daemon_msg "dkms: running auto installation service for kernel $kernel"
152
+    dkms autoinstall --kernelver $kernel
153
+    log_end_msg $?
154
     ;;
155
   stop|restart|force-reload|status|reload)
156
     # ignore
157
dkms-2.1.1.2.tar.bz2/dkms_common.postinst -> dkms-2.2.0.3.tar.bz2/dkms_common.postinst Changed
178
 
1
@@ -6,11 +6,32 @@
2
 
3
 set -e
4
 
5
+uname_s=$(uname -s)
6
+
7
+_get_kernel_dir() {
8
+    KVER=$1
9
+    case ${uname_s} in
10
+   Linux)      DIR="/lib/modules/$KVER/build" ;;
11
+   GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
12
+    esac
13
+    echo $DIR
14
+}
15
+
16
+_check_kernel_dir() {
17
+    DIR=$(_get_kernel_dir $1)
18
+    case ${uname_s} in
19
+   Linux)      test -e $DIR/include ;;
20
+   GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
21
+   *)      return 1 ;;
22
+    esac
23
+    return $?
24
+}
25
+
26
 # Check the existence of a kernel named as $1
27
 _is_kernel_name_correct() {
28
     CORRECT="no"
29
     KERNEL_NAME=$1
30
-    
31
+
32
     for kernel in /boot/config-*; do
33
         KERNEL=${kernel#*-}
34
         if [ "${KERNEL}" = "${KERNEL_NAME}" ]; then
35
@@ -30,7 +51,7 @@
36
     NEWEST_KERNEL=
37
     NEWEST_VERSION=
38
     NEWEST_ABI=
39
-    
40
+
41
     for kernel in /boot/config-*; do
42
         KERNEL=${kernel#*-}
43
         KERNEL_VERSION=${KERNEL%%-*}
44
@@ -44,7 +65,7 @@
45
             # Get the biggest version
46
             COMPARE_TO="$NEWEST_VERSION-$NEWEST_ABI"
47
         fi
48
-            
49
+
50
         # if $kernel is greater than $COMPARE_TO
51
         if [ `dpkg --compare-versions "$KERNEL_VERSION-$ABI" gt "$COMPARE_TO" && echo "yes" || \
52
               echo "no"` = "yes" ]; then
53
@@ -61,7 +82,7 @@
54
 # is the most recent kernel then the function will print a null string.
55
 _get_newest_kernel_rhel() {
56
     NEWEST_KERNEL=
57
-    
58
+
59
     LAST_INSTALLED_KERNEL=$(rpm -q --whatprovides kernel  --last | grep kernel -m1 | cut -f1 -d' ')
60
 
61
     LIK_FORMATTED_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}\n")
62
@@ -71,7 +92,7 @@
63
         NEWEST_KERNEL=$LIK_FORMATTED_NAME
64
     else
65
         # Hack for Mandriva where $LIK_FORMATTED_NAME is broken
66
-        LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n") 
67
+        LIK_NAME=$(rpm -q $LAST_INSTALLED_KERNEL --queryformat="%{NAME}\n")
68
         LIK_TYPE=${LIK_NAME#kernel-}
69
         LIK_TYPE=${LIK_TYPE%%-*}
70
         LIK_STRIPPED=${LIK_NAME#kernel-}
71
@@ -99,7 +120,7 @@
72
         CURRENT_ABI=${CURRENT_ABI%%-*}
73
         NEWEST_KERNEL=$(_get_newest_kernel_debian "$CURRENT_VERSION-$CURRENT_ABI")
74
 
75
-    elif [ `which rpm &>/dev/null` ]; then
76
+    elif [ `which rpm >/dev/null` ]; then
77
         # If RPM based
78
         NEWEST_KERNEL=$(_get_newest_kernel_rhel)
79
     fi
80
@@ -135,11 +156,6 @@
81
 fi
82
 
83
 #Load new files, by source package and by tarball
84
-echo "Loading new $NAME-$VERSION DKMS files..."
85
-if [ -d "/usr/src/$NAME-$VERSION" ]; then
86
-    dkms add -m $NAME -v $VERSION > /dev/null
87
-fi
88
-
89
 if [ -f "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz" ]; then
90
     if ! dkms ldtarball --archive "$TARBALL_ROOT/$NAME-$VERSION.dkms.tar.gz"; then
91
         echo ""
92
@@ -151,8 +167,11 @@
93
         echo " - Corrupt distribution specific archive"
94
         echo ""
95
         echo ""
96
-        exit 2 
97
+        exit 2
98
     fi
99
+elif [ -d "/usr/src/$NAME-$VERSION" ]; then
100
+    echo "Loading new $NAME-$VERSION DKMS files..."
101
+    dkms add -m $NAME -v $VERSION > /dev/null
102
 fi
103
 
104
 # On 1st installation, let us look for a directory
105
@@ -160,10 +179,10 @@
106
 # is found it is possible that buildd is being used
107
 # and that uname -r is giving us the name of the
108
 # kernel used by the buildd machine.
109
-# 
110
+#
111
 # If this is the case we try to build the kernel
112
-# module for each kernel which has a directory in 
113
-# /lib/modules. Furthermore we will have to tell 
114
+# module for each kernel which has a directory in
115
+# /lib/modules. Furthermore we will have to tell
116
 # DKMS which architecture it should build the module
117
 # for (e.g. if the buildd machine is using a
118
 # 2.6.24-23-xen 64bit kernel).
119
@@ -188,13 +207,26 @@
120
 # current kernel.
121
 NEWEST_KERNEL=$(get_newest_kernel "$KERNELS")
122
 
123
-if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
124
-    echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
125
-    KERNELS="$KERNELS $NEWEST_KERNEL"
126
+# If the current kernel doesn't come from the host of a chroot
127
+if [ `_is_kernel_name_correct $CURRENT_KERNEL` = "yes" ]; then
128
+    # See if it's worth building the module for both the newest kernel
129
+    # and for the current kernel
130
+    if [ -n "$NEWEST_KERNEL" ] && [ ${CURRENT_KERNEL} != ${NEWEST_KERNEL} ]; then
131
+        echo "Building for $CURRENT_KERNEL and $NEWEST_KERNEL"
132
+        KERNELS="$CURRENT_KERNEL $NEWEST_KERNEL"
133
+    else
134
+        echo "Building only for $CURRENT_KERNEL"
135
+    fi
136
+# The current kernel is not useful as it's the host's
137
 else
138
-    echo "Building only for $CURRENT_KERNEL"
139
-fi
140
+    echo "It is likely that $CURRENT_KERNEL belongs to a chroot's host"
141
 
142
+    # Let's use only the newest kernel
143
+    if [ -n "$NEWEST_KERNEL" ]; then
144
+        KERNELS="$NEWEST_KERNEL"
145
+        echo "Building only for $NEWEST_KERNEL"
146
+    fi
147
+fi
148
 
149
 if [ -n "$ARCH" ]; then
150
     if which lsb_release >/dev/null && [ $(lsb_release -s -i) = "Ubuntu" ]; then
151
@@ -229,10 +261,24 @@
152
             echo " since the package source was not provided"
153
             continue
154
         fi
155
-        if [ -e /lib/modules/$KERNEL/build/include ]; then
156
+        if _check_kernel_dir $KERNEL; then
157
             echo "Building initial module for $KERNEL"
158
+            set +e
159
             dkms build -m $NAME -v $VERSION -k $KERNEL $ARCH > /dev/null
160
-            echo "Done."
161
+            case $? in
162
+            9)
163
+                set -e
164
+                echo "Skipped."
165
+                continue
166
+                ;;
167
+            0)
168
+                set -e
169
+                echo "Done."
170
+                ;;
171
+            *)
172
+                exit $?
173
+                ;;
174
+            esac
175
             dkms_status=`dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH`
176
         else
177
             echo "Module build for the currently running kernel was skipped since the"
178
dkms-2.1.1.2.tar.bz2/dkms_find-provides -> dkms-2.2.0.3.tar.bz2/dkms_find-provides Changed
11
 
1
@@ -59,7 +59,8 @@
2
 }
3
 
4
 
5
-TMPDIR=$(mktemp -d /tmp/dkms-findprovides-$$-$RANDOM-XXXXXX)
6
+tmp=${TMPDIR:-/tmp}
7
+TMPDIR=$(mktemp -d ${tmp}/dkms-findprovides-$$-$RANDOM-XXXXXX)
8
 trap "rm -rf $TMPDIR >/dev/null 2>&1"  QUIT EXIT HUP INT TERM
9
 
10
 modlist=
11
dkms-2.1.1.2.tar.bz2/dkms_upgrade_add_arch_support.sh -> dkms-2.2.0.3.tar.bz2/dkms_upgrade_add_arch_support.sh Changed
126
 
1
@@ -8,70 +8,62 @@
2
 #
3
 # DKMS v2.0 will be the first stable release to have arch support.
4
 
5
+# bail if no dkms
6
+dkms_version=$(dkms -V 2>/dev/null) || exit
7
+dkms_version=(${dkms_version//./ })
8
 
9
-function readlink()
10
-{
11
-    # $1 = the symlink to read
12
-    read_link=""
13
-    if [ -L "$1" ]; then
14
-        read_link="$1"
15
-        while [ -L "$read_link" ]; do
16
-            read_link=`ls -l $read_link | sed 's/.*-> //'`
17
-        done
18
-    fi
19
-}
20
+# do nothing if we are already new enough
21
+((${dkms_version[2]} > 1 || \
22
+    (${dkms_version[2]} == 1 && ${dkms_version[3]} >= 90) )) && exit
23
+
24
+mv /var/dkms /var/lib/dkms
25
+arch_used=$(uname -m)
26
+[[ $arch_used = x86_64 ]] && (($(grep -c "Intel" /proc/cpuinfo > 0 && \
27
+    $(ls /lib/modules/$kernel_test/build/configs 2>/dev/null | \
28
+    grep -c "ia32e") > 0)) && arch_used="ia32e"
29
 
30
-dkms_version=`dkms -V 2>/dev/null`
31
-if [ -n "$dkms_version" ]; then
32
-   version_major=`echo $dkms_version | awk {'print $2'} | cut -d '.' -f 1-1`
33
-   version_minor=`echo $dkms_version | awk {'print $2'} | cut -d '.' -f 2-2`
34
-   if [ "$version_major" -lt 2 ] && [ "$version_minor" -lt 90 ] || [ "$version_major" -eq 0 ]; then
35
-       mv /var/dkms /var/lib/dkms
36
-       arch_used=""
37
-       [ `uname -m` == "x86_64" ] && [ `cat /proc/cpuinfo | grep -c "Intel"` -gt 0 ] && [ `ls /lib/modules/$kernel_test/build/configs 2>/dev/null | grep -c "ia32e"` -gt 0 ] && arch_used="ia32e" || arch_used=`uname -m`
38
-       echo ""
39
-       echo "ALERT! ALERT! ALERT!"
40
-       echo ""
41
-       echo "You are using a version of DKMS which does not support multiple system"
42
-       echo "architectures.  Your DKMS tree will now be modified to add this support."
43
-       echo ""
44
-       echo "The upgrade will assume all built modules are for arch: $arch_used"
45
+echo ""
46
+echo "ALERT! ALERT! ALERT!"
47
+echo ""
48
+echo "You are using a version of DKMS which does not support multiple system"
49
+echo "architectures.  Your DKMS tree will now be modified to add this support."
50
+echo ""
51
+echo "The upgrade will assume all built modules are for arch: $arch_used"
52
 
53
-       # Set important variables
54
-       current_kernel=`uname -r`
55
-       dkms_tree="/var/lib/dkms"
56
-       source_tree="/usr/src"
57
-       tmp_location="/tmp"
58
-       dkms_frameworkconf="/etc/dkms_framework.conf"
59
+# Set important variables
60
+current_kernel=$(uname -r)
61
+dkms_tree="/var/lib/dkms"
62
+source_tree="/usr/src"
63
+tmp_location="/tmp"
64
+dkms_frameworkconf="/etc/dkms_framework.conf"
65
 
66
-       # Source in /etc/dkms_framework.conf
67
-       . $dkms_frameworkconf 2>/dev/null
68
+# Source in /etc/dkms_framework.conf
69
+. $dkms_frameworkconf 2>/dev/null
70
 
71
-       # Add the arch dirs
72
-       echo ""
73
-       echo "Fixing directories."
74
-       for directory in `find $dkms_tree -type d -name "module" -mindepth 3 -maxdepth 4`; do
75
-           dir_to_fix=`echo $directory | sed 's#/module$##'`
76
-           echo "Creating $dir_to_fix/$arch_used..."
77
-           mkdir $dir_to_fix/$arch_used
78
-           mv -f $dir_to_fix/* $dir_to_fix/$arch_used 2>/dev/null
79
-       done
80
+# Add the arch dirs
81
+echo ""
82
+echo "Fixing directories."
83
+for directory in $(find $dkms_tree -type d -name "module" -mindepth 3 -maxdepth 4); do
84
+    dir_to_fix=${directory%module}
85
+    echo "Creating $dir_to_fix/$arch_used..."
86
+    mkdir $dir_to_fix/$arch_used
87
+    mv -f $dir_to_fix/* $dir_to_fix/$arch_used 2>/dev/null
88
+done
89
 
90
-       # Fix symlinks
91
-       echo ""
92
-       echo "Fixing symlinks."
93
-       for symlink in `find $dkms_tree -type l -name "kernel*" -mindepth 2 -maxdepth 2`; do
94
-           symlink_kernelname=`echo $symlink | sed 's#.*/kernel-##'`
95
-           dir_of_symlink=`echo $symlink | sed 's#/kernel-.*$##'`
96
-           cd $dir_of_symlink
97
-           readlink $symlink
98
-           if [ `echo $read_link | sed 's#/# #g' | wc -w | awk {'print $1'}` -lt 3 ]; then
99
-               echo "Updating $symlink..."
100
-               ln -sf $read_link/$arch_used kernel-$symlink_kernelname-$arch_used
101
-               rm -f $symlink
102
-           fi
103
-           cd -
104
-       done
105
-       echo ""
106
-   fi
107
-fi
108
+# Fix symlinks
109
+echo ""
110
+echo "Fixing symlinks."
111
+for symlink in $(find $dkms_tree -type l -name "kernel*" -mindepth 2 -maxdepth 2); do
112
+    symlink_kernelname=${symlink/*\/kernel-//}
113
+    dir_of_symlink=${symlink/\/kernel-*//}
114
+    cd $dir_of_symlink
115
+    split_symlink=$(readlink -e "$symlink")
116
+    split_symlink=(${split_symlink//\// })
117
+    if ((${#split_symlink[@]} < 3)); then
118
+   echo "Updating $symlink..."
119
+   ln -sf $read_link/$arch_used kernel-$symlink_kernelname-$arch_used
120
+   rm -f $symlink
121
+    fi
122
+    cd -
123
+done
124
+echo ""
125
\ No newline at end of file
126
dkms-2.1.1.2.tar.bz2/kernel_postinst.d_dkms -> dkms-2.2.0.3.tar.bz2/kernel_postinst.d_dkms Changed
46
 
1
@@ -3,6 +3,44 @@
2
 # We're passed the version of the kernel being installed
3
 inst_kern=$1
4
 
5
+uname_s=$(uname -s)
6
+
7
+_get_kernel_dir() {
8
+    KVER=$1
9
+    case ${uname_s} in
10
+       Linux)          DIR="/lib/modules/$KVER/build" ;;
11
+       GNU/kFreeBSD)   DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
12
+    esac
13
+    echo $DIR
14
+}
15
+
16
+_check_kernel_dir() {
17
+    DIR=$(_get_kernel_dir $1)
18
+    case ${uname_s} in
19
+       Linux)          test -e $DIR/include ;;
20
+       GNU/kFreeBSD)   test -e $DIR/kern && test -e $DIR/conf/kmod.mk ;;
21
+       *)              return 1 ;;
22
+    esac
23
+    return $?
24
+}
25
+
26
+case "${uname_s}" in
27
+    Linux)
28
+        header_pkg="linux-headers-$inst_kern"
29
+        kernel="Linux"
30
+    ;;
31
+    GNU/kFreeBSD)
32
+        header_pkg="kfreebsd-headers-$inst_kern"
33
+        kernel="kFreeBSD"
34
+    ;;
35
+esac
36
+
37
 if [ -x /usr/lib/dkms/dkms_autoinstaller ]; then
38
     exec /usr/lib/dkms/dkms_autoinstaller start $inst_kern > /dev/null
39
 fi
40
+
41
+if ! _check_kernel_dir $inst_kern ; then
42
+    echo "dkms: WARNING: $kernel headers are missing, which may explain the above failures." >&2
43
+    echo "      please install the $header_pkg package to fix this." >&2
44
+fi
45
+
46
dkms-2.1.1.2.tar.bz2/kernel_prerm.d_dkms -> dkms-2.2.0.3.tar.bz2/kernel_prerm.d_dkms Changed
12
 
1
@@ -8,8 +8,8 @@
2
    name=`echo "$line" | awk '{print $1}' | sed 's/,$//'`
3
    vers=`echo "$line" | awk '{print $2}' | sed 's/,$//'`
4
    arch=`echo "$line" | awk '{print $4}' | sed 's/:$//'`
5
-   echo "Uninstalling: $name $vers ($inst_kern) ($arch)"
6
-   dkms uninstall -m $name -v $vers -k $inst_kern -a $arch
7
+   echo "dkms: removing: $name $vers ($inst_kern) ($arch)" >&2
8
+   dkms remove -m $name -v $vers -k $inst_kern -a $arch
9
 done < <(dkms status -k $inst_kern 2>/dev/null | grep ": installed")
10
 fi
11
 
12
dkms-2.1.1.2.tar.bz2/template-dkms-mkdeb/debian/postinst -> dkms-2.2.0.3.tar.bz2/template-dkms-mkdeb/debian/postinst Changed
11
 
1
@@ -8,7 +8,8 @@
2
 
3
 NAME=MODULE_NAME
4
 PACKAGE_NAME=$NAME-dkms
5
-CVERSION=`dpkg-query -W -f='${Version}' $PACKAGE_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`
6
+DEB_NAME=$(echo $PACKAGE_NAME | sed 's,_,-,')
7
+CVERSION=`dpkg-query -W -f='${Version}' $DEB_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`
8
 ARCH=`dpkg --print-architecture`
9
 
10
 dkms_configure () {
11
dkms-2.2.0.3.tar.bz2/template-dkms-redhat-kmod.spec Added
50
 
1
@@ -0,0 +1,48 @@
2
+%{?!module_name: %{error: You did not specify a module name (%%module_name)}}
3
+%{?!version: %{error: You did not specify a module version (%%version)}}
4
+Name:      %{module_name}
5
+Version:   %{version}
6
+Release:   1%{?dist}
7
+Summary:   %{module_name}-%{version} RHEL6 Driver Update Program package
8
+
9
+Group:     System/Kernel
10
+License:   Unkown
11
+Source0:   %{module_name}-%{version}.tar.bz2
12
+BuildRoot: %(mktemp -ud %{_tmppath}/%{module_name}-%{version}-%{release}-XXXXXX)
13
+BuildRequires: %kernel_module_package_buildreqs
14
+
15
+%kernel_module_package default
16
+
17
+%description
18
+%{module_name}-%{version} RHEL6 Driver Update package.
19
+
20
+%prep
21
+%setup
22
+set -- *
23
+mkdir source
24
+mv "$@" source/
25
+mkdir obj
26
+
27
+%build
28
+for flavor in %flavors_to_build; do
29
+   rm -rf obj/$flavor
30
+   cp -r source obj/$flavor
31
+   make -C %{kernel_source $flavor} M=$PWD/obj/$flavor
32
+done
33
+
34
+%install
35
+export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
36
+export INSTALL_MOD_DIR=extra/%{name}
37
+for flavor in %flavors_to_build ; do
38
+   make -C %{kernel_source $flavor} modules_install \
39
+       M=$PWD/obj/$flavor
40
+done
41
+
42
+%clean
43
+rm -rf $RPM_BUILD_ROOT
44
+
45
+%changelog
46
+* Sun Jun 15 2010 Prudhvi Tella <prudhvi_tella@dell.com>
47
+- DKMS template for RHEL6 Driver Update package.
48
+* Sun Mar 28 2010 Jon Masters <jcm@redhat.com>
49
+- Example RHEL6 Driver Update package.
50
dkms.rpmlintrc Changed
5
 
1
@@ -1,1 +1,2 @@
2
-addFilter(".*incoherent-init-script-name*.*dkms_autoinstaller*")
3
+addFilter(".*devel-dependency kernel-devel.*")
4
+addFilter(".*incoherent-init-script-name.*")
5
Refresh

No build results available

Refresh

No rpmlint results available

Request History
Adam Mizerski's avatar

etamPL created request over 11 years ago

update to 2.2.0.3


Peter Linnell's avatar

mrdocs accepted request about 12 years ago

Thanks. Looks good to me!