VirtualBox

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

Last change on this file since 66891 was 64525, checked in by vboxsync, 8 years ago

Additions: fixed a few 'the the' typos

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