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