VirtualBox

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

Last change on this file since 59635 was 59199, checked in by vboxsync, 9 years ago

bugref:8087: Additions/x11: support non-root X server: when we load the system OpenGL library we should load the system EGL library too, as the X server uses EGL when the modesetting driver is in use.

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