VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/run-inst.sh@ 50926

Last change on this file since 50926 was 50925, checked in by vboxsync, 11 years ago

Additions/linux/installer: make sure symlinks to the VBoxGuestAdditions folder and to mount.vboxsf are set correctly.

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