VirtualBox

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

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

Additions/Linux/installer: set umask.

  • 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# Choose a proper umask
305umask 022
306
307# Set installer modules directory
308INSTALLATION_MODULES_DIR="$INSTALLATION_DIR/installer/"
309
310# install and load installer modules
311if [ -d installer ]; then
312 info "Copying additional installer modules ..."
313 mkdir -p -m 755 "$INSTALLATION_MODULES_DIR"
314 for CUR_FILE in `ls installer/*`; do
315 install -p -m 755 "$CUR_FILE" "$INSTALLATION_MODULES_DIR"
316 if [ $? -ne 0 ]; then
317 info "Error: Failed to copy installer module \"$CUR_FILE\""
318 if ! test "$FORCE_UPGRADE" = "force"; then
319 exit 1
320 fi
321 fi
322 done
323fi
324
325# install the new version
326mkdir -p -m 755 "$CONFIG_DIR"
327test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
328mkdir -p -m 755 "$INSTALLATION_DIR"
329# Create a list of the files in the archive, skipping any directories which
330# already exist in the filesystem.
331bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
332 while read name; do
333 fullname="$INSTALLATION_DIR/$name"
334 case "$fullname" in
335 */)
336 test ! -d "$fullname" &&
337 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
338 ;;
339 *)
340 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
341 ;;
342 esac
343 done
344bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
345
346# Set symlinks into /usr and /sbin
347link_into_fs "bin" "/usr/bin"
348link_into_fs "sbin" "/usr/sbin"
349link_into_fs "lib" "$lib_path"
350link_into_fs "share" "/usr/share"
351link_into_fs "src" "/usr/src"
352
353if [ -d "$INSTALLATION_MODULES_DIR" ]; then
354 info "Installing additional modules ..."
355 for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" 2>/dev/null`
356 do
357 echo "$CUR_MODULE" >> "$CONFIG_DIR/$CONFIG_FILES"
358 done
359fi
360
361for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
362do
363 mod_${CUR_MODULE}_install
364 if [ $? -ne 0 ]; then
365 info "Error: Failed to install module \"$CUR_MODULE\""
366 if ! test "$FORCE_UPGRADE" = "force"; then
367 exit 1
368 fi
369 fi
370done
371
372# Remember our installation configuration before we call any init scripts
373cat > "$CONFIG_DIR/$CONFIG" << EOF
374# $PACKAGE installation record.
375# Package installation directory
376INSTALL_DIR='$INSTALLATION_DIR'
377# Additional installation modules
378INSTALL_MODULES_DIR='$INSTALLATION_MODULES_DIR'
379INSTALL_MODULES_LIST='$INSTALLATION_MODULES_LIST'
380# Package uninstaller. If you repackage this software, please make sure
381# that this prints a message and returns an error so that the default
382# uninstaller does not attempt to delete the files installed by your
383# package.
384UNINSTALLER='$UNINSTALL'
385# Package version
386INSTALL_VER='$INSTALLATION_VER'
387INSTALL_REV='$INSTALLATION_REV'
388# Build type and user name for logging purposes
389BUILD_TYPE='$BUILD_TYPE'
390USERNAME='$USERNAME'
391EOF
392
393# Give the modules the chance to write their stuff
394# to the installation config as well.
395if [ -n "${INSTALLATION_MODULES_LIST}" ]; then
396 info "Saving modules configuration ..."
397 for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
398 do
399 echo "`mod_${CUR_MODULE}_config_save`" >> "$CONFIG_DIR/$CONFIG"
400 done
401fi
402
403# Install, set up and start init scripts
404for i in "$INSTALLATION_DIR/init/"*; do
405 if test -r "$i"; then
406 install_init_script "$i" "`basename "$i"`"
407 test -n "$DO_SETUP" && setup_init_script "`basename "$i"`" 1>&2
408 start_init_script "`basename "$i"`"
409 fi
410done
411
412cp $ROUTINES $INSTALLATION_DIR
413echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
414cat > $INSTALLATION_DIR/$UNINSTALL << EOF
415#!/bin/sh
416# Auto-generated uninstallation file
417
418PATH=\$PATH:/bin:/sbin:/usr/sbin
419LOGFILE="/var/log/$PACKAGE-uninstall.log"
420
421# Read routines.sh
422if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
423 echo 1>&2 "Required file $ROUTINES not found. Aborting..."
424 return 1
425fi
426. "$INSTALLATION_DIR/$ROUTINES"
427
428# We need to be run as root
429check_root
430
431create_log "\$LOGFILE"
432
433echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
434
435NO_CLEANUP=""
436if test "\$1" = "no_cleanup"; then
437 shift
438 NO_CLEANUP="no_cleanup"
439fi
440
441test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
442
443# Stop and clean up all services
444for i in "$INSTALLATION_DIR/init/"*; do
445 if test -r "\$i"; then
446 stop_init_script "\`basename "\$i"\`"
447 test -z "\$NO_CLEANUP" && cleanup_init "\`basename "\$i"\`" 2>> "\$LOGFILE"
448 remove_init_script "\`basename "\$i"\`"
449 fi
450done
451
452# Load all modules
453# Important: This needs to be done before loading the configuration
454# value below to not override values which are set to a default
455# value in the modules itself.
456for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" -name "module-*" 2>/dev/null`
457 do
458 . "\$CUR_MODULE"
459 done
460
461# Load configuration values
462test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
463
464# Call uninstallation initialization of all modules
465for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
466 do
467 if test -z "\$CUR_MODULE"; then
468 continue
469 fi
470 mod_\${CUR_MODULE}_pre_uninstall
471 if [ $? -ne 0 ]; then
472 echo 1>&2 "Module \"\$CUR_MODULE\" failed to initialize uninstallation"
473 # Continue initialization.
474 fi
475 done
476
477# Call uninstallation of all modules
478for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
479 do
480 if test -z "\$CUR_MODULE"; then
481 continue
482 fi
483 mod_\${CUR_MODULE}_uninstall
484 if [ $? -ne 0 ]; then
485 echo 1>&2 "Module \"\$CUR_MODULE\" failed to uninstall"
486 # Continue uninstallation.
487 fi
488 done
489
490# And remove all files and empty installation directories
491# Remove any non-directory entries
492cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
493# Remove any empty (of files) directories in the file list
494cat "$CONFIG_DIR/$CONFIG_FILES" |
495 while read file; do
496 case "\$file" in
497 */)
498 test -d "\$file" &&
499 find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
500 ;;
501 esac
502 done
503
504# Remove configuration files
505rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
506rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
507rmdir "$CONFIG_DIR" 2>/dev/null
508exit 0
509EOF
510chmod 0755 $INSTALLATION_DIR/$UNINSTALL
511echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
512test -n "$REMOVE_INSTALLATION_DIR" &&
513 echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
514
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