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 | DKMS=`which dkms 2>/dev/null`
|
---|
18 | if [ -n "$DKMS" ]
|
---|
19 | then
|
---|
20 | if [ "$1" = "uninstall" ]; then
|
---|
21 |
|
---|
22 | echo "Uninstalling modules from DKMS"
|
---|
23 | for m in _OLDMODULES_
|
---|
24 | do
|
---|
25 | $DKMS status -m $m | while read line
|
---|
26 | # first, remove _any_ old module
|
---|
27 | do
|
---|
28 | if echo "$line" | grep -q added > /dev/null ||
|
---|
29 | echo "$line" | grep -q built > /dev/null ||
|
---|
30 | echo "$line" | grep -q installed > /dev/null; then
|
---|
31 | # either 'vboxvideo, <version>: added'
|
---|
32 | # or 'vboxvideo, <version>, ...: installed'
|
---|
33 | version=`echo "$line" | sed "s/$m,\([^,]*\)[,:].*/\1/;t;d"`
|
---|
34 | echo " removing old DKMS module $m version $version"
|
---|
35 | $DKMS remove -m $m -v $version --all
|
---|
36 | fi
|
---|
37 | done
|
---|
38 | done
|
---|
39 | # there should not be any more matches
|
---|
40 | status=`$DKMS status -m _MODULE_ -v _VERSION_`
|
---|
41 | if echo $status | grep added > /dev/null ||
|
---|
42 | echo $status | grep built > /dev/null ||
|
---|
43 | echo $status | grep installed > /dev/null
|
---|
44 | then
|
---|
45 | $DKMS remove -m _MODULE_ -v _VERSION_ --all
|
---|
46 | fi
|
---|
47 | exit 0
|
---|
48 |
|
---|
49 | elif [ "$1" = "install" ]; then
|
---|
50 |
|
---|
51 | echo "Attempting to install using DKMS"
|
---|
52 | if $DKMS add -m _MODULE_ -v _VERSION_ &&
|
---|
53 | $DKMS build -m _MODULE_ -v _VERSION_ &&
|
---|
54 | $DKMS install -m _MODULE_ -v _VERSION_ --force
|
---|
55 | then
|
---|
56 | exit 0
|
---|
57 | fi
|
---|
58 | echo "Failed to install using DKMS, attempting to install without"
|
---|
59 |
|
---|
60 | fi
|
---|
61 | fi
|
---|
62 |
|
---|
63 | exit 1
|
---|