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