VirtualBox

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

Last change on this file since 24487 was 24487, checked in by vboxsync, 15 years ago

Additions/linux/installer: non-Debian versions of X.Org 1.6 do need configuration file hacking

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
1#! /bin/sh
2# Sun VirtualBox
3# Linux Additions X11 setup init script ($Revision: 24487 $)
4#
5
6#
7# Copyright (C) 2006-2009 Sun Microsystems, Inc.
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# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18# Clara, CA 95054 USA or visit http://www.sun.com if you need
19# additional information or have any questions.
20#
21
22
23# chkconfig: 35 30 70
24# description: VirtualBox Linux Additions kernel modules
25#
26### BEGIN INIT INFO
27# Provides: vboxadd-x11
28# Required-Start:
29# Required-Stop:
30# Default-Start:
31# Default-Stop:
32# Description: VirtualBox Linux Additions X11 setup
33### END INIT INFO
34
35PATH=$PATH:/bin:/sbin:/usr/sbin
36LOG="/var/log/vboxadd-install-x11.log"
37
38# Find the version of X installed
39# The last of the three is for the X.org 6.7 included in Fedora Core 2
40xver=`X -version 2>&1`
41x_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'`
42# Version of Redhat or Fedora installed. Needed for setting up selinux policy.
43redhat_release=`cat /etc/redhat-release 2> /dev/null`
44# All the different possible locations for XFree86/X.Org configuration files
45# - how many of these have ever been used?
46x11conf_files="/etc/X11/xorg.conf /etc/X11/xorg.conf-4 /etc/X11/.xorg.conf \
47 /etc/xorg.conf /usr/etc/X11/xorg.conf-4 /usr/etc/X11/xorg.conf \
48 /usr/lib/X11/xorg.conf-4 /usr/lib/X11/xorg.conf /etc/X11/XF86Config-4 \
49 /etc/X11/XF86Config /etc/XF86Config /usr/X11R6/etc/X11/XF86Config-4 \
50 /usr/X11R6/etc/X11/XF86Config /usr/X11R6/lib/X11/XF86Config-4 \
51 /usr/X11R6/lib/X11/XF86Config"
52
53if [ -f /etc/arch-release ]; then
54 system=arch
55elif [ -f /etc/redhat-release ]; then
56 system=redhat
57elif [ -f /etc/SuSE-release ]; then
58 system=suse
59elif [ -f /etc/gentoo-release ]; then
60 system=gentoo
61elif [ -f /etc/lfs-release -a -d /etc/rc.d/init.d ]; then
62 system=lfs
63else
64 system=other
65fi
66
67if [ "$system" = "arch" ]; then
68 USECOLOR=yes
69 . /etc/rc.d/functions
70 fail_msg() {
71 stat_fail
72 }
73
74 succ_msg() {
75 stat_done
76 }
77
78 begin() {
79 stat_busy "$1"
80 }
81fi
82
83if [ "$system" = "redhat" ]; then
84 . /etc/init.d/functions
85 fail_msg() {
86 echo_failure
87 echo
88 }
89 succ_msg() {
90 echo_success
91 echo
92 }
93 begin() {
94 echo -n "$1"
95 }
96fi
97
98if [ "$system" = "suse" ]; then
99 . /etc/rc.status
100 fail_msg() {
101 rc_failed 1
102 rc_status -v
103 }
104 succ_msg() {
105 rc_reset
106 rc_status -v
107 }
108 begin() {
109 echo -n "$1"
110 }
111fi
112
113if [ "$system" = "gentoo" ]; then
114 if [ -f /sbin/functions.sh ]; then
115 . /sbin/functions.sh
116 elif [ -f /etc/init.d/functions.sh ]; then
117 . /etc/init.d/functions.sh
118 fi
119 fail_msg() {
120 eend 1
121 }
122 succ_msg() {
123 eend $?
124 }
125 begin() {
126 ebegin $1
127 }
128 if [ "`which $0`" = "/sbin/rc" ]; then
129 shift
130 fi
131fi
132
133if [ "$system" = "lfs" ]; then
134 . /etc/rc.d/init.d/functions
135 fail_msg() {
136 echo_failure
137 }
138 succ_msg() {
139 echo_ok
140 }
141 begin() {
142 echo $1
143 }
144fi
145
146if [ "$system" = "other" ]; then
147 fail_msg() {
148 echo " ...fail!"
149 }
150 succ_msg() {
151 echo " ...done."
152 }
153 begin() {
154 echo -n $1
155 }
156fi
157
158dev=/dev/vboxguest
159userdev=/dev/vboxuser
160owner=vboxadd
161group=1
162
163fail()
164{
165 if [ "$system" = "gentoo" ]; then
166 eerror $1
167 exit 1
168 fi
169 fail_msg
170 echo "($1)"
171 exit 1
172}
173
174# Install an X11 desktop startup application. The application should be a shell script.
175# Its name should be purely alphanumeric and should start with a two digit number (preferably
176# 98 or thereabouts) to indicate its place in the Debian Xsession startup order.
177#
178# syntax: install_x11_startup_app app desktop service_name
179install_x11_startup_app() {
180 app_src=$1
181 desktop_src=$2
182 service_name=$3
183 alt_command=$4
184 test -r "$app_src" ||
185 { echo "install_x11_startup_app: no script given"; return 1; }
186 test -r "$desktop_src" ||
187 { echo "install_x11_startup_app: no desktop file given"; return 1; }
188 test -n "$service_name" ||
189 { echo "install_x11_startup_app: no service given"; return 1; }
190 test -n "$alt_command" ||
191 { echo "install_x11_startup_app: no service given"; return 1; }
192 app_dest=`basename $app_src sh`
193 app_dest_sh=`basename $app_src sh`.sh
194 desktop_dest=`basename $desktop_src`
195 found=0
196 x11_autostart="/etc/xdg/autostart"
197 kde_autostart="/usr/share/autostart"
198 redhat_dir=/etc/X11/Xsession.d
199 mandriva_dir=/etc/X11/xinit.d
200 debian_dir=/etc/X11/xinit/xinitrc.d
201 if [ -d "$mandriva_dir" -a -w "$mandriva_dir" -a -x "$mandriva_dir" ]
202 then
203 install -m 0644 $app_src "$mandriva_dir/$app_dest"
204 found=1
205 fi
206 if [ -d "$x11_autostart" -a -w "$x11_autostart" -a -x "$x11_autostart" ]
207 then
208 install -m 0644 $desktop_src "$x11_autostart/$desktop_dest"
209 found=1
210 fi
211 if [ -d "$kde_autostart" -a -w "$kde_autostart" -a -x "$kde_autostart" ]
212 then
213 install -m 0644 $desktop_src "$kde_autostart/$desktop_dest"
214 found=1
215 fi
216 if [ -d "$redhat_dir" -a -w "$redhat_dir" -a -x "$redhat_dir" ]
217 then
218 install -m 0644 $app_src "$redhat_dir/$app_dest"
219 found=1
220 fi
221 if [ -d "$debian_dir" -a -w "$debian_dir" -a -x "$debian_dir" ]
222 then
223 install -m 0755 $app_src "$debian_dir/$app_dest_sh"
224 found=1
225 fi
226 if [ $found -eq 1 ]; then
227 return 0
228 fi
229 cat << EOF
230Could not set up the X Window $service_name service.
231To start the $service_name service at log-in for a given user,
232add the command $alt_command to the file .xinitrc in their home
233directory.
234EOF
235 return 1
236}
237
238
239start()
240{
241 # Todo: check configuration and correct it if necessary
242 return 0
243}
244
245stop()
246{
247 return 0
248}
249
250restart()
251{
252 stop && start
253 return 0
254}
255
256# setup_script
257setup()
258{
259 begin "Setting up the X Window System drivers"
260 lib_dir="/usr/lib/VBoxGuestAdditions"
261 share_dir="/usr/share/VBoxGuestAdditions"
262 test -x "$lib_dir" -a -x "$share_dir" ||
263 fail "Invalid Guest Additions configuration found"
264 # By default, we want to run our X Window System configuration script
265 dox11config=1
266 # But not the special version for X.Org 1.5+
267 dox11config15=0
268 # And we don't install our SUSE/X.Org 1.5 configuration file by default
269 dox11config15suse=0
270 # We want to use hal for auto-loading the mouse driver
271 useHalForMouse=1
272 # And on newer servers, we want to test whether dynamic resizing will work
273 testRandR=1
274 # The video driver to install for X.Org 6.9+
275 vboxvideo_src=
276 # The mouse driver to install for X.Org 6.9+
277 vboxmouse_src=
278
279 modules_dir=`X -showDefaultModulePath 2>&1` || modules_dir=
280 if [ -z "$modules_dir" ]; then
281 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
282 if [ -d $dir ]; then
283 modules_dir=$dir
284 break
285 fi
286 done
287 fi
288
289 test -z "$x_version" -o -z "$modules_dir" &&
290 fail "Could not find X.org or XFree86 on the guest system. The X Window drivers \
291will not be installed."
292
293 echo
294 case $x_version in
295 1.7.99.* )
296 echo "Warning: unsupported pre-release version of X.Org Server installed. Not"
297 echo "installing the X.Org drivers."
298 dox11config=0
299 ;;
300 1.6.99.* | 1.7.* )
301 begin "Installing experimental Xorg Server 1.7 modules"
302 vboxvideo_src=vboxvideo_drv_17.so
303 vboxmouse_src=vboxmouse_drv_17.so
304 dox11config=0
305 ;;
306 1.5.99.* | 1.6.* )
307 begin "Installing Xorg Server 1.6 modules"
308 vboxvideo_src=vboxvideo_drv_16.so
309 vboxmouse_src=vboxmouse_drv_16.so
310 dox11config15=1
311 ;;
312 1.4.99.* | 1.5.* )
313 # Fedora 9 shipped X.Org Server version 1.4.99.9x (1.5.0 RC)
314 # in its released version
315 begin "Installing Xorg Server 1.5 modules"
316 vboxvideo_src=vboxvideo_drv_15.so
317 vboxmouse_src=vboxmouse_drv_15.so
318 # SUSE with X.Org 1.5 is a special case, and is handled specially
319 if [ -f /etc/SuSE-release ]
320 then
321 dox11config15suse=1
322 else
323 # This means do a limited configuration for systems with
324 # autodetection support
325 dox11config15=1
326 fi
327 ;;
328 1.4.* )
329 begin "Installing Xorg Server 1.4 modules"
330 vboxvideo_src=vboxvideo_drv_14.so
331 vboxmouse_src=vboxmouse_drv_14.so
332 useHalForMouse=0
333 ;;
334 1.3.* )
335 # This was the first release which gave the server version number
336 # rather than the X11 release version when you did 'X -version'.
337 begin "Installing Xorg Server 1.3 modules"
338 vboxvideo_src=vboxvideo_drv_13.so
339 vboxmouse_src=vboxmouse_drv_71.so
340 useHalForMouse=0
341 ;;
342 7.1.* | 7.2.* )
343 begin "Installing Xorg 7.1 modules"
344 vboxvideo_src=vboxvideo_drv_71.so
345 vboxmouse_src=vboxmouse_drv_71.so
346 useHalForMouse=0
347 testRandR=0
348 ;;
349 6.9.* | 7.0.* )
350 begin "Installing Xorg 6.9/7.0 modules"
351 vboxvideo_src=vboxvideo_drv_70.so
352 vboxmouse_src=vboxmouse_drv_70.so
353 useHalForMouse=0
354 testRandR=0
355 ;;
356 6.7* | 6.8.* | 4.2.* | 4.3.* )
357 # Assume X.Org post-fork or XFree86
358 begin "Installing XFree86 4.3/Xorg 6.8 modules"
359 ln -s "$lib_dir/vboxvideo_drv.o" "$modules_dir/drivers/vboxvideo_drv.o"
360 ln -s "$lib_dir/vboxmouse_drv.o" "$modules_dir/input/vboxmouse_drv.o"
361 useHalForMouse=0
362 testRandR=0
363 ;;
364 * )
365 echo "Warning: unknown version of the X Window System installed. Not installing"
366 echo "X Window System drivers."
367 dox11config=0
368 useHalForMouse=0
369 ;;
370 esac
371 if [ -n "$vboxvideo_src" -a -n "$vboxmouse_src" ]; then
372 rm "$modules_dir/drivers/vboxvideo_drv.so" 2>/dev/null
373 rm "$modules_dir/input/vboxmouse_drv.so" 2>/dev/null
374 ln -s "$lib_dir/$vboxvideo_src" "$modules_dir/drivers/vboxvideo_drv.so"
375 ln -s "$lib_dir/$vboxmouse_src" "$modules_dir/input/vboxmouse_drv.so" &&
376 succ_msg
377 fi
378 if [ $testRandR -eq 1 ]; then
379 # Run VBoxRandR in test mode as it prints out useful information if
380 # dynamic resizing can't be used. Don't fail here though.
381 /usr/bin/VBoxRandR --test 1>&2
382 else
383 echo "You appear to be have an old version of the X Window system installed on"
384 echo "your guest system. Seamless mode and dynamic resizing will not work in"
385 echo "this guest."
386 fi
387 # Install selinux policy for Fedora 7 and 8 to allow the X server to
388 # open device files
389 case "$redhat_release" in
390 Fedora\ release\ 7* | Fedora\ release\ 8* )
391 semodule -i vbox_x11.pp > /dev/null 2>&1
392 ;;
393 esac
394
395 # Our logging code generates some glue code on 32-bit systems. At least F10
396 # needs a rule to allow this. Send all output to /dev/null in case this is
397 # completely irrelevant on the target system.
398 chcon -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
399 semanage fcontext -a -t unconfined_execmem_exec_t '/usr/bin/VBoxClient' > /dev/null 2>&1
400
401 # Certain Ubuntu/Debian versions use a special PCI-id file to identify
402 # video drivers. Some versions have the directory and don't use it.
403 # Those versions can autoload vboxvideo though, so we don't need to
404 # hack the configuration file for them.
405 test -f /etc/debian_version -a -d /usr/share/xserver-xorg/pci &&
406 {
407 test -h -a ! -e "$lib_dir/vboxvideo.ids" &&
408 rm -f "$lib_dir/vboxvideo.ids"
409 ln -s "$lib_dir/vboxvideo.ids" /usr/share/xserver-xorg/pci 2>/dev/null
410 test "$useHalForMouse" -eq 1 && doX11Config=0
411 }
412
413 # Do the XF86Config/xorg.conf hack for those versions that require it
414 if [ $dox11config -eq 1 ]
415 then
416 # Backup any xorg.conf files
417 for i in $x11conf_files; do
418 test -r "$i" -a ! -f "`dirname $i`/xorg.vbox.nobak" &&
419 cp "$i" "$i.vbox"
420 done
421 if [ $dox11config15suse -eq 1 ]
422 then
423 cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak 2> /dev/null
424 cp "$lib_dir/linux_xorg_suse11.conf" /etc/X11/xorg.conf 2> /dev/null
425 elif [ $dox11config15 -eq 1 ]
426 then
427 "$lib_dir/x11config15.pl" >> $LOG 2>&1
428 x11configured=0
429 for x11configdir in /etc/X11 /etc /usr/etc/X11 /usr/lib/X11
430 do
431 if [ -e $x11configdir/xorg.conf -o -e $x11configdir/xorg.conf-4 ]
432 then
433 x11configured=1
434 fi
435 if [ $x11configured -eq 0 ]
436 then
437 cat > /etc/X11/xorg.conf << EOF
438# Default xorg.conf for Xorg 1.5+ without PCI_TXT_IDS_PATH enabled.
439#
440# This file was created by VirtualBox Additions installer as it
441# was unable to find any existing configuration file for X.
442
443Section "Device"
444 Identifier "VirtualBox Video Card"
445 Driver "vboxvideo"
446EndSection
447EOF
448 touch /etc/X11/xorg.vbox.nobak
449 fi
450 done
451 else
452 "$lib_dir/x11config.pl" >> $LOG 2>&1
453 fi
454 fi
455
456 # Certain Ubuntu/Debian versions use a special PCI-id file to identify
457 # video drivers. Some versions have the directory and don't use it.
458 # Those versions can autoload vboxvideo though, so we don't need to
459 # hack the configuration file for them.
460 test -f /etc/debian_version -a -d /usr/share/xserver-xorg/pci &&
461 {
462 test -h -a ! -e "$share_dir/vboxvideo.ids" &&
463 rm -rf "$share_dir/vboxvideo.ids"
464 ln -s "$share_dir/vboxvideo.ids" /usr/share/xserver-xorg/pci 2>/dev/null
465 test "$useHalForMouse" -eq 1 && doX11Config=0
466 }
467
468 # X.Org Server versions starting with 1.5 can do mouse auto-detection,
469 # to make our lives easier and spare us the nasty hacks.
470 if [ $useHalForMouse -eq 1 ]
471 then
472 # Install hal information about the mouse driver so that X.Org
473 # knows to load it.
474 if [ -d /etc/hal/fdi/policy ]
475 then
476 install -o 0 -g 0 -m 0644 "$share_dir/90-vboxguest.fdi" /etc/hal/fdi/policy
477 # Delete the hal cache so that it notices our fdi file
478 rm -r /var/cache/hald/fdi-cache 2> /dev/null
479 fi
480 fi
481 # Install the guest OpenGL drivers
482 if [ "$ARCH" = "amd64" ]
483 then
484 LIB=/usr/lib64
485 else
486 LIB=/usr/lib
487 fi
488 if [ -d /usr/lib64/dri ]
489 then
490 rm -f /usr/lib64/dri/vboxvideo_dri.so
491 ln -s $LIB/VBoxOGL.so /usr/lib64/dri/vboxvideo_dri.so
492 elif [ -d /usr/lib/dri ]
493 then
494 rm -f /usr/lib/dri/vboxvideo_dri.so
495 ln -s $LIB/VBoxOGL.so /usr/lib/dri/vboxvideo_dri.so
496 fi
497
498 # And set up VBoxClient to start when the X session does
499 install_x11_startup_app "$lib_dir/98vboxadd-xclient" "$share_dir/vboxclient.desktop" VBoxClient VBoxClient-all
500}
501
502# cleanup_script
503cleanup()
504{
505 # Restore xorg.conf files as far as possible
506 for i in $x11conf_files; do
507 restored=0
508 if test -f "`dirname $i`/xorg.vbox.nobak"; then
509 rm -f "$i" 2> /dev/null
510 restored=1
511 elif test -r "$i.vbox"; then
512 if ! grep -q -E "vboxvideo|vboxmouse" "$i.vbox"; then
513 mv -f "$i.vbox" "$i"
514 restored=1
515 fi
516 elif test -r "$i.bak"; then
517 if ! grep -q -E "vboxvideo|vboxmouse" "$i.bak"; then
518 mv -f "$i.bak" "$i"
519 restored=1
520 fi
521 elif ! test -f "$i"; then
522 restored=1
523 fi
524 test "$restored" = 1 &&
525 rm -f "`dirname $i`/xorg.vbox.nobak" "$i.vbox" 2> /dev/null
526 test "$restored" = 0 && cat << EOF
527Failed to restore the X server configuration file $i.
528Please make sure that you reconfigure your X server before it is started
529again, as otherwise it may fail to start!
530EOF
531 done
532
533 # Remove X.Org drivers
534 find "$x11_modules_dir" /usr/lib64/xorg/modules /usr/lib/xorg/modules \
535 /usr/X11R6/lib64/modules /usr/X11R6/lib/modules \
536 /usr/X11R6/lib/X11/modules \
537 '(' -name 'vboxvideo_drv*' -o -name 'vboxmouse_drv*' ')' \
538 -exec rm -f '{}' ';' 2>/dev/null
539
540 # Remove the link to vboxvideo_dri.so
541 rm -f /usr/lib/dri/vboxvideo_dri.so /usr/lib64/dri/vboxvideo_dri.so 2>/dev/null
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
550 # Remove other files
551 rm /etc/hal/fdi/policy/90-vboxguest.fdi 2>/dev/null
552 rm /usr/share/xserver-xorg/pci/vboxvideo.ids 2>/dev/null
553}
554
555dmnstatus()
556{
557 if running_vboxguest; then
558 echo "The VirtualBox Additions are currently running."
559 else
560 echo "The VirtualBox Additions are not currently running."
561 fi
562}
563
564case "$1" in
565start)
566 start
567 ;;
568stop)
569 stop
570 ;;
571restart)
572 restart
573 ;;
574setup)
575 setup
576 ;;
577cleanup)
578 cleanup
579 ;;
580status)
581 dmnstatus
582 ;;
583*)
584 echo "Usage: $0 {start|stop|restart|status}"
585 exit 1
586esac
587
588exit
Note: See TracBrowser for help on using the repository browser.

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