VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/vboxadd-x11.sh@ 67658

Last change on this file since 67658 was 67658, checked in by vboxsync, 7 years ago

Additions/linux: bugref:8869: blacklist the vboxvideo kernel module for OL6

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 20.2 KB
Line 
1#! /bin/sh
2#
3# Linux Additions X11 setup init script ($Revision: 67658 $)
4#
5
6#
7# Copyright (C) 2006-2012 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License (GPL) as published by the Free Software
13# Foundation, in version 2 as it comes in the "COPYING" file of the
14# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16#
17
18
19# chkconfig: 35 30 70
20# description: VirtualBox Linux Additions kernel modules
21#
22### BEGIN INIT INFO
23# Provides: vboxadd-x11
24# Required-Start:
25# Required-Stop:
26# Default-Start:
27# Default-Stop:
28# Description: VirtualBox Linux Additions X11 setup
29### END INIT INFO
30
31PATH=$PATH:/bin:/sbin:/usr/sbin
32LOG="/var/log/vboxadd-install-x11.log"
33CONFIG_DIR="/var/lib/VBoxGuestAdditions"
34CONFIG="${CONFIG_DIR}/config"
35MODPROBE=/sbin/modprobe
36
37if $MODPROBE -c 2>/dev/null | grep -q '^allow_unsupported_modules *0'; then
38 MODPROBE="$MODPROBE --allow-unsupported-modules"
39fi
40
41# Find the version of X installed
42# The last of the three is for the X.org 6.7 included in Fedora Core 2
43xver=`X -version 2>&1`
44x_version=`echo "$xver" | sed -n 's/^X Window System Version \([0-9.]\+\)/\1/p'``echo "$xver" | sed -n 's/^XFree86 Version \([0-9.]\+\)/\1/p'``echo "$xver" | sed -n 's/^X Protocol Version 11, Revision 0, Release \([0-9.]\+\)/\1/p'``echo "$xver" | sed -n 's/^X.Org X Server \([0-9.]\+\)/\1/p'`
45x_version_short=`echo "${x_version}" | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/'`
46# Version of Redhat or Fedora installed. Needed for setting up selinux policy.
47redhat_release=`cat /etc/redhat-release 2> /dev/null`
48# Version of OL installed. Needed for blacklisting vboxvideo.
49oracle_release=`cat /etc/oracle-release 2> /dev/null`
50# All the different possible locations for XFree86/X.Org configuration files
51# - how many of these have ever been used?
52x11conf_files="/etc/X11/xorg.conf /etc/X11/xorg.conf-4 /etc/X11/.xorg.conf \
53 /etc/xorg.conf /usr/etc/X11/xorg.conf-4 /usr/etc/X11/xorg.conf \
54 /usr/lib/X11/xorg.conf-4 /usr/lib/X11/xorg.conf /etc/X11/XF86Config-4 \
55 /etc/X11/XF86Config /etc/XF86Config /usr/X11R6/etc/X11/XF86Config-4 \
56 /usr/X11R6/etc/X11/XF86Config /usr/X11R6/lib/X11/XF86Config-4 \
57 /usr/X11R6/lib/X11/XF86Config"
58
59# Preamble for Gentoo
60if [ "`which $0`" = "/sbin/rc" ]; then
61 shift
62fi
63
64dev=/dev/vboxguest
65userdev=/dev/vboxuser
66owner=vboxadd
67group=1
68
69fail()
70{
71 echo "${1}" >&2
72 exit 1
73}
74
75# Install an X11 desktop startup application. The application should be a shell script.
76# Its name should be purely alphanumeric and should start with a two digit number (preferably
77# 98 or thereabouts) to indicate its place in the Debian Xsession startup order.
78#
79# syntax: install_x11_startup_app app desktop service_name
80install_x11_startup_app() {
81 self="install_x11_startup_app"
82 app_src=$1
83 desktop_src=$2
84 service_name=$3
85 alt_command=$4
86 test -r "$app_src" || fail "$self: no script given"
87 test -r "$desktop_src" || fail "$self: no desktop file given"
88 test -n "$service_name" || fail "$self: no service given"
89 test -n "$alt_command" || fail "$self: no service given"
90 app_dest=`basename $app_src sh`
91 app_dest_sh=`basename $app_src sh`.sh
92 desktop_dest=`basename $desktop_src`
93 found=0
94 x11_autostart="/etc/xdg/autostart"
95 kde_autostart="/usr/share/autostart"
96 redhat_dir=/etc/X11/Xsession.d
97 mandriva_dir=/etc/X11/xinit.d
98 debian_dir=/etc/X11/xinit/xinitrc.d
99 if [ -d "$mandriva_dir" -a -w "$mandriva_dir" -a -x "$mandriva_dir" ]
100 then
101 install -m 0644 $app_src "$mandriva_dir/$app_dest"
102 found=1
103 fi
104 if [ -d "$x11_autostart" -a -w "$x11_autostart" -a -x "$x11_autostart" ]
105 then
106 install -m 0644 $desktop_src "$x11_autostart/$desktop_dest"
107 found=1
108 fi
109 if [ -d "$kde_autostart" -a -w "$kde_autostart" -a -x "$kde_autostart" ]
110 then
111 install -m 0644 $desktop_src "$kde_autostart/$desktop_dest"
112 found=1
113 fi
114 if [ -d "$redhat_dir" -a -w "$redhat_dir" -a -x "$redhat_dir" ]
115 then
116 install -m 0644 $app_src "$redhat_dir/$app_dest"
117 found=1
118 fi
119 if [ -d "$debian_dir" -a -w "$debian_dir" -a -x "$debian_dir" ]
120 then
121 install -m 0755 $app_src "$debian_dir/$app_dest_sh"
122 found=1
123 fi
124 if [ $found -eq 1 ]; then
125 return 0
126 fi
127 cat >&2 << EOF
128Could not set up the $service_name desktop service.
129To start it at log-in for a given user, add the command $alt_command
130to the file .xinitrc in their home directory.
131EOF
132 return 1
133}
134
135
136start()
137{
138 # Todo: check configuration and correct it if necessary
139 return 0
140}
141
142stop()
143{
144 return 0
145}
146
147restart()
148{
149 stop && start
150 return 0
151}
152
153setup()
154{
155 if test -r "${CONFIG}"; then
156 . "${CONFIG}"
157 else
158 fail "Configuration file ${CONFIG} not found"
159 fi
160 test -n "$INSTALL_DIR" -a -n "$INSTALL_VER" ||
161 fail "Configuration file ${CONFIG} not complete"
162 lib_dir="${INSTALL_DIR}/other"
163 test -x "${lib_dir}" ||
164 fail "Invalid Guest Additions configuration found."
165 # By default we want to configure X
166 dox11config="true"
167 # By default, we want to run our xorg.conf setup script
168 setupxorgconf="true"
169 # All but the oldest supported X servers can automatically set up the
170 # keyboard driver.
171 autokeyboard="--autoKeyboard"
172 # On more recent servers our kernel mouse driver will be used
173 # automatically
174 automouse="--autoMouse"
175 # We need to tell our xorg.conf hacking script whether /dev/psaux exists
176 nopsaux="--nopsaux"
177 case "`uname -r`" in 2.4.*)
178 test -c /dev/psaux && nopsaux="";;
179 esac
180 # Should we use the VMSVGA driver instead of VBoxVideo?
181 if grep 80eebeef /proc/bus/pci/devices > /dev/null; then
182 vmsvga=""
183 elif grep 15ad0405 /proc/bus/pci/devices > /dev/null; then
184 vmsvga="--vmsvga"
185 else
186 dox11config=""
187 fi
188 # The video driver to install for X.Org 6.9+
189 vboxvideo_src=
190 # The mouse driver to install for X.Org 6.9+
191 vboxmouse_src=
192 # The driver extension
193 driver_ext=".so"
194 # The configuration file we generate if no original was found but we need
195 # one.
196 main_cfg="/etc/X11/xorg.conf"
197
198 modules_dir=`X -showDefaultModulePath 2>&1` || modules_dir=
199 if [ -z "$modules_dir" ]; then
200 for dir in /usr/lib64/xorg/modules /usr/lib/xorg/modules /usr/X11R6/lib64/modules /usr/X11R6/lib/modules /usr/X11R6/lib/X11/modules; do
201 if [ -d $dir ]; then
202 modules_dir=$dir
203 break
204 fi
205 done
206 fi
207
208 test -z "$x_version" -o -z "$modules_dir" &&
209 {
210 echo "Could not find the X.Org or XFree86 Window System, skipping." >&2
211 exit 0
212 }
213
214 # openSUSE 10.3 shipped X.Org 7.2 with X.Org Server 1.3, but didn't
215 # advertise the fact.
216 if grep -q '10\.3' /etc/SuSE-release 2>/dev/null; then
217 case $x_version in 7.2.*)
218 x_version=1.3.0;;
219 esac
220 fi
221 case $x_version in
222 1.*.99.* )
223 echo "Warning: unsupported pre-release version of X.Org Server installed. Not installing the X.Org drivers." >&2
224 dox11config=""
225 ;;
226 1.11.* )
227 xserver_version="X.Org Server 1.11"
228 vboxvideo_src=vboxvideo_drv_111.so
229 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
230 ;;
231 1.10.* )
232 xserver_version="X.Org Server 1.10"
233 vboxvideo_src=vboxvideo_drv_110.so
234 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
235 ;;
236 1.9.* )
237 xserver_version="X.Org Server 1.9"
238 vboxvideo_src=vboxvideo_drv_19.so
239 # Fedora 14 to 16 patched out vboxvideo detection
240 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
241 ;;
242 1.8.* )
243 xserver_version="X.Org Server 1.8"
244 vboxvideo_src=vboxvideo_drv_18.so
245 # Fedora 13 shipped without vboxvideo detection
246 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
247 ;;
248 1.7.* )
249 xserver_version="X.Org Server 1.7"
250 vboxvideo_src=vboxvideo_drv_17.so
251 setupxorgconf=""
252 ;;
253 1.6.* )
254 xserver_version="X.Org Server 1.6"
255 vboxvideo_src=vboxvideo_drv_16.so
256 vboxmouse_src=vboxmouse_drv_16.so
257 # SUSE SLE* with X.Org 1.6 does not do input autodetection;
258 # openSUSE does.
259 if grep -q -E '^SLE[^ ]' /etc/SuSE-brand 2>/dev/null; then
260 automouse=""
261 else
262 test "$system" = "suse" && setupxorgconf=""
263 fi
264 ;;
265 1.5.* )
266 xserver_version="X.Org Server 1.5"
267 vboxvideo_src=vboxvideo_drv_15.so
268 vboxmouse_src=vboxmouse_drv_15.so
269 # Historical note: SUSE with X.Org Server 1.5 disabled automatic
270 # mouse configuration and was handled specially. However since our
271 # kernel driver seems to have problems with X.Org Server 1.5 anyway
272 # we just create an X.Org configuration file and use the user space
273 # one generally, no longer just for SUSE.
274 automouse=""
275 ;;
276 1.4.* )
277 xserver_version="X.Org Server 1.4"
278 vboxvideo_src=vboxvideo_drv_14.so
279 vboxmouse_src=vboxmouse_drv_14.so
280 automouse=""
281 ;;
282 1.3.* )
283 # This was the first release which gave the server version number
284 # rather than the X11 release version when you did 'X -version'.
285 xserver_version="X.Org Server 1.3"
286 vboxvideo_src=vboxvideo_drv_13.so
287 vboxmouse_src=vboxmouse_drv_13.so
288 automouse=""
289 ;;
290 7.1.* | 7.2.* )
291 xserver_version="X.Org 7.1"
292 vboxvideo_src=vboxvideo_drv_71.so
293 vboxmouse_src=vboxmouse_drv_71.so
294 automouse=""
295 ;;
296 6.9.* | 7.0.* )
297 xserver_version="X.Org 6.9/7.0"
298 vboxvideo_src=vboxvideo_drv_70.so
299 vboxmouse_src=vboxmouse_drv_70.so
300 automouse=""
301 ;;
302 6.7* | 6.8.* | 4.2.* | 4.3.* )
303 # As the module binaries are the same we use one text for these
304 # four server versions.
305 xserver_version="XFree86 4.2/4.3 and X.Org 6.7/6.8"
306 driver_ext=.o
307 vboxvideo_src=vboxvideo_drv.o
308 vboxmouse_src=vboxmouse_drv.o
309 automouse=""
310 autokeyboard=""
311 case $x_version in
312 6.8.* )
313 autokeyboard="true"
314 ;;
315 4.2.* | 4.3.* )
316 main_cfg="/etc/X11/XF86Config"
317 ;;
318 esac
319 ;;
320 1.12.* | 1.13.* | 1.14.* | 1.15.* | 1.16.* | 1.17.* | 1.18.* )
321 xserver_version="X.Org Server ${x_version_short}"
322 vboxvideo_src=vboxvideo_drv_`echo ${x_version_short} | sed 's/\.//'`.so
323 setupxorgconf=""
324 test -f "${lib_dir}/${vboxvideo_src}" ||
325 {
326 echo "Warning: unknown version of the X Window System installed. Not installing X Window System drivers." >&2
327 dox11config=""
328 vboxvideo_src=""
329 }
330 ;;
331 * )
332 # For anything else, assume kernel drivers.
333 dox11config=""
334 ;;
335 esac
336 case "${x_version}" in
337 4.* | 6.* | 7.* | 1.?.* | 1.1[0-6].* )
338 blacklist_vboxvideo="yes"
339 ;;
340 *)
341 if test -f /etc/modprobe.d/blacklist-vboxvideo.conf; then
342 rm -f /etc/modprobe.d/blacklist-vboxvideo.conf
343 # We do not want to load the driver if X.Org Server is already
344 # running, as without a driver the server will touch the hardware
345 # directly, causing problems.
346 ps -Af | grep -q '[X]org' || ${MODPROBE} vboxvideo
347 fi
348 ;;
349 esac
350 case "$oracle_release" in
351 Oracle*release\ 6.* )
352 # relevant for OL6/UEK4 but cannot hurt for other kernels
353 blacklist_vboxvideo="yes"
354 ;;
355 esac
356 test -n "${blacklist_vboxvideo}" &&
357 echo "blacklist vboxvideo" > /etc/modprobe.d/blacklist-vboxvideo.conf
358 test -n "${dox11config}" &&
359 echo "Installing $xserver_version modules" >&2
360 case "$vboxvideo_src" in
361 ?*)
362 ln -s "${lib_dir}/$vboxvideo_src" "$modules_dir/drivers/vboxvideo_drv$driver_ext.new" &&
363 mv "$modules_dir/drivers/vboxvideo_drv$driver_ext.new" "$modules_dir/drivers/vboxvideo_drv$driver_ext";;
364 *)
365 rm "$modules_dir/drivers/vboxvideo_drv$driver_ext" 2>/dev/null
366 esac
367 case "$vboxmouse_src" in
368 ?*)
369 ln -s "${lib_dir}/$vboxmouse_src" "$modules_dir/input/vboxmouse_drv$driver_ext.new" &&
370 mv "$modules_dir/input/vboxmouse_drv$driver_ext.new" "$modules_dir/input/vboxmouse_drv$driver_ext";;
371 *)
372 rm "$modules_dir/input/vboxmouse_drv$driver_ext" 2>/dev/null
373 esac
374
375 if test -n "$dox11config"; then
376 # Certain Ubuntu/Debian versions use a special PCI-id file to identify
377 # video drivers. Some versions have the directory and don't use it.
378 # Those versions can autoload vboxvideo though, so we don't need to
379 # hack the configuration file for them.
380 test "$system" = "debian" -a -d /usr/share/xserver-xorg/pci &&
381 {
382 rm -f "/usr/share/xserver-xorg/pci/vboxvideo.ids"
383 ln -s "${lib_dir}/vboxvideo.ids" /usr/share/xserver-xorg/pci 2>/dev/null
384 test -n "$automouse" && setupxorgconf=""
385 }
386
387 # Do the XF86Config/xorg.conf hack for those versions that require it
388 configured=""
389 generated=""
390 if test -n "$setupxorgconf"; then
391 for i in $x11conf_files; do
392 if test -r "$i"; then
393 if grep -q "VirtualBox generated" "$i"; then
394 generated="$generated `printf "$i\n"`"
395 else
396 "${lib_dir}/x11config.sh" $autokeyboard $automouse $nopsaux $vmsvga "$i"
397 fi
398 configured="true"
399 fi
400 # Timestamp, so that we can see if the config file is changed
401 # by someone else later
402 test -r "$i.vbox" && touch "$i.vbox"
403 done
404 # X.Org Server 1.5 and 1.6 can detect hardware they know, but they
405 # need a configuration file for VBoxVideo.
406 nobak_cfg="`expr "${main_cfg}" : '\([^.]*\)'`.vbox.nobak"
407 if test -z "$configured"; then
408 touch "$main_cfg"
409 "${lib_dir}/x11config.sh" $autokeyboard $automouse $nopsaux $vmsvga --noBak "$main_cfg"
410 touch "${nobak_cfg}"
411 fi
412 fi
413 test -n "$generated" &&
414 cat >&2 << EOF
415The following X.Org/XFree86 configuration files were originally generated by
416the VirtualBox Guest Additions and were not modified:
417
418$generated
419
420EOF
421 tty >/dev/null && cat << EOF
422You may need to restart the Window System (or just restart the guest system)
423to enable the Guest Additions.
424
425EOF
426 fi
427
428 case "$redhat_release" in
429 # Install selinux policy for Fedora 7 and 8 to allow the X server to
430 # open device files
431 Fedora\ release\ 7* | Fedora\ release\ 8* )
432 semodule -i "${lib_dir}/vbox_x11.pp" > /dev/null 2>&1
433 ;;
434 # Similar for the accelerated graphics check on Fedora 15
435 Fedora\ release\ 15* )
436 semodule -i "${lib_dir}/vbox_accel.pp" > /dev/null 2>&1
437 ;;
438 esac
439
440 # Install selinux policy for Fedora 8 to allow the X server to
441 # open our drivers
442 case "$redhat_release" in
443 Fedora\ release\ 8* )
444 chcon -u system_u -t lib_t "${lib_dir}"/*.so
445 ;;
446 esac
447
448 # Our logging code generates some glue code on 32-bit systems. At least F10
449 # needs a rule to allow this. Send all output to /dev/null in case this is
450 # completely irrelevant on the target system.
451 chcon -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
452 semanage fcontext -a -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
453
454 # And set up VBoxClient to start when the X session does
455 install_x11_startup_app "${lib_dir}/98vboxadd-xclient" "${lib_dir}/vboxclient.desktop" VBoxClient VBoxClient-all ||
456 fail "See the log file $LOG for more information."
457 ln -s "${lib_dir}/98vboxadd-xclient" /usr/bin/VBoxClient-all 2>/dev/null
458}
459
460cleanup()
461{
462 # Restore xorg.conf files as far as possible
463 # List of generated files which have been changed since we generated them
464 newer=""
465 # Are we dealing with a legacy information which didn't support
466 # uninstallation?
467 legacy=""
468 # Do any of the restored configuration files still reference our drivers?
469 failed=""
470 # Have we encountered a "nobak" configuration file which means that there
471 # is no original file to restore?
472 nobak=""
473 test -r "$CONFIG_DIR/$CONFIG" || legacy="true"
474 for main_cfg in "/etc/X11/xorg.conf" "/etc/X11/XF86Config"; do
475 nobak_cfg="`expr "${main_cfg}" : '\([^.]*\)'`.vbox.nobak"
476 if test -r "${nobak_cfg}"; then
477 test -r "${main_cfg}" &&
478 if test -n "${legacy}" -o ! "${nobak_cfg}" -ot "${main_cfg}"; then
479 rm -f "${nobak_cfg}" "${main_cfg}"
480 else
481 newer="${newer}`printf " ${main_cfg} (no original)\n"`"
482 fi
483 nobak="true"
484 fi
485 done
486 if test -z "${nobak}"; then
487 for i in $x11conf_files; do
488 if test -r "$i.vbox"; then
489 if test ! "$i" -nt "$i.vbox" -o -n "$legacy"; then
490 mv -f "$i.vbox" "$i"
491 grep -q -E 'vboxvideo|vboxmouse' "$i" &&
492 failed="$failed`printf " $i\n"`"
493 else
494 newer="$newer`printf " $i ($i.vbox)\n"`"
495 fi
496 fi
497 done
498 fi
499 test -n "$newer" && cat >&2 << EOF
500
501The following X.Org/XFree86 configuration files were not restored, as they may
502have been changed since they were generated by the VirtualBox Guest Additions.
503You may wish to restore these manually. The file name in brackets is the
504original version.
505
506$newer
507
508EOF
509 test -n "$failed" && cat >&2 << EOF
510
511The following X.Org/XFree86 configuration files were restored, but still
512contain references to the Guest Additions drivers. You may wish to check and
513possibly correct the restored configuration files to be sure that the server
514will continue to work after it is restarted.
515
516$failed
517
518EOF
519
520 # Remove X.Org drivers
521 modules_dir=`X -showDefaultModulePath 2>&1` || modules_dir=
522 if [ -z "$modules_dir" ]; then
523 for dir in /usr/lib64/xorg/modules /usr/lib/xorg/modules /usr/X11R6/lib64/modules /usr/X11R6/lib/modules /usr/X11R6/lib/X11/modules; do
524 if [ -d $dir ]; then
525 modules_dir=$dir
526 break
527 fi
528 done
529 fi
530 rm -f "$modules_dir/drivers/vboxvideo_drv"* 2>/dev/null
531 rm -f "$modules_dir/input/vboxmouse_drv"* 2>/dev/null
532
533 # Remove the link to vboxvideo_dri.so
534 for dir in /usr/lib/dri /usr/lib32/dri /usr/lib64/dri \
535 /usr/lib/xorg/modules/dri /usr/lib32/xorg/modules/dri \
536 /usr/lib64/xorg/modules/dri /usr/lib/i386-linux-gnu/dri \
537 /usr/lib/x86_64-linux-gnu/dri; do
538 if [ -d $dir ]; then
539 rm -f "$dir/vboxvideo_dri.so" 2>/dev/null
540 fi
541 done
542
543 # Remove VBoxClient autostart files
544 rm /etc/X11/Xsession.d/98vboxadd-xclient 2>/dev/null
545 rm /etc/X11/xinit.d/98vboxadd-xclient 2>/dev/null
546 rm /etc/X11/xinit/xinitrc.d/98vboxadd-xclient.sh 2>/dev/null
547 rm /etc/xdg/autostart/vboxclient.desktop 2>/dev/null
548 rm /usr/share/autostart/vboxclient.desktop 2>/dev/null
549 rm /usr/bin/VBoxClient-all 2>/dev/null
550
551 # Remove other files
552 rm /usr/share/xserver-xorg/pci/vboxvideo.ids 2>/dev/null
553}
554
555dmnstatus()
556{
557 /bin/true
558}
559
560case "$1" in
561start)
562 start
563 ;;
564stop)
565 stop
566 ;;
567restart)
568 restart
569 ;;
570setup)
571 setup
572 ;;
573cleanup)
574 cleanup
575 ;;
576status)
577 dmnstatus
578 ;;
579*)
580 echo "Usage: $0 {start|stop|restart|status}"
581 exit 1
582esac
583
584exit
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette