VirtualBox

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

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

Additions/installer/linux: remove old directories too.

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