VirtualBox

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

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

Additions/x11: VBoxClient now handles dynamic resizing using library calls, not a shell script, and for older server versions too

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