VirtualBox

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

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

bugref:8906: Additions/linux: kernel modules not always rebuild before reboot on Fedora kernel upgrade
Load vboxvideo when it is rebuilt at boot time even on guests without Xorg.

Our Additions boot scripts load vboxvideo manually if it was previously
blacklisted. However, there is another case when it might not be loaded
automatically: when it has just been built at boot time and Xorg is not.
installed on the guest. Fix that.

  • 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: 67858 $)
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 case "${x_version}" in
209 4.* | 6.* | 7.* | 1.?.* | 1.1[0-6].* )
210 blacklist_vboxvideo="yes"
211 ;;
212 esac
213 case "$oracle_release" in
214 Oracle*release\ 6.* )
215 # relevant for OL6/UEK4 but cannot hurt for other kernels
216 blacklist_vboxvideo="yes"
217 esac
218 if test -n "${blacklist_vboxvideo}"; then
219 echo "blacklist vboxvideo" > /etc/modprobe.d/blacklist-vboxvideo.conf
220 else
221 test -f /etc/modprobe.d/blacklist-vboxvideo.conf &&
222 rm -f /etc/modprobe.d/blacklist-vboxvideo.conf
223 # We do not want to load the driver if X.Org Server is already
224 # running, as without a driver the server will touch the hardware
225 # directly, causing problems.
226 ps -Af | grep -q '[X]org' || ${MODPROBE} -q vboxvideo
227 fi
228
229 test -z "$x_version" -o -z "$modules_dir" &&
230 {
231 echo "Could not find the X.Org or XFree86 Window System, skipping." >&2
232 exit 0
233 }
234
235 # openSUSE 10.3 shipped X.Org 7.2 with X.Org Server 1.3, but didn't
236 # advertise the fact.
237 if grep -q '10\.3' /etc/SuSE-release 2>/dev/null; then
238 case $x_version in 7.2.*)
239 x_version=1.3.0;;
240 esac
241 fi
242 case $x_version in
243 1.*.99.* )
244 echo "Warning: unsupported pre-release version of X.Org Server installed. Not installing the X.Org drivers." >&2
245 dox11config=""
246 ;;
247 1.11.* )
248 xserver_version="X.Org Server 1.11"
249 vboxvideo_src=vboxvideo_drv_111.so
250 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
251 ;;
252 1.10.* )
253 xserver_version="X.Org Server 1.10"
254 vboxvideo_src=vboxvideo_drv_110.so
255 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
256 ;;
257 1.9.* )
258 xserver_version="X.Org Server 1.9"
259 vboxvideo_src=vboxvideo_drv_19.so
260 # Fedora 14 to 16 patched out vboxvideo detection
261 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
262 ;;
263 1.8.* )
264 xserver_version="X.Org Server 1.8"
265 vboxvideo_src=vboxvideo_drv_18.so
266 # Fedora 13 shipped without vboxvideo detection
267 test "$system" = "redhat" && test -z "${vmsvga}" || setupxorgconf=""
268 ;;
269 1.7.* )
270 xserver_version="X.Org Server 1.7"
271 vboxvideo_src=vboxvideo_drv_17.so
272 setupxorgconf=""
273 ;;
274 1.6.* )
275 xserver_version="X.Org Server 1.6"
276 vboxvideo_src=vboxvideo_drv_16.so
277 vboxmouse_src=vboxmouse_drv_16.so
278 # SUSE SLE* with X.Org 1.6 does not do input autodetection;
279 # openSUSE does.
280 if grep -q -E '^SLE[^ ]' /etc/SuSE-brand 2>/dev/null; then
281 automouse=""
282 else
283 test "$system" = "suse" && setupxorgconf=""
284 fi
285 ;;
286 1.5.* )
287 xserver_version="X.Org Server 1.5"
288 vboxvideo_src=vboxvideo_drv_15.so
289 vboxmouse_src=vboxmouse_drv_15.so
290 # Historical note: SUSE with X.Org Server 1.5 disabled automatic
291 # mouse configuration and was handled specially. However since our
292 # kernel driver seems to have problems with X.Org Server 1.5 anyway
293 # we just create an X.Org configuration file and use the user space
294 # one generally, no longer just for SUSE.
295 automouse=""
296 ;;
297 1.4.* )
298 xserver_version="X.Org Server 1.4"
299 vboxvideo_src=vboxvideo_drv_14.so
300 vboxmouse_src=vboxmouse_drv_14.so
301 automouse=""
302 ;;
303 1.3.* )
304 # This was the first release which gave the server version number
305 # rather than the X11 release version when you did 'X -version'.
306 xserver_version="X.Org Server 1.3"
307 vboxvideo_src=vboxvideo_drv_13.so
308 vboxmouse_src=vboxmouse_drv_13.so
309 automouse=""
310 ;;
311 7.1.* | 7.2.* )
312 xserver_version="X.Org 7.1"
313 vboxvideo_src=vboxvideo_drv_71.so
314 vboxmouse_src=vboxmouse_drv_71.so
315 automouse=""
316 ;;
317 6.9.* | 7.0.* )
318 xserver_version="X.Org 6.9/7.0"
319 vboxvideo_src=vboxvideo_drv_70.so
320 vboxmouse_src=vboxmouse_drv_70.so
321 automouse=""
322 ;;
323 6.7* | 6.8.* | 4.2.* | 4.3.* )
324 # As the module binaries are the same we use one text for these
325 # four server versions.
326 xserver_version="XFree86 4.2/4.3 and X.Org 6.7/6.8"
327 driver_ext=.o
328 vboxvideo_src=vboxvideo_drv.o
329 vboxmouse_src=vboxmouse_drv.o
330 automouse=""
331 autokeyboard=""
332 case $x_version in
333 6.8.* )
334 autokeyboard="true"
335 ;;
336 4.2.* | 4.3.* )
337 main_cfg="/etc/X11/XF86Config"
338 ;;
339 esac
340 ;;
341 1.12.* | 1.13.* | 1.14.* | 1.15.* | 1.16.* | 1.17.* | 1.18.* )
342 xserver_version="X.Org Server ${x_version_short}"
343 vboxvideo_src=vboxvideo_drv_`echo ${x_version_short} | sed 's/\.//'`.so
344 setupxorgconf=""
345 test -f "${lib_dir}/${vboxvideo_src}" ||
346 {
347 echo "Warning: unknown version of the X Window System installed. Not installing X Window System drivers." >&2
348 dox11config=""
349 vboxvideo_src=""
350 }
351 ;;
352 * )
353 # For anything else, assume kernel drivers.
354 dox11config=""
355 ;;
356 esac
357 test -n "${dox11config}" &&
358 echo "Installing $xserver_version modules" >&2
359 case "$vboxvideo_src" in
360 ?*)
361 ln -s "${lib_dir}/$vboxvideo_src" "$modules_dir/drivers/vboxvideo_drv$driver_ext.new" &&
362 mv "$modules_dir/drivers/vboxvideo_drv$driver_ext.new" "$modules_dir/drivers/vboxvideo_drv$driver_ext";;
363 *)
364 rm "$modules_dir/drivers/vboxvideo_drv$driver_ext" 2>/dev/null
365 esac
366 case "$vboxmouse_src" in
367 ?*)
368 ln -s "${lib_dir}/$vboxmouse_src" "$modules_dir/input/vboxmouse_drv$driver_ext.new" &&
369 mv "$modules_dir/input/vboxmouse_drv$driver_ext.new" "$modules_dir/input/vboxmouse_drv$driver_ext";;
370 *)
371 rm "$modules_dir/input/vboxmouse_drv$driver_ext" 2>/dev/null
372 esac
373
374 if test -n "$dox11config"; then
375 # Certain Ubuntu/Debian versions use a special PCI-id file to identify
376 # video drivers. Some versions have the directory and don't use it.
377 # Those versions can autoload vboxvideo though, so we don't need to
378 # hack the configuration file for them.
379 test "$system" = "debian" -a -d /usr/share/xserver-xorg/pci &&
380 {
381 rm -f "/usr/share/xserver-xorg/pci/vboxvideo.ids"
382 ln -s "${lib_dir}/vboxvideo.ids" /usr/share/xserver-xorg/pci 2>/dev/null
383 test -n "$automouse" && setupxorgconf=""
384 }
385
386 # Do the XF86Config/xorg.conf hack for those versions that require it
387 configured=""
388 generated=""
389 if test -n "$setupxorgconf"; then
390 for i in $x11conf_files; do
391 if test -r "$i"; then
392 if grep -q "VirtualBox generated" "$i"; then
393 generated="$generated `printf "$i\n"`"
394 else
395 "${lib_dir}/x11config.sh" $autokeyboard $automouse $nopsaux $vmsvga "$i"
396 fi
397 configured="true"
398 fi
399 # Timestamp, so that we can see if the config file is changed
400 # by someone else later
401 test -r "$i.vbox" && touch "$i.vbox"
402 done
403 # X.Org Server 1.5 and 1.6 can detect hardware they know, but they
404 # need a configuration file for VBoxVideo.
405 nobak_cfg="`expr "${main_cfg}" : '\([^.]*\)'`.vbox.nobak"
406 if test -z "$configured"; then
407 touch "$main_cfg"
408 "${lib_dir}/x11config.sh" $autokeyboard $automouse $nopsaux $vmsvga --noBak "$main_cfg"
409 touch "${nobak_cfg}"
410 fi
411 fi
412 test -n "$generated" &&
413 cat >&2 << EOF
414The following X.Org/XFree86 configuration files were originally generated by
415the VirtualBox Guest Additions and were not modified:
416
417$generated
418
419EOF
420 tty >/dev/null && cat << EOF
421You may need to restart the Window System (or just restart the guest system)
422to enable the Guest Additions.
423
424EOF
425 fi
426
427 case "$redhat_release" in
428 # Install selinux policy for Fedora 7 and 8 to allow the X server to
429 # open device files
430 Fedora\ release\ 7* | Fedora\ release\ 8* )
431 semodule -i "${lib_dir}/vbox_x11.pp" > /dev/null 2>&1
432 ;;
433 # Similar for the accelerated graphics check on Fedora 15
434 Fedora\ release\ 15* )
435 semodule -i "${lib_dir}/vbox_accel.pp" > /dev/null 2>&1
436 ;;
437 esac
438
439 # Install selinux policy for Fedora 8 to allow the X server to
440 # open our drivers
441 case "$redhat_release" in
442 Fedora\ release\ 8* )
443 chcon -u system_u -t lib_t "${lib_dir}"/*.so
444 ;;
445 esac
446
447 # Our logging code generates some glue code on 32-bit systems. At least F10
448 # needs a rule to allow this. Send all output to /dev/null in case this is
449 # completely irrelevant on the target system.
450 chcon -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
451 semanage fcontext -a -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
452
453 # And set up VBoxClient to start when the X session does
454 install_x11_startup_app "${lib_dir}/98vboxadd-xclient" "${lib_dir}/vboxclient.desktop" VBoxClient VBoxClient-all ||
455 fail "See the log file $LOG for more information."
456 ln -s "${lib_dir}/98vboxadd-xclient" /usr/bin/VBoxClient-all 2>/dev/null
457}
458
459cleanup()
460{
461 # Restore xorg.conf files as far as possible
462 # List of generated files which have been changed since we generated them
463 newer=""
464 # Are we dealing with a legacy information which didn't support
465 # uninstallation?
466 legacy=""
467 # Do any of the restored configuration files still reference our drivers?
468 failed=""
469 # Have we encountered a "nobak" configuration file which means that there
470 # is no original file to restore?
471 nobak=""
472 test -r "$CONFIG_DIR/$CONFIG" || legacy="true"
473 for main_cfg in "/etc/X11/xorg.conf" "/etc/X11/XF86Config"; do
474 nobak_cfg="`expr "${main_cfg}" : '\([^.]*\)'`.vbox.nobak"
475 if test -r "${nobak_cfg}"; then
476 test -r "${main_cfg}" &&
477 if test -n "${legacy}" -o ! "${nobak_cfg}" -ot "${main_cfg}"; then
478 rm -f "${nobak_cfg}" "${main_cfg}"
479 else
480 newer="${newer}`printf " ${main_cfg} (no original)\n"`"
481 fi
482 nobak="true"
483 fi
484 done
485 if test -z "${nobak}"; then
486 for i in $x11conf_files; do
487 if test -r "$i.vbox"; then
488 if test ! "$i" -nt "$i.vbox" -o -n "$legacy"; then
489 mv -f "$i.vbox" "$i"
490 grep -q -E 'vboxvideo|vboxmouse' "$i" &&
491 failed="$failed`printf " $i\n"`"
492 else
493 newer="$newer`printf " $i ($i.vbox)\n"`"
494 fi
495 fi
496 done
497 fi
498 test -n "$newer" && cat >&2 << EOF
499
500The following X.Org/XFree86 configuration files were not restored, as they may
501have been changed since they were generated by the VirtualBox Guest Additions.
502You may wish to restore these manually. The file name in brackets is the
503original version.
504
505$newer
506
507EOF
508 test -n "$failed" && cat >&2 << EOF
509
510The following X.Org/XFree86 configuration files were restored, but still
511contain references to the Guest Additions drivers. You may wish to check and
512possibly correct the restored configuration files to be sure that the server
513will continue to work after it is restarted.
514
515$failed
516
517EOF
518
519 # Remove X.Org drivers
520 modules_dir=`X -showDefaultModulePath 2>&1` || modules_dir=
521 if [ -z "$modules_dir" ]; then
522 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
523 if [ -d $dir ]; then
524 modules_dir=$dir
525 break
526 fi
527 done
528 fi
529 rm -f "$modules_dir/drivers/vboxvideo_drv"* 2>/dev/null
530 rm -f "$modules_dir/input/vboxmouse_drv"* 2>/dev/null
531
532 # Remove the link to vboxvideo_dri.so
533 for dir in /usr/lib/dri /usr/lib32/dri /usr/lib64/dri \
534 /usr/lib/xorg/modules/dri /usr/lib32/xorg/modules/dri \
535 /usr/lib64/xorg/modules/dri /usr/lib/i386-linux-gnu/dri \
536 /usr/lib/x86_64-linux-gnu/dri; do
537 if [ -d $dir ]; then
538 rm -f "$dir/vboxvideo_dri.so" 2>/dev/null
539 fi
540 done
541
542 # Remove VBoxClient autostart files
543 rm /etc/X11/Xsession.d/98vboxadd-xclient 2>/dev/null
544 rm /etc/X11/xinit.d/98vboxadd-xclient 2>/dev/null
545 rm /etc/X11/xinit/xinitrc.d/98vboxadd-xclient.sh 2>/dev/null
546 rm /etc/xdg/autostart/vboxclient.desktop 2>/dev/null
547 rm /usr/share/autostart/vboxclient.desktop 2>/dev/null
548 rm /usr/bin/VBoxClient-all 2>/dev/null
549
550 # Remove other files
551 rm /usr/share/xserver-xorg/pci/vboxvideo.ids 2>/dev/null
552}
553
554dmnstatus()
555{
556 /bin/true
557}
558
559case "$1" in
560start)
561 start
562 ;;
563stop)
564 stop
565 ;;
566restart)
567 restart
568 ;;
569setup)
570 setup
571 ;;
572cleanup)
573 cleanup
574 ;;
575status)
576 dmnstatus
577 ;;
578*)
579 echo "Usage: $0 {start|stop|restart|status}"
580 exit 1
581esac
582
583exit
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