VirtualBox

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

Last change on this file since 59865 was 58820, checked in by vboxsync, 9 years ago

Additions/linux/installers: fix error reporting when the kernel module build fails, both in the installer and the service.

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