VirtualBox

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

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

Additions/linux/installer: do not refuse to create a symbolic link in the installer if it already exists. The files in question are all clearly VirtualBox-specific in any case, and this goes wrong more often than it goes right.

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