VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/install.sh.in@ 66020

Last change on this file since 66020 was 64788, checked in by vboxsync, 8 years ago

bugref:8679: Additions/x11/graphics: ldconfig on Debian 7.11 guest not picking up VBoxOGL.so: old versions of Mesa contain a GNU ABI notes section which makes ldconfig always prefer them to available alternatives, regardless of the specified order of precedence. This was fixed for most current distributions in freedesktop.org bug 26663. Handle this un-invasively by detecting the problem and telling the user how to fix it.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 KB
Line 
1#!/bin/sh
2#
3# Oracle VM VirtualBox
4# VirtualBox Makeself installation starter script
5# for Linux Guest Additions
6
7#
8# Copyright (C) 2006-2015 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19# This is a stub installation script to be included in VirtualBox Makeself
20# installers which removes any previous installations of the package, unpacks
21# the package into the filesystem (by default under /opt) and starts the real
22# installation script.
23#
24PATH=$PATH:/bin:/sbin:/usr/sbin
25
26# Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
27PACKAGE="VBoxGuestAdditions"
28PACKAGE_NAME="VirtualBox Guest Additions"
29UNINSTALL="uninstall.sh"
30ROUTINES="routines.sh"
31INSTALLATION_VER="_VERSION_"
32BUILD_TYPE="_BUILDTYPE_"
33USERNAME="_USERNAME_"
34UNINSTALL_SCRIPTS="vboxadd-x11 vboxvfs vboxadd-timesync vboxadd-service vboxadd"
35
36INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
37CONFIG_DIR="/var/lib/$PACKAGE"
38CONFIG="config"
39CONFIG_FILES="filelist"
40SELF=$1
41LOGFILE="/var/log/vboxadd-install.log"
42
43. "./$ROUTINES"
44
45check_root
46
47create_log "$LOGFILE"
48
49## @todo r=andy: Explain options like "force" and "no_setup" -- not self-explanatory
50# to the user.
51usage()
52{
53 info ""
54 info "Usage: $SELF install [<installation directory>]"
55 info " [--with-<module>] |"
56 info " uninstall"
57 info " [--force] [--no-setup]"
58 info ""
59 info "Example:"
60 info "$SELF install"
61 exit 1
62}
63
64# Create a symlink in the filesystem and add it to the list of package files
65add_symlink()
66{
67 self=add_symlink
68 ## Parameters:
69 # The file the link should point to
70 target="$1"
71 # The name of the actual symlink file. Must be an absolute path to a
72 # non-existing file in an existing directory.
73 link="$2"
74 link_dir="`dirname "$link"`"
75 test -n "$target" ||
76 { echo 1>&2 "$self: no target specified"; return 1; }
77 test -d "$link_dir" ||
78 { echo 1>&2 "$self: link directory $link_dir does not exist"; return 1; }
79 expr "$link" : "/.*" > /dev/null ||
80 { echo 1>&2 "$self: link file name is not absolute"; return 1; }
81 rm -f "$link"
82 ln -s "$target" "$link"
83 echo "$link" >> "$CONFIG_DIR/$CONFIG_FILES"
84}
85
86# Create symbolic links targeting all files in a directory in another
87# directory in the filesystem
88link_into_fs()
89{
90 ## Parameters:
91 # Directory containing the link target files
92 target_branch="$1"
93 # Directory to create the link files in
94 directory="$2"
95 for i in "$INSTALLATION_DIR/$target_branch"/*; do
96 test -e "$i" &&
97 add_symlink "$i" "$directory/`basename $i`"
98 done
99}
100
101# Look for broken installations or installations without a known uninstaller
102# and try to clean them up, asking the user first.
103def_uninstall()
104{
105 ## Parameters:
106 # Whether to force cleanup without asking the user
107 force="$1"
108
109 . ./deffiles
110 found=0
111 for i in "/opt/$PACKAGE-"*; do
112 test -e "$i" && found=1
113 done
114 for i in $DEFAULT_FILE_NAMES; do
115 test "$found" = 0 && test -e "$i" && found=1
116 done
117 test "$found" = 0 &&
118 for i in $DEFAULT_VERSIONED_FILE_NAMES; do
119 for j in $i-*; do
120 test "$found" = 0 && test -e "$j" && found=1
121 done
122 done
123 test "$found" = 0 && return 0
124 if ! test "$1" = "force" ; then
125 cat 1>&2 << EOF
126You appear to have a version of the VirtualBox Guest Additions
127on your system which was installed from a different source or using a
128different type of installer. If you installed it from a package from your
129Linux distribution or if it is a default part of the system then we strongly
130recommend that you cancel this installation and remove it properly before
131installing this version. If this is simply an older or a damaged
132installation you may safely proceed.
133
134Do you wish to continue anyway? [yes or no]
135EOF
136 read reply dummy
137 if ! expr "$reply" : [yY] > /dev/null &&
138 ! expr "$reply" : [yY][eE][sS] > /dev/null
139 then
140 info
141 info "Cancelling installation."
142 return 1
143 fi
144 fi
145 # Stop what we can in the way of services and remove them from the
146 # system
147 for i in $UNINSTALL_SCRIPTS; do
148 stop_init_script "$i" 2>> "${LOGFILE}"
149 test -z "$NO_CLEANUP" && test -x "./$i" && "./$i" cleanup 1>&2 2>> "$LOGFILE"
150 delrunlevel "$i" 2>> "${LOGFILE}"
151 remove_init_script "$i" 2>> "${LOGFILE}"
152 done
153 for i in "/opt/$PACKAGE-"*/init; do
154 for j in $UNINSTALL_SCRIPTS; do
155 script="${i}/${j}"
156 test -x "${script}" && test -z "$NO_CLEANUP" &&
157 grep -q '^# *cleanup_script *$' "${script}" &&
158 "${script}" cleanup 1>&2 2>> "$LOGFILE"
159 done
160 done
161
162 # Get rid of any remaining files
163 for i in $DEFAULT_FILE_NAMES; do
164 rm -f "$i" 2> /dev/null
165 done
166 for i in $DEFAULT_VERSIONED_FILE_NAMES; do
167 rm -f "$i-"* 2> /dev/null
168 done
169 rm -f "/usr/lib/$PACKAGE" "/usr/lib64/$PACKAGE" "/usr/share/$PACKAGE" \
170 "/usr/lib/i386-linux-gnu/$PACKAGE" "/usr/lib/x86_64-linux-gnu/$PACKAGE"
171
172 # And any packages left under /opt
173 for i in "/opt/$PACKAGE-"*; do
174 test -d "$i" && rm -rf "$i"
175 done
176 return 0
177}
178
179info "$PACKAGE_NAME installer"
180
181# Check architecture
182cpu=`uname -m`;
183case "$cpu" in
184 i[3456789]86|x86)
185 cpu="x86"
186 lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
187 ;;
188 x86_64|amd64)
189 cpu="amd64"
190 lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
191 ;;
192 *)
193 cpu="unknown"
194esac
195ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
196if [ ! -r "$ARCH_PACKAGE" ]; then
197 info "Detected unsupported $cpu machine type."
198 exit 1
199fi
200# Find the most appropriate libary folder by seeing which of the candidate paths
201# are actually in the shared linker path list and choosing the first. We look
202# for Debian-specific paths first, then LSB ones, then the new RedHat ones.
203libs=`ldconfig -v 2>/dev/null | grep -v ^$'\t'`
204for i in $lib_candidates; do
205 if echo $libs | grep -q $i; then
206 lib_path=$i
207 break
208 fi
209done
210if [ ! -x "$lib_path" ]; then
211 info "Unable to determine correct library path."
212 exit 1
213fi
214
215# Sensible default actions
216ACTION="install"
217DO_SETUP="true"
218NO_CLEANUP=""
219FORCE_UPGRADE=""
220
221while [ $# -ge 2 ];
222do
223 ARG=$2
224 shift
225
226 if [ -z "$MY_END_OF_OPTIONS" ]; then
227 case "$ARG" in
228
229 install)
230 ACTION="install"
231 ;;
232
233 uninstall)
234 ACTION="uninstall"
235 ;;
236
237 ## @todo Add per-module options handling, e.g. --lightdm-greeter-dir
238 # or --lightdm-config
239
240 ## @todo Add listing all available modules (+ their options, e.g.
241 # with callback mod_mymod_show_options?)
242
243 --with-*)
244 MODULE_CUR=`expr "$ARG" : '--with-\(.*\)'`
245 # Check if corresponding module in installer/module-$1 exists.
246 # Note: Module names may not contain spaces or other funny things.
247 if [ ! -f "./installer/module-${MODULE_CUR}" ]; then
248 info "Error: Module \"${MODULE_CUR}\" does not exist."
249 usage
250 fi
251 # Give the module the chance of doing initialization work / checks.
252 . "./installer/module-${MODULE_CUR}"
253 mod_${MODULE_CUR}_init
254 if test $? -ne 0; then
255 echo 1>&2 "Module '${MODULE_CUR}' failed to initialize"
256 if ! test "$FORCE_UPGRADE" = "force"; then
257 return 1
258 fi
259 # Continue initialization.
260 fi
261 # Add module to the list of modules to handle later.
262 if test -z "${INSTALLATION_MODULES_LIST}"; then
263 INSTALLATION_MODULES_LIST="${MODULE_CUR}"
264 else
265 INSTALLATION_MODULES_LIST="${INSTALLATION_MODULES_LIST} ${MODULE_CUR}"
266 fi
267 shift
268 ;;
269
270 --force|force) # Keep "force" for backwards compatibility.
271 FORCE_UPGRADE="force"
272 ;;
273
274 --no-setup|no_setup) # Keep "no_setup" for backwards compatibility.
275 DO_SETUP=""
276 ;;
277
278 --no-cleanup|no_cleanup) # Keep "no_cleanup" for backwards compatibility.
279 # Do not do cleanup of old modules when removing them. For
280 # testing purposes only.
281 DO_SETUP=""
282 NO_CLEANUP="no_cleanup"
283 ;;
284
285 --)
286 MY_END_OF_OPTIONS="1"
287 ;;
288
289 *)
290 if [ "`echo $1|cut -c1`" != "/" ]; then
291 info "Please specify an absolute path"
292 usage
293 fi
294 INSTALLATION_DIR="$1"
295 shift
296 ;;
297 esac
298 fi
299done
300
301# uninstall any previous installation
302INSTALL_DIR=""
303uninstalled=0
304test -r "$CONFIG_DIR/$CONFIG" &&
305 eval `grep ^INSTALL_DIR= "$CONFIG_DIR/$CONFIG"` 2>/dev/null &&
306 eval `grep ^UNINSTALLER= "$CONFIG_DIR/$CONFIG"` 2>/dev/null
307if test -n "$INSTALL_DIR" -a -x "$INSTALL_DIR/$UNINSTALLER"; then
308 "$INSTALL_DIR/$UNINSTALLER" $NO_CLEANUP 1>&2 ||
309 abort "Failed to remove existing installation. Aborting..."
310 uninstalled=1
311fi
312test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
313test "$uninstalled" = 0 && exit 1
314rm -f "$CONFIG_DIR/$CONFIG"
315rm -f "$CONFIG_DIR/$CONFIG_FILES"
316rmdir "$CONFIG_DIR" 2>/dev/null
317test "$ACTION" = "install" || exit 0
318
319# Choose a proper umask
320umask 022
321
322# Set installer modules directory
323INSTALLATION_MODULES_DIR="$INSTALLATION_DIR/installer/"
324
325# install the new version
326mkdir -p -m 755 "$CONFIG_DIR"
327test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
328mkdir -p -m 755 "$INSTALLATION_DIR"
329
330# install and load installer modules
331if [ -d installer ]; then
332 info "Copying additional installer modules ..."
333 mkdir -p -m 755 "$INSTALLATION_MODULES_DIR"
334 for CUR_FILE in `ls installer/*`; do
335 install -p -m 755 "$CUR_FILE" "$INSTALLATION_MODULES_DIR"
336 if [ $? -ne 0 ]; then
337 info "Error: Failed to copy installer module \"$CUR_FILE\""
338 if ! test "$FORCE_UPGRADE" = "force"; then
339 exit 1
340 fi
341 fi
342 done
343fi
344
345# Create a list of the files in the archive, skipping any directories which
346# already exist in the filesystem.
347bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
348 while read name; do
349 fullname="$INSTALLATION_DIR/$name"
350 case "$fullname" in
351 */)
352 test ! -d "$fullname" &&
353 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
354 ;;
355 *)
356 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
357 ;;
358 esac
359 done
360bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
361
362# Set symlinks into /usr and /sbin
363link_into_fs "bin" "/usr/bin"
364link_into_fs "sbin" "/usr/sbin"
365link_into_fs "lib" "$lib_path"
366add_symlink "$INSTALLATION_DIR/lib/$PACKAGE" /usr/lib/"$PACKAGE"
367link_into_fs "src" "/usr/src"
368
369if [ -d "$INSTALLATION_MODULES_DIR" ]; then
370 info "Installing additional modules ..."
371 for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" 2>/dev/null`
372 do
373 echo "$CUR_MODULE" >> "$CONFIG_DIR/$CONFIG_FILES"
374 done
375fi
376
377for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
378do
379 mod_${CUR_MODULE}_install
380 if [ $? -ne 0 ]; then
381 info "Error: Failed to install module \"$CUR_MODULE\""
382 if ! test "$FORCE_UPGRADE" = "force"; then
383 exit 1
384 fi
385 fi
386done
387
388# Remember our installation configuration before we call any init scripts
389cat > "$CONFIG_DIR/$CONFIG" << EOF
390# $PACKAGE installation record.
391# Package installation directory
392INSTALL_DIR='$INSTALLATION_DIR'
393# Additional installation modules
394INSTALL_MODULES_DIR='$INSTALLATION_MODULES_DIR'
395INSTALL_MODULES_LIST='$INSTALLATION_MODULES_LIST'
396# Package uninstaller. If you repackage this software, please make sure
397# that this prints a message and returns an error so that the default
398# uninstaller does not attempt to delete the files installed by your
399# package.
400UNINSTALLER='$UNINSTALL'
401# Package version
402INSTALL_VER='$INSTALLATION_VER'
403# Build type and user name for logging purposes
404BUILD_TYPE='$BUILD_TYPE'
405USERNAME='$USERNAME'
406EOF
407
408# Give the modules the chance to write their stuff
409# to the installation config as well.
410if [ -n "${INSTALLATION_MODULES_LIST}" ]; then
411 info "Saving modules configuration ..."
412 for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
413 do
414 echo "`mod_${CUR_MODULE}_config_save`" >> "$CONFIG_DIR/$CONFIG"
415 done
416fi
417
418"$INSTALLATION_DIR/init/vboxadd" setup 1>&2 2>> "${LOGFILE}"
419
420# Install, set up and start init scripts
421for i in "$INSTALLATION_DIR/init/vboxadd" "$INSTALLATION_DIR/init/vboxadd-service"; do
422 install_init_script "$i" "`basename "$i"`" 2>> "${LOGFILE}"
423 addrunlevel "`basename "$i"`" 2>> "${LOGFILE}"
424 start_init_script "`basename "$i"`" 2>> "${LOGFILE}"
425done
426
427cp $ROUTINES $INSTALLATION_DIR
428echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
429cat > $INSTALLATION_DIR/$UNINSTALL << EOF
430#!/bin/sh
431# Auto-generated uninstallation file
432
433PATH=\$PATH:/bin:/sbin:/usr/sbin
434LOGFILE="/var/log/vboxadd-uninstall.log"
435
436# Read routines.sh
437if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
438 echo 1>&2 "Required file $ROUTINES not found. Aborting..."
439 return 1
440fi
441. "$INSTALLATION_DIR/$ROUTINES"
442
443# We need to be run as root
444check_root
445
446create_log "\$LOGFILE"
447
448echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
449
450NO_CLEANUP=""
451if test "\$1" = "no_cleanup"; then
452 shift
453 NO_CLEANUP="no_cleanup"
454fi
455
456test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
457
458# Stop and clean up all services
459for i in "$INSTALLATION_DIR/init/vboxadd-service" "$INSTALLATION_DIR/init/vboxadd"; do
460 if test -r "\$i"; then
461 stop_init_script "\`basename "\$i"\`" 2>> "${LOGFILE}"
462 test -z "\${NO_CLEANUP}" && grep -q '^# *cleanup_script *$' "\${i}" && "\${i}" cleanup 2>> "\$LOGFILE"
463 delrunlevel "\`basename "\$i"\`" 2>> "${LOGFILE}"
464 remove_init_script "\`basename "\$i"\`" 2>> "${LOGFILE}"
465 fi
466done
467
468# Load all modules
469# Important: This needs to be done before loading the configuration
470# value below to not override values which are set to a default
471# value in the modules itself.
472for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" -name "module-*" 2>/dev/null`
473 do
474 . "\$CUR_MODULE"
475 done
476
477# Load configuration values
478test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
479
480# Call uninstallation initialization of all modules
481for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
482 do
483 if test -z "\$CUR_MODULE"; then
484 continue
485 fi
486 mod_\${CUR_MODULE}_pre_uninstall
487 if [ $? -ne 0 ]; then
488 echo 1>&2 "Module \"\$CUR_MODULE\" failed to initialize uninstallation"
489 # Continue initialization.
490 fi
491 done
492
493# Call uninstallation of all modules
494for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
495 do
496 if test -z "\$CUR_MODULE"; then
497 continue
498 fi
499 mod_\${CUR_MODULE}_uninstall
500 if [ $? -ne 0 ]; then
501 echo 1>&2 "Module \"\$CUR_MODULE\" failed to uninstall"
502 # Continue uninstallation.
503 fi
504 done
505
506# And remove all files and empty installation directories
507# Remove any non-directory entries
508cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
509# Remove any empty (of files) directories in the file list
510cat "$CONFIG_DIR/$CONFIG_FILES" |
511 while read file; do
512 case "\$file" in
513 */)
514 test -d "\$file" &&
515 find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
516 ;;
517 esac
518 done
519
520# Remove configuration files
521rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
522rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
523rmdir "$CONFIG_DIR" 2>/dev/null
524exit 0
525EOF
526chmod 0755 $INSTALLATION_DIR/$UNINSTALL
527echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
528test -n "$REMOVE_INSTALLATION_DIR" &&
529 echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
530
531# Test for a problem with old Mesa versions which stopped our 3D libraries
532# from working. Known to affect Debian 7.11, probably OL/RHEL 5.
533# The problem was that the system Mesa library had an ABI note, which caused
534# ldconfig to always prefer it to ours.
535if ldconfig -p | grep -q "libGL.so.1.*Linux 2.4"; then
536 gl_with_abi=`ldconfig -p | grep "libGL.so.1.*Linux 2.4" | sed 's/.*=> //'`
537 cat >&2 << EOF
538This system appears to be running a version of Mesa with a known problem
539which will prevent VirtualBox 3D pass-through from working. See
540 https://bugs.freedesktop.org/show_bug.cgi?id=26663
541The following, run as root should fix this, though you will have to run it
542again if the system version of Mesa is updated:
543EOF
544 for i in ${gl_with_abi}; do
545 echo >&2 " strip -R .note.ABI-tag ${i}"
546 done
547 echo >&2 " ldconfig"
548fi
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