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 |
|
---|
19 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
20 |
|
---|
21 | # Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
|
---|
22 | PACKAGE="_PACKAGE_"
|
---|
23 | PACKAGE_NAME="_PACKAGE_NAME_"
|
---|
24 | UNINSTALL="uninstall.sh"
|
---|
25 | ROUTINES="routines.sh"
|
---|
26 | ARCH="_ARCH_"
|
---|
27 | INSTALLATION_VER="_VERSION_"
|
---|
28 | UNINSTALL_SCRIPTS="_UNINSTALL_SCRIPTS_"
|
---|
29 |
|
---|
30 | INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
|
---|
31 | CONFIG_DIR="/var/lib/$PACKAGE"
|
---|
32 | CONFIG="config"
|
---|
33 | CONFIG_FILES="filelist"
|
---|
34 | SELF=$1
|
---|
35 | LOGFILE="/var/log/$PACKAGE.log"
|
---|
36 |
|
---|
37 | . "./$ROUTINES"
|
---|
38 |
|
---|
39 | check_root
|
---|
40 |
|
---|
41 | create_log "$LOGFILE"
|
---|
42 |
|
---|
43 | usage()
|
---|
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
|
---|
54 | add_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
|
---|
79 | link_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.
|
---|
94 | def_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
|
---|
112 | You appear to have a version of the _PACKAGE_ software
|
---|
113 | on your system which was installed from a different source or using a
|
---|
114 | different type of installer. If you installed it from a package from your
|
---|
115 | Linux distribution or if it is a default part of the system then we strongly
|
---|
116 | recommend that you cancel this installation and remove it properly before
|
---|
117 | installing this version. If this is simply an older or a damaged
|
---|
118 | installation you may safely proceed.
|
---|
119 |
|
---|
120 | Do you wish to continue anyway? [yes or no]
|
---|
121 | EOF
|
---|
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 |
|
---|
156 | info "$PACKAGE_NAME installer"
|
---|
157 |
|
---|
158 | check_bzip2
|
---|
159 |
|
---|
160 | # Check architecture
|
---|
161 | cpu=`uname -m`;
|
---|
162 | case "$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"
|
---|
177 | esac
|
---|
178 | ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
|
---|
179 | if [ ! -r "$ARCH_PACKAGE" ]; then
|
---|
180 | info "Detected unsupported $cpu machine type."
|
---|
181 | exit 1
|
---|
182 | fi
|
---|
183 |
|
---|
184 | # Sensible default actions
|
---|
185 | ACTION="install"
|
---|
186 | DO_SETUP="true"
|
---|
187 | NO_CLEANUP=""
|
---|
188 | FORCE_UPGRADE=""
|
---|
189 | while true
|
---|
190 | do
|
---|
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
|
---|
224 | done
|
---|
225 |
|
---|
226 | # uninstall any previous installation
|
---|
227 | INSTALL_DIR=""
|
---|
228 | uninstalled=0
|
---|
229 | test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
|
---|
230 | if 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
|
---|
234 | fi
|
---|
235 | test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
|
---|
236 | test "$uninstalled" = 0 && exit 1
|
---|
237 | rm -f "$CONFIG_DIR/$CONFIG"
|
---|
238 | rm -f "$CONFIG_DIR/$CONFIG_FILES"
|
---|
239 | rmdir "$CONFIG_DIR" 2>/dev/null
|
---|
240 | test "$ACTION" = "install" || exit 0
|
---|
241 |
|
---|
242 | # install the new version
|
---|
243 | mkdir -p "$CONFIG_DIR"
|
---|
244 | test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
|
---|
245 | mkdir -p "$INSTALLATION_DIR"
|
---|
246 | # Create a list of the files in the archive, skipping any directories which
|
---|
247 | # already exist in the filesystem.
|
---|
248 | bzip2 -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
|
---|
261 | bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
|
---|
262 |
|
---|
263 | # Set symlinks into /usr and /sbin
|
---|
264 | link_into_fs "bin" "/usr/bin"
|
---|
265 | link_into_fs "sbin" "/usr/sbin"
|
---|
266 | link_into_fs "lib" "$lib_path"
|
---|
267 | link_into_fs "share" "/usr/share"
|
---|
268 | link_into_fs "src" "/usr/src"
|
---|
269 |
|
---|
270 | # Install, set up and start init scripts
|
---|
271 | for 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
|
---|
277 | done
|
---|
278 |
|
---|
279 | # Remember our installation configuration
|
---|
280 | cat > "$CONFIG_DIR/$CONFIG" << EOF
|
---|
281 | # $PACKAGE installation record.
|
---|
282 | # Package installation directory
|
---|
283 | INSTALL_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.
|
---|
288 | UNINSTALLER=$UNINSTALL
|
---|
289 | # Package version
|
---|
290 | INSTALL_VER=$INSTALLATION_VER
|
---|
291 | EOF
|
---|
292 |
|
---|
293 | cp $ROUTINES $INSTALLATION_DIR
|
---|
294 | echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
295 | cat > $INSTALLATION_DIR/$UNINSTALL << EOF
|
---|
296 | #!/bin/sh
|
---|
297 | # Auto-generated uninstallation file
|
---|
298 |
|
---|
299 | PATH=\$PATH:/bin:/sbin:/usr/sbin
|
---|
300 | LOGFILE="/var/log/$PACKAGE-uninstall.log"
|
---|
301 |
|
---|
302 | # Read routines.sh
|
---|
303 | if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
|
---|
304 | echo 1>&2 "Required file $ROUTINES not found. Aborting..."
|
---|
305 | return 1
|
---|
306 | fi
|
---|
307 | . "$INSTALLATION_DIR/$ROUTINES"
|
---|
308 |
|
---|
309 | # We need to be run as root
|
---|
310 | check_root
|
---|
311 |
|
---|
312 | create_log "\$LOGFILE"
|
---|
313 |
|
---|
314 | echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
|
---|
315 |
|
---|
316 | NO_CLEANUP=""
|
---|
317 | if test "\$1" = "no_cleanup"; then
|
---|
318 | shift
|
---|
319 | NO_CLEANUP="no_cleanup"
|
---|
320 | fi
|
---|
321 |
|
---|
322 | test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
|
---|
323 |
|
---|
324 | # Stop and clean up all services
|
---|
325 | for 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
|
---|
331 | done
|
---|
332 |
|
---|
333 | # And remove all files and empty installation directories
|
---|
334 | # Remove any non-directory entries
|
---|
335 | cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
|
---|
336 | # Remove any empty (of files) directories in the file list
|
---|
337 | cat "$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
|
---|
346 | rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
|
---|
347 | rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
|
---|
348 | rmdir "$CONFIG_DIR" 2>/dev/null
|
---|
349 | exit 0
|
---|
350 | EOF
|
---|
351 | chmod 0755 $INSTALLATION_DIR/$UNINSTALL
|
---|
352 | echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
353 | test -n "$REMOVE_INSTALLATION_DIR" &&
|
---|
354 | echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|