1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Oracle VirtualBox
|
---|
4 | # VirtualBox linux installation script
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox base platform packages, as
|
---|
10 | # available from https://www.virtualbox.org.
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation, in version 3 of the
|
---|
15 | # License.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful, but
|
---|
18 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | #
|
---|
25 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | #
|
---|
27 |
|
---|
28 | set -e
|
---|
29 |
|
---|
30 | # Usage:
|
---|
31 | USAGE_MESSAGE=\
|
---|
32 | 'Usage: `basename ${0}` [-h|--help|
|
---|
33 | --test [<uname -r output> rpm|dpkg [<base expected> <versioned expected>]]]
|
---|
34 | This script tests whether a Linux system is set up to build kernel modules,
|
---|
35 | and if not prints a guess as to which distribution packages need to be
|
---|
36 | installed to do so, and what commands to use. It uses the output of the
|
---|
37 | "uname -r" command to guess the packages and searches for packaging tools
|
---|
38 | by checking for packaging databases.
|
---|
39 |
|
---|
40 | For testing you can specify the output of "uname -r" which will be used
|
---|
41 | instead of the real one and the package type, and optionally the expected
|
---|
42 | output. --test without parameters will test a number of known inputs.'
|
---|
43 |
|
---|
44 | # General theory of operation (valid Nov 19 2016): we check whether this is an
|
---|
45 | # rpm or dpkg system by checking for the respective non-empty database directory
|
---|
46 | # (we assert that only one is present), and based on that we map uname -r output
|
---|
47 | # to a kernel package name. Here is a textual description of known mappings
|
---|
48 | # (not all of these are currently implemented) for both the general package name
|
---|
49 | # and the version-specific package name. Keeping this here as it took some time
|
---|
50 | # and pain to research.
|
---|
51 | #
|
---|
52 | # Debian/Ubuntu (dpkg): <version>-<flavour> -> linux-headers-<flavour>,
|
---|
53 | # linux-headers-<version>-<flavour>
|
---|
54 | DEBIAN_FLAVOURS="generic lowlatency virtual 486 686-pae amd64 rt-686-pae \
|
---|
55 | rt-amd64 i386 586 grsec-686-pae grsec-amd64 686"
|
---|
56 | # SUSE (rpm): <version>-<flavour> -> kernel-<flavour>-devel,
|
---|
57 | # kernel-<flavour>-devel-<version>
|
---|
58 | SUSE_FLAVOURS="debug default ec2 pae trace vanilla vmi xen"
|
---|
59 | # OL/RHEL/CentOS (rpm): <version><flavour>[.i686|.x86_64] -> kernel-<flavour>-devel,
|
---|
60 | # kernel-<flavour>-devel-<`uname -r`>, where <version> ends in el*.
|
---|
61 | EL_FLAVOURS="uek xen"
|
---|
62 | # Fedora (rpm): <version> -> kernel-devel, kernel-devel-<version>, where <version>
|
---|
63 | # ends in fc*.
|
---|
64 | #
|
---|
65 | # OUTPUT NOT YET TESTED ON REAL SYSTEMS
|
---|
66 | #
|
---|
67 | # Mageia (rpm): <version>-*.mga* -> kernel-linus-latest,
|
---|
68 | # kernel-linus-<`uname -r`>
|
---|
69 | # <version>-<flavour>-*.mga* -> kernel-<flavour>-latest,
|
---|
70 | # kernel-<flavour>-<`uname -r`>
|
---|
71 | MAGEIA_FLAVOURS="desktop desktop586 server tmb-desktop"
|
---|
72 | # PCLinuxOS (dpkg): <version>-pclos* -> kernel-devel, kernel-devel-<`uname -r`>
|
---|
73 |
|
---|
74 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
75 |
|
---|
76 | HAVE_TOOLS=
|
---|
77 | HAVE_HEADERS=
|
---|
78 | PACKAGE_TYPE=
|
---|
79 | UNAME=
|
---|
80 | BASE_PACKAGE=
|
---|
81 | VERSIONED_PACKAGE=
|
---|
82 | TOOLS="gcc make perl"
|
---|
83 | TEST=
|
---|
84 | UNIT_TEST=
|
---|
85 |
|
---|
86 | case "${1}" in
|
---|
87 | "")
|
---|
88 | # Return immediately successfully if everything is installed
|
---|
89 | type ${TOOLS} >/dev/null 2>&1 && HAVE_TOOLS=yes
|
---|
90 | test -d "/lib/modules/`uname -r`/build/include" && HAVE_HEADERS=yes
|
---|
91 | test -n "${HAVE_TOOLS}" && test -n "${HAVE_HEADERS}" && exit 0
|
---|
92 | UNAME=`uname -r`
|
---|
93 | for i in rpm dpkg; do
|
---|
94 | for j in /var/lib/${i}/*; do
|
---|
95 | test -e "${j}" || break
|
---|
96 | if test -z "${PACKAGE_TYPE}"; then
|
---|
97 | PACKAGE_TYPE="${i}"
|
---|
98 | else
|
---|
99 | PACKAGE_TYPE=unknown
|
---|
100 | fi
|
---|
101 | break
|
---|
102 | done
|
---|
103 | done
|
---|
104 | ;;
|
---|
105 | -h|--help)
|
---|
106 | echo "${USAGE_MESSAGE}"
|
---|
107 | exit 0 ;;
|
---|
108 | *)
|
---|
109 | ERROR=""
|
---|
110 | UNAME="${2}"
|
---|
111 | PACKAGE_TYPE="${3}"
|
---|
112 | BASE_EXPECTED="${4}"
|
---|
113 | VERSIONED_EXPECTED="${5}"
|
---|
114 | test "${1}" = --test || ERROR=yes
|
---|
115 | test -n "${UNAME}" && test -n "${PACKAGE_TYPE}" || test -z "${UNAME}" ||
|
---|
116 | ERROR=yes
|
---|
117 | test -n "${BASE_EXPECTED}" && test -n "${VERSIONED_EXPECTED}" ||
|
---|
118 | test -z "${BASE_EXPECTED}" || ERROR=yes
|
---|
119 | case "${ERROR}" in ?*)
|
---|
120 | echo "${USAGE_MESSAGE}" >&2
|
---|
121 | exit 1
|
---|
122 | esac
|
---|
123 | TEST=yes
|
---|
124 | TEST_PARAMS="${2} ${3} ${4} ${5}"
|
---|
125 | test -z "${UNAME}" && UNIT_TEST=yes
|
---|
126 | ;;
|
---|
127 | esac
|
---|
128 |
|
---|
129 | case "${PACKAGE_TYPE}" in
|
---|
130 | rpm)
|
---|
131 | for i in ${SUSE_FLAVOURS}; do
|
---|
132 | case "${UNAME}" in *-"${i}")
|
---|
133 | BASE_PACKAGE="kernel-${i}-devel"
|
---|
134 | VERSIONED_PACKAGE="kernel-${i}-devel-${UNAME%-${i}}"
|
---|
135 | break
|
---|
136 | esac
|
---|
137 | done
|
---|
138 | for i in ${EL_FLAVOURS} ""; do
|
---|
139 | case "${UNAME}" in *.el5"${i}"|*.el*"${i}".i686|*.el*"${i}".x86_64)
|
---|
140 | test -n "${i}" && i="${i}-" # Hack to handle empty flavour.
|
---|
141 | BASE_PACKAGE="kernel-${i}devel"
|
---|
142 | VERSIONED_PACKAGE="kernel-${i}devel-${UNAME}"
|
---|
143 | break
|
---|
144 | esac
|
---|
145 | done
|
---|
146 | case "${UNAME}" in *.fc*.i686|*.fc*.x86_64) # Fedora
|
---|
147 | BASE_PACKAGE="kernel-devel"
|
---|
148 | VERSIONED_PACKAGE="kernel-devel-${UNAME}"
|
---|
149 | esac
|
---|
150 | for i in ${MAGEIA_FLAVOURS} ""; do # Mageia
|
---|
151 | case "${UNAME}" in *-"${i}"*.mga*)
|
---|
152 | if test -z "${i}"; then
|
---|
153 | BASE_PACKAGE="kernel-linus-devel"
|
---|
154 | VERSIONED_PACKAGE="kernel-linus-devel-${UNAME}"
|
---|
155 | else
|
---|
156 | BASE_PACKAGE="kernel-${i}-devel"
|
---|
157 | VERSIONED_PACKAGE="kernel-${i}-devel-${UNAME%-${i}*}${UNAME#*${i}}"
|
---|
158 | fi
|
---|
159 | break
|
---|
160 | esac
|
---|
161 | done
|
---|
162 | ;;
|
---|
163 | dpkg)
|
---|
164 | for i in ${DEBIAN_FLAVOURS}; do # Debian/Ubuntu
|
---|
165 | case "${UNAME}" in *-${i})
|
---|
166 | BASE_PACKAGE="linux-headers-${i}"
|
---|
167 | VERSIONED_PACKAGE="linux-headers-${UNAME}"
|
---|
168 | break
|
---|
169 | esac
|
---|
170 | done
|
---|
171 | case "${UNAME}" in *-pclos*) # PCLinuxOS
|
---|
172 | BASE_PACKAGE="kernel-devel"
|
---|
173 | VERSIONED_PACKAGE="kernel-devel-${UNAME}"
|
---|
174 | esac
|
---|
175 | esac
|
---|
176 |
|
---|
177 | case "${UNIT_TEST}${BASE_EXPECTED}" in "")
|
---|
178 | echo "This system is currently not set up to build kernel modules." >&2
|
---|
179 | test -n "${HAVE_TOOLS}" ||
|
---|
180 | echo "Please install the ${TOOLS} packages from your distribution." >&2
|
---|
181 | test -n "${HAVE_HEADERS}" && exit 1
|
---|
182 | echo "Please install the Linux kernel \"header\" files matching the current kernel" >&2
|
---|
183 | echo "for adding new hardware support to the system." >&2
|
---|
184 | if test -n "${BASE_PACKAGE}${VERSIONED_PACKAGE}"; then
|
---|
185 | echo "The distribution packages containing the headers are probably:" >&2
|
---|
186 | echo " ${BASE_PACKAGE} ${VERSIONED_PACKAGE}" >&2
|
---|
187 | fi
|
---|
188 | test -z "${TEST}" && exit 1
|
---|
189 | exit 0
|
---|
190 | esac
|
---|
191 |
|
---|
192 | case "${BASE_EXPECTED}" in ?*)
|
---|
193 | case "${BASE_EXPECTED} ${VERSIONED_EXPECTED}" in
|
---|
194 | "${BASE_PACKAGE} ${VERSIONED_PACKAGE}")
|
---|
195 | exit 0
|
---|
196 | esac
|
---|
197 | echo "Test: ${TEST_PARAMS}" >&2
|
---|
198 | echo "Result: ${BASE_PACKAGE} ${VERSIONED_PACKAGE}"
|
---|
199 | exit 1
|
---|
200 | esac
|
---|
201 |
|
---|
202 | # Unit test as of here.
|
---|
203 | # Test expected correct results.
|
---|
204 | for i in \
|
---|
205 | "4.1.12-37.5.1.el6uek.x86_64 rpm kernel-uek-devel kernel-uek-devel-4.1.12-37.5.1.el6uek.x86_64" \
|
---|
206 | "2.6.32-642.el6.x86_64 rpm kernel-devel kernel-devel-2.6.32-642.el6.x86_64" \
|
---|
207 | "4.1.12-vanilla rpm kernel-vanilla-devel kernel-vanilla-devel-4.1.12" \
|
---|
208 | "4.8.8-pclos1 dpkg kernel-devel kernel-devel-4.8.8-pclos1" \
|
---|
209 | "4.8.8-desktop-1.mga6 rpm kernel-desktop-devel kernel-desktop-devel-4.8.8-1.mga6" \
|
---|
210 | "3.19.8-2.mga5 rpm kernel-linus-devel kernel-linus-devel-3.19.8-2.mga5" \
|
---|
211 | "4.8.0-27-generic dpkg linux-headers-generic linux-headers-4.8.0-27-generic"
|
---|
212 | do
|
---|
213 | "${0}" --test ${i} || exit 1
|
---|
214 | done
|
---|
215 |
|
---|
216 | # Test argument combinations expected to fail.
|
---|
217 | for i in \
|
---|
218 | "--test NOT_EMPTY" \
|
---|
219 | "--test NOT_EMPTY NOT_EMPTY NOT_EMPTY" \
|
---|
220 | "--wrong" \
|
---|
221 | "--test 4.8.8-pclos1 dpkg kernel-devel kernel-devel-WRONG" \
|
---|
222 | "--test 4.8.8-pclos1 dpkg kernel-WRONG kernel-devel-4.8.8-pclos1"
|
---|
223 | do
|
---|
224 | "${0}" ${i} >/dev/null 2>&1 && echo "Bad argument test failed:" &&
|
---|
225 | echo " ${i}" && exit 1
|
---|
226 | done
|
---|
227 | exit 0
|
---|