VirtualBox

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

Last change on this file since 57971 was 57945, checked in by vboxsync, 9 years ago

Installers/linux: cleaned up init script output and logging a bit.

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