VirtualBox

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

Last change on this file since 56874 was 56842, checked in by vboxsync, 9 years ago

Installers/linux: do not depend on non-standard init script verbs.

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