VirtualBox

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

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

Additions/linux: call vboxadd-x11 during uninstall, otherwise a few files in /etc survive

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