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