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-2015 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 | # Testing:
|
---|
20 | # * After successful installation, 0 is returned if the vboxguest module version
|
---|
21 | # built matches the one loaded and 2 is returned otherwise. E.g. VBoxClient
|
---|
22 | # running will prevent vboxguest reloading.
|
---|
23 | # * If the kernel modules cannot be built (run the installer with KERN_VER=none)
|
---|
24 | # or loaded (run with KERN_VER=<installed non-current version>) then 1 is
|
---|
25 | # returned.
|
---|
26 |
|
---|
27 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
28 |
|
---|
29 | # Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
|
---|
30 | PACKAGE="VBoxGuestAdditions"
|
---|
31 | PACKAGE_NAME="VirtualBox Guest Additions"
|
---|
32 | UNINSTALL="uninstall.sh"
|
---|
33 | PUBLIC_UNINSTALL_HOOK="/usr/sbin/vbox-uninstall-guest-additions"
|
---|
34 | ROUTINES="routines.sh"
|
---|
35 | INSTALLATION_VER="_VERSION_"
|
---|
36 | BUILD_TYPE="_BUILDTYPE_"
|
---|
37 | USERNAME="_USERNAME_"
|
---|
38 | UNINSTALL_SCRIPTS="vboxadd-x11 vboxvfs vboxadd-timesync vboxadd-service vboxadd"
|
---|
39 |
|
---|
40 | INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
|
---|
41 | CONFIG_DIR="/var/lib/$PACKAGE"
|
---|
42 | CONFIG="config"
|
---|
43 | CONFIG_FILES="filelist"
|
---|
44 | SELF=$1
|
---|
45 | LOGFILE="/var/log/vboxadd-install.log"
|
---|
46 |
|
---|
47 | ## Were we able to stop any previously running Additions kernel modules?
|
---|
48 | MODULES_STOPPED=1
|
---|
49 |
|
---|
50 | . "./$ROUTINES"
|
---|
51 |
|
---|
52 | check_root
|
---|
53 |
|
---|
54 | create_log "$LOGFILE"
|
---|
55 |
|
---|
56 | ## @todo r=andy: Explain options like "force" and "no_setup" -- not self-explanatory
|
---|
57 | # to the user.
|
---|
58 | usage()
|
---|
59 | {
|
---|
60 | info ""
|
---|
61 | info "Usage: $SELF install [<installation directory>]"
|
---|
62 | info " [--with-<module>] |"
|
---|
63 | info " uninstall"
|
---|
64 | info " [--force] [--no-setup]"
|
---|
65 | info ""
|
---|
66 | info "Example:"
|
---|
67 | info "$SELF install"
|
---|
68 | exit 1
|
---|
69 | }
|
---|
70 |
|
---|
71 | # Create a symlink in the filesystem and add it to the list of package files
|
---|
72 | add_symlink()
|
---|
73 | {
|
---|
74 | self=add_symlink
|
---|
75 | ## Parameters:
|
---|
76 | # The file the link should point to
|
---|
77 | target="$1"
|
---|
78 | # The name of the actual symlink file. Must be an absolute path to a
|
---|
79 | # non-existing file in an existing directory.
|
---|
80 | link="$2"
|
---|
81 | link_dir="`dirname "$link"`"
|
---|
82 | test -n "$target" ||
|
---|
83 | { echo 1>&2 "$self: no target specified"; return 1; }
|
---|
84 | test -d "$link_dir" ||
|
---|
85 | { echo 1>&2 "$self: link directory $link_dir does not exist"; return 1; }
|
---|
86 | expr "$link" : "/.*" > /dev/null ||
|
---|
87 | { echo 1>&2 "$self: link file name is not absolute"; return 1; }
|
---|
88 | rm -f "$link"
|
---|
89 | ln -s "$target" "$link"
|
---|
90 | echo "$link" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
91 | }
|
---|
92 |
|
---|
93 | # Create symbolic links targeting all files in a directory in another
|
---|
94 | # directory in the filesystem
|
---|
95 | link_into_fs()
|
---|
96 | {
|
---|
97 | ## Parameters:
|
---|
98 | # Directory containing the link target files
|
---|
99 | target_branch="$1"
|
---|
100 | # Directory to create the link files in
|
---|
101 | directory="$2"
|
---|
102 | for i in "$INSTALLATION_DIR/$target_branch"/*; do
|
---|
103 | test -e "$i" &&
|
---|
104 | add_symlink "$i" "$directory/`basename $i`"
|
---|
105 | done
|
---|
106 | }
|
---|
107 |
|
---|
108 | # Look for broken installations or installations without a known uninstaller
|
---|
109 | # and try to clean them up, asking the user first.
|
---|
110 | def_uninstall()
|
---|
111 | {
|
---|
112 | ## Parameters:
|
---|
113 | # Whether to force cleanup without asking the user
|
---|
114 | force="$1"
|
---|
115 |
|
---|
116 | . ./deffiles
|
---|
117 | found=0
|
---|
118 | for i in "/opt/$PACKAGE-"*; do
|
---|
119 | test -e "$i" && found=1
|
---|
120 | done
|
---|
121 | for i in $DEFAULT_FILE_NAMES; do
|
---|
122 | test "$found" = 0 && test -e "$i" && found=1
|
---|
123 | done
|
---|
124 | test "$found" = 0 &&
|
---|
125 | for i in $DEFAULT_VERSIONED_FILE_NAMES; do
|
---|
126 | for j in $i-*; do
|
---|
127 | test "$found" = 0 && test -e "$j" && found=1
|
---|
128 | done
|
---|
129 | done
|
---|
130 | test "$found" = 0 && return 0
|
---|
131 | if ! test "$1" = "force" ; then
|
---|
132 | # Try to make the promised notification appear on next start.
|
---|
133 | VBoxControl guestproperty delete \
|
---|
134 | /VirtualBox/GuestAdd/HostVerLastChecked 2>&1 > /dev/null
|
---|
135 | cat 1>&2 << EOF
|
---|
136 | This system appears to have a version of the VirtualBox Guest Additions
|
---|
137 | already installed. If it is part of the operating system and kept up-to-date,
|
---|
138 | there is most likely no need to replace it. If it is not up-to-date, you
|
---|
139 | should get a notification when you start the system. If you wish to replace
|
---|
140 | it with this version, please do not continue with this installation now, but
|
---|
141 | instead remove the current version first, following the instructions for the
|
---|
142 | operating system.
|
---|
143 |
|
---|
144 | If your system simply has the remains of a version of the Additions you could
|
---|
145 | not remove you should probably continue now, and these will be removed during
|
---|
146 | installation.
|
---|
147 |
|
---|
148 | Do you wish to continue? [yes or no]
|
---|
149 | EOF
|
---|
150 | read reply dummy
|
---|
151 | if ! expr "$reply" : [yY] > /dev/null &&
|
---|
152 | ! expr "$reply" : [yY][eE][sS] > /dev/null
|
---|
153 | then
|
---|
154 | info
|
---|
155 | info "Cancelling installation."
|
---|
156 | return 1
|
---|
157 | fi
|
---|
158 | fi
|
---|
159 | # Stop what we can in the way of services and remove them from the
|
---|
160 | # system
|
---|
161 | for i in $UNINSTALL_SCRIPTS; do
|
---|
162 | stop_init_script "$i" 2>> "${LOGFILE}"
|
---|
163 | test -z "$NO_CLEANUP" && test -x "./$i" && "./$i" cleanup 1>&2 2>> "$LOGFILE"
|
---|
164 | delrunlevel "$i" 2>> "${LOGFILE}"
|
---|
165 | remove_init_script "$i" 2>> "${LOGFILE}"
|
---|
166 | done
|
---|
167 | for i in "/opt/$PACKAGE-"*/init; do
|
---|
168 | for j in $UNINSTALL_SCRIPTS; do
|
---|
169 | script="${i}/${j}"
|
---|
170 | test -x "${script}" && test -z "$NO_CLEANUP" &&
|
---|
171 | grep -q '^# *cleanup_script *$' "${script}" &&
|
---|
172 | "${script}" cleanup 1>&2 2>> "$LOGFILE"
|
---|
173 | done
|
---|
174 | done
|
---|
175 |
|
---|
176 | # Get rid of any remaining files
|
---|
177 | for i in $DEFAULT_FILE_NAMES; do
|
---|
178 | rm -f "$i" 2> /dev/null
|
---|
179 | done
|
---|
180 | for i in $DEFAULT_VERSIONED_FILE_NAMES; do
|
---|
181 | rm -f "$i-"* 2> /dev/null
|
---|
182 | done
|
---|
183 | rm -f "/usr/lib/$PACKAGE" "/usr/lib64/$PACKAGE" "/usr/share/$PACKAGE" \
|
---|
184 | "/usr/lib/i386-linux-gnu/$PACKAGE" "/usr/lib/x86_64-linux-gnu/$PACKAGE"
|
---|
185 |
|
---|
186 | # And any packages left under /opt
|
---|
187 | for i in "/opt/$PACKAGE-"*; do
|
---|
188 | test -d "$i" && rm -rf "$i"
|
---|
189 | done
|
---|
190 | return 0
|
---|
191 | }
|
---|
192 |
|
---|
193 | info "$PACKAGE_NAME installer"
|
---|
194 |
|
---|
195 | # Check architecture
|
---|
196 | cpu=`uname -m`;
|
---|
197 | case "$cpu" in
|
---|
198 | i[3456789]86|x86)
|
---|
199 | cpu="x86"
|
---|
200 | lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
|
---|
201 | ;;
|
---|
202 | x86_64|amd64)
|
---|
203 | cpu="amd64"
|
---|
204 | lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
|
---|
205 | ;;
|
---|
206 | *)
|
---|
207 | cpu="unknown"
|
---|
208 | esac
|
---|
209 | ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
|
---|
210 | if [ ! -r "$ARCH_PACKAGE" ]; then
|
---|
211 | info "Detected unsupported $cpu machine type."
|
---|
212 | exit 1
|
---|
213 | fi
|
---|
214 | # Find the most appropriate libary folder by seeing which of the candidate paths
|
---|
215 | # are actually in the shared linker path list and choosing the first. We look
|
---|
216 | # for Debian-specific paths first, then LSB ones, then the new RedHat ones.
|
---|
217 | libs=`ldconfig -v 2>/dev/null | grep -v ^$'\t'`
|
---|
218 | for i in $lib_candidates; do
|
---|
219 | if echo $libs | grep -q $i; then
|
---|
220 | lib_path=$i
|
---|
221 | break
|
---|
222 | fi
|
---|
223 | done
|
---|
224 | if [ ! -x "$lib_path" ]; then
|
---|
225 | info "Unable to determine correct library path."
|
---|
226 | exit 1
|
---|
227 | fi
|
---|
228 |
|
---|
229 | # Sensible default actions
|
---|
230 | ACTION="install"
|
---|
231 | DO_SETUP="true"
|
---|
232 | NO_CLEANUP=""
|
---|
233 | FORCE_UPGRADE=""
|
---|
234 |
|
---|
235 | while [ $# -ge 2 ];
|
---|
236 | do
|
---|
237 | ARG=$2
|
---|
238 | shift
|
---|
239 |
|
---|
240 | if [ -z "$MY_END_OF_OPTIONS" ]; then
|
---|
241 | case "$ARG" in
|
---|
242 |
|
---|
243 | install)
|
---|
244 | ACTION="install"
|
---|
245 | ;;
|
---|
246 |
|
---|
247 | uninstall)
|
---|
248 | ACTION="uninstall"
|
---|
249 | ;;
|
---|
250 |
|
---|
251 | ## @todo Add per-module options handling, e.g. --lightdm-greeter-dir
|
---|
252 | # or --lightdm-config
|
---|
253 |
|
---|
254 | ## @todo Add listing all available modules (+ their options, e.g.
|
---|
255 | # with callback mod_mymod_show_options?)
|
---|
256 |
|
---|
257 | --with-*)
|
---|
258 | MODULE_CUR=`expr "$ARG" : '--with-\(.*\)'`
|
---|
259 | # Check if corresponding module in installer/module-$1 exists.
|
---|
260 | # Note: Module names may not contain spaces or other funny things.
|
---|
261 | if [ ! -f "./installer/module-${MODULE_CUR}" ]; then
|
---|
262 | info "Error: Module \"${MODULE_CUR}\" does not exist."
|
---|
263 | usage
|
---|
264 | fi
|
---|
265 | # Give the module the chance of doing initialization work / checks.
|
---|
266 | . "./installer/module-${MODULE_CUR}"
|
---|
267 | mod_${MODULE_CUR}_init
|
---|
268 | if test $? -ne 0; then
|
---|
269 | echo 1>&2 "Module '${MODULE_CUR}' failed to initialize"
|
---|
270 | if ! test "$FORCE_UPGRADE" = "force"; then
|
---|
271 | return 1
|
---|
272 | fi
|
---|
273 | # Continue initialization.
|
---|
274 | fi
|
---|
275 | # Add module to the list of modules to handle later.
|
---|
276 | if test -z "${INSTALLATION_MODULES_LIST}"; then
|
---|
277 | INSTALLATION_MODULES_LIST="${MODULE_CUR}"
|
---|
278 | else
|
---|
279 | INSTALLATION_MODULES_LIST="${INSTALLATION_MODULES_LIST} ${MODULE_CUR}"
|
---|
280 | fi
|
---|
281 | shift
|
---|
282 | ;;
|
---|
283 |
|
---|
284 | --force|force) # Keep "force" for backwards compatibility.
|
---|
285 | FORCE_UPGRADE="force"
|
---|
286 | ;;
|
---|
287 |
|
---|
288 | --no-setup|no_setup) # Keep "no_setup" for backwards compatibility.
|
---|
289 | DO_SETUP=""
|
---|
290 | ;;
|
---|
291 |
|
---|
292 | --no-cleanup|no_cleanup) # Keep "no_cleanup" for backwards compatibility.
|
---|
293 | # Do not do cleanup of old modules when removing them. For
|
---|
294 | # testing purposes only.
|
---|
295 | DO_SETUP=""
|
---|
296 | NO_CLEANUP="no_cleanup"
|
---|
297 | ;;
|
---|
298 |
|
---|
299 | --)
|
---|
300 | MY_END_OF_OPTIONS="1"
|
---|
301 | ;;
|
---|
302 |
|
---|
303 | *)
|
---|
304 | if [ "`echo $1|cut -c1`" != "/" ]; then
|
---|
305 | info "Please specify an absolute path"
|
---|
306 | usage
|
---|
307 | fi
|
---|
308 | INSTALLATION_DIR="$1"
|
---|
309 | shift
|
---|
310 | ;;
|
---|
311 | esac
|
---|
312 | fi
|
---|
313 | done
|
---|
314 |
|
---|
315 | # uninstall any previous installation
|
---|
316 | # If the currently installed Additions have provided an uninstallation hook, try
|
---|
317 | # that first.
|
---|
318 | if test -x "${PUBLIC_UNINSTALL_HOOK}"; then
|
---|
319 | "${PUBLIC_UNINSTALL_HOOK}" 1>&2 ||
|
---|
320 | abort "Failed to remove existing installation. Aborting..."
|
---|
321 | fi
|
---|
322 |
|
---|
323 | INSTALL_DIR=""
|
---|
324 | uninstalled=0
|
---|
325 | test -r "$CONFIG_DIR/$CONFIG" &&
|
---|
326 | eval `grep ^INSTALL_DIR= "$CONFIG_DIR/$CONFIG"` 2>/dev/null &&
|
---|
327 | eval `grep ^UNINSTALLER= "$CONFIG_DIR/$CONFIG"` 2>/dev/null
|
---|
328 | if test -n "$INSTALL_DIR" -a -x "$INSTALL_DIR/$UNINSTALLER"; then
|
---|
329 | "$INSTALL_DIR/$UNINSTALLER" $NO_CLEANUP 1>&2 ||
|
---|
330 | abort "Failed to remove existing installation. Aborting..."
|
---|
331 | uninstalled=1
|
---|
332 | fi
|
---|
333 | test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
|
---|
334 | test "$uninstalled" = 0 && exit 1
|
---|
335 | rm -f "$CONFIG_DIR/$CONFIG"
|
---|
336 | rm -f "$CONFIG_DIR/$CONFIG_FILES"
|
---|
337 | rmdir "$CONFIG_DIR" 2>/dev/null
|
---|
338 | test "$ACTION" = "install" || exit 0
|
---|
339 |
|
---|
340 | # Now check whether the kernel modules were stopped.
|
---|
341 | lsmod | grep -q vboxguest && MODULES_STOPPED=
|
---|
342 |
|
---|
343 | # Choose a proper umask
|
---|
344 | umask 022
|
---|
345 |
|
---|
346 | # Set installer modules directory
|
---|
347 | INSTALLATION_MODULES_DIR="$INSTALLATION_DIR/installer/"
|
---|
348 |
|
---|
349 | # install the new version
|
---|
350 | mkdir -p -m 755 "$CONFIG_DIR"
|
---|
351 | test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
|
---|
352 | mkdir -p -m 755 "$INSTALLATION_DIR"
|
---|
353 |
|
---|
354 | # install and load installer modules
|
---|
355 | if [ -d installer ]; then
|
---|
356 | info "Copying additional installer modules ..."
|
---|
357 | mkdir -p -m 755 "$INSTALLATION_MODULES_DIR"
|
---|
358 | for CUR_FILE in `ls installer/*`; do
|
---|
359 | install -p -m 755 "$CUR_FILE" "$INSTALLATION_MODULES_DIR"
|
---|
360 | if [ $? -ne 0 ]; then
|
---|
361 | info "Error: Failed to copy installer module \"$CUR_FILE\""
|
---|
362 | if ! test "$FORCE_UPGRADE" = "force"; then
|
---|
363 | exit 1
|
---|
364 | fi
|
---|
365 | fi
|
---|
366 | done
|
---|
367 | fi
|
---|
368 |
|
---|
369 | # Create a list of the files in the archive, skipping any directories which
|
---|
370 | # already exist in the filesystem.
|
---|
371 | bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
|
---|
372 | while read name; do
|
---|
373 | fullname="$INSTALLATION_DIR/$name"
|
---|
374 | case "$fullname" in
|
---|
375 | */)
|
---|
376 | test ! -d "$fullname" &&
|
---|
377 | echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
378 | ;;
|
---|
379 | *)
|
---|
380 | echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
381 | ;;
|
---|
382 | esac
|
---|
383 | done
|
---|
384 | bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
|
---|
385 |
|
---|
386 | # Set symlinks into /usr and /sbin
|
---|
387 | link_into_fs "bin" "/usr/bin"
|
---|
388 | link_into_fs "sbin" "/usr/sbin"
|
---|
389 | link_into_fs "lib" "$lib_path"
|
---|
390 | add_symlink "$INSTALLATION_DIR/lib/$PACKAGE" /usr/lib/"$PACKAGE"
|
---|
391 | link_into_fs "src" "/usr/src"
|
---|
392 |
|
---|
393 | if [ -d "$INSTALLATION_MODULES_DIR" ]; then
|
---|
394 | info "Installing additional modules ..."
|
---|
395 | for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" 2>/dev/null`
|
---|
396 | do
|
---|
397 | echo "$CUR_MODULE" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
398 | done
|
---|
399 | fi
|
---|
400 |
|
---|
401 | for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
|
---|
402 | do
|
---|
403 | mod_${CUR_MODULE}_install
|
---|
404 | if [ $? -ne 0 ]; then
|
---|
405 | info "Error: Failed to install module \"$CUR_MODULE\""
|
---|
406 | if ! test "$FORCE_UPGRADE" = "force"; then
|
---|
407 | exit 1
|
---|
408 | fi
|
---|
409 | fi
|
---|
410 | done
|
---|
411 |
|
---|
412 | # Remember our installation configuration before we call any init scripts
|
---|
413 | cat > "$CONFIG_DIR/$CONFIG" << EOF
|
---|
414 | # $PACKAGE installation record.
|
---|
415 | # Package installation directory
|
---|
416 | INSTALL_DIR='$INSTALLATION_DIR'
|
---|
417 | # Additional installation modules
|
---|
418 | INSTALL_MODULES_DIR='$INSTALLATION_MODULES_DIR'
|
---|
419 | INSTALL_MODULES_LIST='$INSTALLATION_MODULES_LIST'
|
---|
420 | # Package uninstaller. If you repackage this software, please make sure
|
---|
421 | # that this prints a message and returns an error so that the default
|
---|
422 | # uninstaller does not attempt to delete the files installed by your
|
---|
423 | # package.
|
---|
424 | UNINSTALLER='$UNINSTALL'
|
---|
425 | # Package version
|
---|
426 | INSTALL_VER='$INSTALLATION_VER'
|
---|
427 | # Build type and user name for logging purposes
|
---|
428 | BUILD_TYPE='$BUILD_TYPE'
|
---|
429 | USERNAME='$USERNAME'
|
---|
430 | EOF
|
---|
431 |
|
---|
432 | # Give the modules the chance to write their stuff
|
---|
433 | # to the installation config as well.
|
---|
434 | if [ -n "${INSTALLATION_MODULES_LIST}" ]; then
|
---|
435 | info "Saving modules configuration ..."
|
---|
436 | for CUR_MODULE in ${INSTALLATION_MODULES_LIST}
|
---|
437 | do
|
---|
438 | echo "`mod_${CUR_MODULE}_config_save`" >> "$CONFIG_DIR/$CONFIG"
|
---|
439 | done
|
---|
440 | fi
|
---|
441 |
|
---|
442 | "$INSTALLATION_DIR/init/vboxadd" setup 1>&2 2>> "${LOGFILE}"
|
---|
443 |
|
---|
444 | # Install, set up and start init scripts
|
---|
445 | for i in "$INSTALLATION_DIR/init/vboxadd" "$INSTALLATION_DIR/init/vboxadd-service"; do
|
---|
446 | install_init_script "$i" "`basename "$i"`" 2>> "${LOGFILE}"
|
---|
447 | addrunlevel "`basename "$i"`" 2>> "${LOGFILE}"
|
---|
448 | start_init_script "`basename "$i"`" 2>> "${LOGFILE}"
|
---|
449 | done
|
---|
450 |
|
---|
451 | cp $ROUTINES $INSTALLATION_DIR
|
---|
452 | echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
453 | cat > $INSTALLATION_DIR/$UNINSTALL << EOF
|
---|
454 | #!/bin/sh
|
---|
455 | # Auto-generated uninstallation file
|
---|
456 |
|
---|
457 | PATH=\$PATH:/bin:/sbin:/usr/sbin
|
---|
458 | LOGFILE="/var/log/vboxadd-uninstall.log"
|
---|
459 |
|
---|
460 | # Read routines.sh
|
---|
461 | if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
|
---|
462 | echo 1>&2 "Required file $ROUTINES not found. Aborting..."
|
---|
463 | return 1
|
---|
464 | fi
|
---|
465 | . "$INSTALLATION_DIR/$ROUTINES"
|
---|
466 |
|
---|
467 | # We need to be run as root
|
---|
468 | check_root
|
---|
469 |
|
---|
470 | create_log "\$LOGFILE"
|
---|
471 |
|
---|
472 | echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
|
---|
473 |
|
---|
474 | NO_CLEANUP=""
|
---|
475 | if test "\$1" = "no_cleanup"; then
|
---|
476 | shift
|
---|
477 | NO_CLEANUP="no_cleanup"
|
---|
478 | fi
|
---|
479 |
|
---|
480 | test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
|
---|
481 |
|
---|
482 | # Stop and clean up all services
|
---|
483 | for i in "$INSTALLATION_DIR/init/vboxadd-service" "$INSTALLATION_DIR/init/vboxadd"; do
|
---|
484 | if test -r "\$i"; then
|
---|
485 | stop_init_script "\`basename "\$i"\`" 2>> "${LOGFILE}"
|
---|
486 | test -z "\${NO_CLEANUP}" && grep -q '^# *cleanup_script *$' "\${i}" && "\${i}" cleanup 2>> "\$LOGFILE"
|
---|
487 | delrunlevel "\`basename "\$i"\`" 2>> "${LOGFILE}"
|
---|
488 | remove_init_script "\`basename "\$i"\`" 2>> "${LOGFILE}"
|
---|
489 | fi
|
---|
490 | done
|
---|
491 |
|
---|
492 | # Load all modules
|
---|
493 | # Important: This needs to be done before loading the configuration
|
---|
494 | # value below to not override values which are set to a default
|
---|
495 | # value in the modules itself.
|
---|
496 | for CUR_MODULE in `find "$INSTALLATION_MODULES_DIR" -name "module-*" 2>/dev/null`
|
---|
497 | do
|
---|
498 | . "\$CUR_MODULE"
|
---|
499 | done
|
---|
500 |
|
---|
501 | # Load configuration values
|
---|
502 | test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
|
---|
503 |
|
---|
504 | # Call uninstallation initialization of all modules
|
---|
505 | for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
|
---|
506 | do
|
---|
507 | if test -z "\$CUR_MODULE"; then
|
---|
508 | continue
|
---|
509 | fi
|
---|
510 | mod_\${CUR_MODULE}_pre_uninstall
|
---|
511 | if [ $? -ne 0 ]; then
|
---|
512 | echo 1>&2 "Module \"\$CUR_MODULE\" failed to initialize uninstallation"
|
---|
513 | # Continue initialization.
|
---|
514 | fi
|
---|
515 | done
|
---|
516 |
|
---|
517 | # Call uninstallation of all modules
|
---|
518 | for CUR_MODULE in "$INSTALLATION_MODULES_LIST"
|
---|
519 | do
|
---|
520 | if test -z "\$CUR_MODULE"; then
|
---|
521 | continue
|
---|
522 | fi
|
---|
523 | mod_\${CUR_MODULE}_uninstall
|
---|
524 | if [ $? -ne 0 ]; then
|
---|
525 | echo 1>&2 "Module \"\$CUR_MODULE\" failed to uninstall"
|
---|
526 | # Continue uninstallation.
|
---|
527 | fi
|
---|
528 | done
|
---|
529 |
|
---|
530 | # And remove all files and empty installation directories
|
---|
531 | # Remove any non-directory entries
|
---|
532 | cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
|
---|
533 | # Remove any empty (of files) directories in the file list
|
---|
534 | cat "$CONFIG_DIR/$CONFIG_FILES" |
|
---|
535 | while read file; do
|
---|
536 | case "\$file" in
|
---|
537 | */)
|
---|
538 | test -d "\$file" &&
|
---|
539 | find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
|
---|
540 | ;;
|
---|
541 | esac
|
---|
542 | done
|
---|
543 |
|
---|
544 | # Remove configuration files
|
---|
545 | rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
|
---|
546 | rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
|
---|
547 | rmdir "$CONFIG_DIR" 2>/dev/null
|
---|
548 | exit 0
|
---|
549 | EOF
|
---|
550 | chmod 0755 $INSTALLATION_DIR/$UNINSTALL
|
---|
551 | echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
552 | test -n "$REMOVE_INSTALLATION_DIR" &&
|
---|
553 | echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
554 |
|
---|
555 | cat > "${PUBLIC_UNINSTALL_HOOK}" << EOF
|
---|
556 | #!/bin/sh
|
---|
557 | # This executable provides a well-known way to uninstall VirtualBox Guest
|
---|
558 | # Additions in order to re-install them from a different source. A common case
|
---|
559 | # is uninstalling distribution-provide Additions to install the version provided
|
---|
560 | # by VirtualBox. Distributions should put the right command in here to do the
|
---|
561 | # removal, e.g. "dnf remove VirtualBox-guest-additions". Leaving kernel modules
|
---|
562 | # provided by the distribution kernel package in place is acceptable if the
|
---|
563 | # location does not clash with the VirtualBox-provided module location (misc).
|
---|
564 | $INSTALLATION_DIR/$UNINSTALL
|
---|
565 | EOF
|
---|
566 | chmod 0755 "${PUBLIC_UNINSTALL_HOOK}"
|
---|
567 | echo "$PUBLIC_UNINSTALL_HOOK" >> "$CONFIG_DIR/$CONFIG_FILES"
|
---|
568 |
|
---|
569 | # Test for a problem with old Mesa versions which stopped our 3D libraries
|
---|
570 | # from working. Known to affect Debian 7.11, probably OL/RHEL 5.
|
---|
571 | # The problem was that the system Mesa library had an ABI note, which caused
|
---|
572 | # ldconfig to always prefer it to ours.
|
---|
573 | if ldconfig -p | grep -q "libGL.so.1.*Linux 2.4"; then
|
---|
574 | gl_with_abi=`ldconfig -p | grep "libGL.so.1.*Linux 2.4" | sed 's/.*=> //'`
|
---|
575 | cat >&2 << EOF
|
---|
576 | This system appears to be running a version of Mesa with a known problem
|
---|
577 | which will prevent VirtualBox 3D pass-through from working. See
|
---|
578 | https://bugs.freedesktop.org/show_bug.cgi?id=26663
|
---|
579 | The following, run as root should fix this, though you will have to run it
|
---|
580 | again if the system version of Mesa is updated:
|
---|
581 | EOF
|
---|
582 | for i in ${gl_with_abi}; do
|
---|
583 | echo >&2 " strip -R .note.ABI-tag ${i}"
|
---|
584 | done
|
---|
585 | echo >&2 " ldconfig"
|
---|
586 | fi
|
---|
587 |
|
---|
588 | # And do a final test as to whether the kernel modules were properly created
|
---|
589 | # and loaded. Return 0 if both are true, 1 if the modules could not be built
|
---|
590 | # or loaded (except due to already running older modules) and 2 if already
|
---|
591 | # running modules probably prevented new ones from loading. vboxvideo is
|
---|
592 | # currently not tested.
|
---|
593 | # Assume that we have already printed enough messages by now and stay silent.
|
---|
594 | modinfo vboxguest >/dev/null 2>&1 || exit 1
|
---|
595 | lsmod | grep -q vboxguest || exit 1
|
---|
596 | test -n "${MODULES_STOPPED}" || exit 2
|
---|
597 | exit 0
|
---|