VirtualBox

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

Last change on this file since 46168 was 44921, checked in by vboxsync, 12 years ago

Additions/linux: cosmetical fix

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