VirtualBox

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

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

bugref:8480: Guest Additions: Cannot unload vboxguest on upgrade: moved run-inst.sh from the host installer tree back to the Additions installer tree where it belongs, changed it back from being a generic installer stub to the hard-coded Additions installer and hard-coded the order of Additions set-up and clean-up scripts to ensure that we only try to unload the kernel drivers after everything else has been shut down.

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