VirtualBox

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

Last change on this file since 60307 was 60286, checked in by vboxsync, 9 years ago

bugref:8087: Additions/x11: support non-root X server: make sure that we really load the kernel graphics driver when it is needed and simplify the installer/loader logic slightly.

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