1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Script to register/build/unregister a kernel module with DKMS.
|
---|
5 | #
|
---|
6 | # Copyright (C) 2010 Oracle Corporation
|
---|
7 | #
|
---|
8 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | # available from http://www.virtualbox.org. This file is free software;
|
---|
10 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | # General Public License (GPL) as published by the Free Software
|
---|
12 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | #
|
---|
16 |
|
---|
17 | ACTION=
|
---|
18 | if [ "$1" = "install" ]; then
|
---|
19 | ACTION="install"
|
---|
20 | MODULE="$2"
|
---|
21 | VERSION="$3"
|
---|
22 | elif [ "$1" = "uninstall" ]; then
|
---|
23 | shift
|
---|
24 | ACTION="uninstall"
|
---|
25 | OLDMODULES="$*"
|
---|
26 | break
|
---|
27 | fi
|
---|
28 |
|
---|
29 | DKMS=`which dkms 2>/dev/null`
|
---|
30 | if [ -n "$DKMS" ]
|
---|
31 | then
|
---|
32 | if [ "$ACTION" = "uninstall" ]; then
|
---|
33 |
|
---|
34 | echo "Uninstalling modules from DKMS"
|
---|
35 | for m in $OLDMODULES
|
---|
36 | do
|
---|
37 | $DKMS status -m $m | while read line
|
---|
38 | # first, remove _any_ old module
|
---|
39 | do
|
---|
40 | if echo "$line" | grep -q added > /dev/null ||
|
---|
41 | echo "$line" | grep -q built > /dev/null ||
|
---|
42 | echo "$line" | grep -q installed > /dev/null; then
|
---|
43 | # either 'vboxvideo, <version>: added'
|
---|
44 | # or 'vboxvideo, <version>, ...: installed'
|
---|
45 | version=`echo "$line" | sed "s/$m,\([^,]*\)[,:].*/\1/;t;d"`
|
---|
46 | echo " removing old DKMS module $m version $version"
|
---|
47 | $DKMS remove -m $m -v $version --all
|
---|
48 | fi
|
---|
49 | done
|
---|
50 | done
|
---|
51 | exit 0
|
---|
52 |
|
---|
53 | elif [ "$ACTION" = "install" ]; then
|
---|
54 |
|
---|
55 | echo "Attempting to install using DKMS"
|
---|
56 | if $DKMS add -m $MODULE -v $VERSION &&
|
---|
57 | $DKMS build -m $MODULE -v $VERSION &&
|
---|
58 | $DKMS install -m $MODULE -v $VERSION --force
|
---|
59 | then
|
---|
60 | exit 0
|
---|
61 | fi
|
---|
62 | echo "Failed to install using DKMS, attempting to install without"
|
---|
63 |
|
---|
64 | fi
|
---|
65 | fi
|
---|
66 |
|
---|
67 | exit 1
|
---|