VirtualBox

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

Last change on this file since 31638 was 31638, checked in by vboxsync, 14 years ago

Linux installer: export some files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1#!/bin/sh
2#
3# Oracle VM VirtualBox
4# VirtualBox Makeself installation starter script for Linux
5
6#
7# Copyright (C) 2006-2009 Oracle Corporation
8#
9# Oracle Corporation confidential
10# All rights reserved
11#
12
13# This is a stub installation script to be included in VirtualBox Makeself
14# installers which removes any previous installations of the package, unpacks
15# the package into the filesystem (by default under /opt) and starts the real
16# installation script.
17#
18
19PATH=$PATH:/bin:/sbin:/usr/sbin
20
21# Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
22PACKAGE="_PACKAGE_"
23PACKAGE_NAME="_PACKAGE_NAME_"
24UNINSTALL="uninstall.sh"
25ROUTINES="routines.sh"
26ARCH="_ARCH_"
27INSTALLATION_VER="_VERSION_"
28UNINSTALL_SCRIPTS="_UNINSTALL_SCRIPTS_"
29
30INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
31CONFIG_DIR="/var/lib/$PACKAGE"
32CONFIG="config"
33CONFIG_FILES="filelist"
34SELF=$1
35LOGFILE="/var/log/$PACKAGE.log"
36
37. "./$ROUTINES"
38
39check_root
40
41create_log "$LOGFILE"
42
43usage()
44{
45 info ""
46 info "Usage: install [<installation directory>] | uninstall [force] [no_setup]"
47 info ""
48 info "Example:"
49 info "$SELF install"
50 exit 1
51}
52
53# Create a symlink in the filesystem and add it to the list of package files
54add_symlink()
55{
56 self=add_symlink
57 ## Parameters:
58 # The file the link should point to
59 target="$1"
60 # The name of the actual symlink file. Must be an absolute path to a
61 # non-existing file in an existing directory.
62 link="$2"
63 link_dir="`dirname "$link"`"
64 test -n "$target" ||
65 { echo 1>&2 "$self: no target specified"; return 1; }
66 test -d "$link_dir" ||
67 { echo 1>&2 "$self: link directory $link_dir does not exist"; return 1; }
68 test ! -e "$link" ||
69 { echo 1>&2 "$self: link file "$link" already exists"; return 1; }
70 expr "$link" : "/.*" > /dev/null ||
71 { echo 1>&2 "$self: link file name is not absolute"; return 1; }
72 rm -f "$link"
73 ln -s "$target" "$link"
74 echo "$link" >> "$CONFIG_DIR/$CONFIG_FILES"
75}
76
77# Create symbolic links targeting all files in a directory in another
78# directory in the filesystem
79link_into_fs()
80{
81 ## Parameters:
82 # Directory containing the link target files
83 target_branch="$1"
84 # Directory to create the link files in
85 directory="$2"
86 for i in "$INSTALLATION_DIR/$target_branch"/*; do
87 test -e "$i" &&
88 add_symlink "$i" "$directory/`basename $i`"
89 done
90}
91
92# Look for broken installations or installations without a known uninstaller
93# and try to clean them up, asking the user first.
94def_uninstall()
95{
96 ## Parameters:
97 # Whether to force cleanup without asking the user
98 force="$1"
99
100 . ./deffiles
101 found=0
102 for i in $DEFAULT_FILE_NAMES; do
103 test "$found" = 0 -a -e "$i" && found=1
104 done
105 test "$found" = 0 &&
106 for i in $DEFAULT_VERSIONED_FILE_NAMES-*; do
107 test "$found" = 0 -a -e "$i" && found=1
108 done
109 test "$found" = 0 && return 0
110 if ! test "$1" = "force" ; then
111 cat 1>&2 << EOF
112You appear to have a version of the _PACKAGE_ software
113on your system which was installed from a different source or using a
114different type of installer. If you installed it from a package from your
115Linux distribution or if it is a default part of the system then we strongly
116recommend that you cancel this installation and remove it properly before
117installing this version. If this is simply an older or a damaged
118installation you may safely proceed.
119
120Do you wish to continue anyway? [yes or no]
121EOF
122 read reply dummy
123 if ! expr "$reply" : [yY] > /dev/null &&
124 ! expr "$reply" : [yY][eE][sS] > /dev/null
125 then
126 info
127 info "Cancelling installation."
128 return 1
129 fi
130 fi
131 # Stop what we can in the way of services and remove them from the
132 # system
133 for i in vboxvfs vboxadd-timesync vboxadd-service vboxadd; do
134 stop_init_script "$i"
135 cleanup_init "$i" 1>&2 2>> "$LOGFILE"
136 test -x "./$i" && "./$i" cleanup 1>&2 2>> "$LOGFILE"
137 remove_init_script "$i"
138 done
139
140 # Get rid of any remaining files
141 for i in $DEFAULT_FILE_NAMES; do
142 rm -f "$i" 2> /dev/null
143 done
144 for i in $DEFAULT_VERSIONED_FILE_NAMES; do
145 rm -f "$i-"* 2> /dev/null
146 done
147 rm -f "/usr/lib/$PACKAGE" "/usr/lib64/$PACKAGE" "/usr/share/$PACKAGE"
148
149 # And any packages left under /opt
150 for i in "/opt/$PACKAGE-"*; do
151 test -d "$i" && rm -rf "$i"
152 done
153 return 0
154}
155
156info "$PACKAGE_NAME installer"
157
158check_bzip2
159
160# Check architecture
161cpu=`uname -m`;
162case "$cpu" in
163 i[3456789]86|x86)
164 cpu="x86"
165 lib_path="/usr/lib"
166 ;;
167 x86_64|amd64)
168 cpu="amd64"
169 if test -d "/usr/lib64"; then
170 lib_path="/usr/lib64"
171 else
172 lib_path="/usr/lib"
173 fi
174 ;;
175 *)
176 cpu="unknown"
177esac
178ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
179if [ ! -r "$ARCH_PACKAGE" ]; then
180 info "Detected unsupported $cpu machine type."
181 exit 1
182fi
183
184# Sensible default actions
185ACTION="install"
186DO_SETUP="true"
187NO_CLEANUP=""
188FORCE_UPGRADE=""
189while true
190do
191 if [ "$2" = "" ]; then
192 break
193 fi
194 shift
195 case "$1" in
196 install)
197 ACTION="install"
198 ;;
199
200 uninstall)
201 ACTION="uninstall"
202 ;;
203
204 force)
205 FORCE_UPGRADE="force"
206 ;;
207 no_setup)
208 DO_SETUP=""
209 ;;
210 no_cleanup)
211 # Do not do cleanup of old modules when removing them. For
212 # testing purposes only.
213 DO_SETUP=""
214 NO_CLEANUP="no_cleanup"
215 ;;
216 *)
217 if [ "`echo $1|cut -c1`" != "/" ]; then
218 info "Please specify an absolute path"
219 usage
220 fi
221 INSTALLATION_DIR="$1"
222 ;;
223 esac
224done
225
226# uninstall any previous installation
227INSTALL_DIR=""
228uninstalled=0
229test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
230if test -n "$INSTALL_DIR" -a -x "$INSTALL_DIR/$UNINSTALLER"; then
231 "$INSTALL_DIR/$UNINSTALLER" $NO_CLEANUP 1>&2 ||
232 abort "Failed to remove existing installation. Aborting..."
233 uninstalled=1
234fi
235test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
236test "$uninstalled" = 0 && exit 1
237rm -f "$CONFIG_DIR/$CONFIG"
238rm -f "$CONFIG_DIR/$CONFIG_FILES"
239rmdir "$CONFIG_DIR" 2>/dev/null
240test "$ACTION" = "install" || exit 0
241
242# install the new version
243mkdir -p "$CONFIG_DIR"
244test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
245mkdir -p "$INSTALLATION_DIR"
246# Create a list of the files in the archive, skipping any directories which
247# already exist in the filesystem.
248bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
249 while read name; do
250 fullname="$INSTALLATION_DIR/$name"
251 case "$fullname" in
252 */)
253 test ! -d "$fullname" &&
254 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
255 ;;
256 *)
257 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
258 ;;
259 esac
260 done
261bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
262
263# Set symlinks into /usr and /sbin
264link_into_fs "bin" "/usr/bin"
265link_into_fs "sbin" "/usr/sbin"
266link_into_fs "lib" "$lib_path"
267link_into_fs "share" "/usr/share"
268link_into_fs "src" "/usr/src"
269
270# Install, set up and start init scripts
271for i in "$INSTALLATION_DIR/init/"*; do
272 if test -r "$i"; then
273 install_init_script "$i" "`basename "$i"`"
274 test -n "$DO_SETUP" && setup_init_script "`basename "$i"`" 1>&2
275 start_init_script "`basename "$i"`"
276 fi
277done
278
279# Remember our installation configuration
280cat > "$CONFIG_DIR/$CONFIG" << EOF
281# $PACKAGE installation record.
282# Package installation directory
283INSTALL_DIR=$INSTALLATION_DIR
284# Package uninstaller. If you repackage this software, please make sure
285# that this prints a message and returns an error so that the default
286# uninstaller does not attempt to delete the files installed by your
287# package.
288UNINSTALLER=$UNINSTALL
289# Package version
290INSTALL_VER=$INSTALLATION_VER
291EOF
292
293cp $ROUTINES $INSTALLATION_DIR
294echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
295cat > $INSTALLATION_DIR/$UNINSTALL << EOF
296#!/bin/sh
297# Auto-generated uninstallation file
298
299PATH=\$PATH:/bin:/sbin:/usr/sbin
300LOGFILE="/var/log/$PACKAGE-uninstall.log"
301
302# Read routines.sh
303if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
304 echo 1>&2 "Required file $ROUTINES not found. Aborting..."
305 return 1
306fi
307. "$INSTALLATION_DIR/$ROUTINES"
308
309# We need to be run as root
310check_root
311
312create_log "\$LOGFILE"
313
314echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
315
316NO_CLEANUP=""
317if test "\$1" = "no_cleanup"; then
318 shift
319 NO_CLEANUP="no_cleanup"
320fi
321
322test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
323
324# Stop and clean up all services
325for i in "$INSTALLATION_DIR/init/"*; do
326 if test -r "\$i"; then
327 stop_init_script "\`basename "\$i"\`"
328 test -z "\$NO_CLEANUP" && cleanup_init "\`basename "\$i"\`" 2>> "\$LOGFILE"
329 remove_init_script "\`basename "\$i"\`"
330 fi
331done
332
333# And remove all files and empty installation directories
334# Remove any non-directory entries
335cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
336# Remove any empty (of files) directories in the file list
337cat "$CONFIG_DIR/$CONFIG_FILES" |
338 while read file; do
339 case "\$file" in
340 */)
341 test -d "\$file" &&
342 find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
343 ;;
344 esac
345 done
346rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
347rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
348rmdir "$CONFIG_DIR" 2>/dev/null
349exit 0
350EOF
351chmod 0755 $INSTALLATION_DIR/$UNINSTALL
352echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
353test -n "$REMOVE_INSTALLATION_DIR" &&
354 echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
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