VirtualBox

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

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

Additions/linux/installer: install the X.Org server 1.5 mouse driver on servers 1.3 and 1.4 by default

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