VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/install.sh@ 41871

Last change on this file since 41871 was 39334, checked in by vboxsync, 13 years ago

Installers/linux: restore debug logging in kernel modules (host).

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 17.7 KB
Line 
1#!/bin/sh
2#
3# Oracle VM VirtualBox
4# VirtualBox linux installation script
5
6#
7# Copyright (C) 2007-2011 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
18PATH=$PATH:/bin:/sbin:/usr/sbin
19
20# Include routines and utilities needed by the installer
21. ./routines.sh
22#include installer-common.sh
23
24LOG="/var/log/vbox-install.log"
25VERSION="_VERSION_"
26SVNREV="_SVNREV_"
27BUILD="_BUILD_"
28ARCH="_ARCH_"
29HARDENED="_HARDENED_"
30# The "BUILD_" prefixes prevent the variables from being overwritten when we
31# read the configuration from the previous installation.
32BUILD_BUILDTYPE="_BUILDTYPE_"
33BUILD_USERNAME="_USERNAME_"
34CONFIG_DIR="/etc/vbox"
35CONFIG="vbox.cfg"
36CONFIG_FILES="filelist"
37DEFAULT_FILES=`pwd`/deffiles
38GROUPNAME="vboxusers"
39INSTALLATION_DIR="/opt/VirtualBox"
40LICENSE_ACCEPTED=""
41PREV_INSTALLATION=""
42PYTHON="_PYTHON_"
43ACTION=""
44SELF=$1
45DKMS=`which dkms 2> /dev/null`
46RC_SCRIPT=0
47if [ -n "$HARDENED" ]; then
48 VBOXDRV_MODE=0600
49 VBOXDRV_GRP="root"
50else
51 VBOXDRV_MODE=0660
52 VBOXDRV_GRP=$GROUPNAME
53fi
54VBOXUSB_MODE=0664
55VBOXUSB_GRP=$GROUPNAME
56
57
58##############################################################################
59# Helper routines #
60##############################################################################
61
62usage() {
63 info ""
64 info "Usage: install | uninstall"
65 info ""
66 info "Example:"
67 info "$SELF install"
68 exit 1
69}
70
71module_loaded() {
72 lsmod | grep -q "vboxdrv[^_-]"
73}
74
75# This routine makes sure that there is no previous installation of
76# VirtualBox other than one installed using this install script or a
77# compatible method. We do this by checking for any of the VirtualBox
78# applications in /usr/bin. If these exist and are not symlinks into
79# the installation directory, then we assume that they are from an
80# incompatible previous installation.
81
82## Helper routine: test for a particular VirtualBox binary and see if it
83## is a link into a previous installation directory
84##
85## Arguments: 1) the binary to search for and
86## 2) the installation directory (if any)
87## Returns: false if an incompatible version was detected, true otherwise
88check_binary() {
89 binary=$1
90 install_dir=$2
91 test ! -e $binary 2>&1 > /dev/null ||
92 ( test -n "$install_dir" &&
93 readlink $binary 2>/dev/null | grep "$install_dir" > /dev/null
94 )
95}
96
97## Main routine
98##
99## Argument: the directory where the previous installation should be
100## located. If this is empty, then we will assume that any
101## installation of VirtualBox found is incompatible with this one.
102## Returns: false if an incompatible installation was found, true otherwise
103check_previous() {
104 install_dir=$1
105 # These should all be symlinks into the installation folder
106 check_binary "/usr/bin/VirtualBox" "$install_dir" &&
107 check_binary "/usr/bin/VBoxManage" "$install_dir" &&
108 check_binary "/usr/bin/VBoxSDL" "$install_dir" &&
109 check_binary "/usr/bin/VBoxVRDP" "$install_dir" &&
110 check_binary "/usr/bin/VBoxHeadless" "$install_dir" &&
111 check_binary "/usr/bin/VBoxBalloonCtrl" "$install_dir" &&
112 check_binary "/usr/bin/vboxwebsrv" "$install_dir"
113}
114
115##############################################################################
116# Main script #
117##############################################################################
118
119info "VirtualBox Version $VERSION r$SVNREV ($BUILD) installer"
120
121
122# Make sure that we were invoked as root...
123check_root
124
125# Set up logging before anything else
126create_log $LOG
127
128# Now stop the ballon control service otherwise it will keep VBoxSVC running
129stop_init_script vboxballoonctrl-service
130
131# Now stop the web service otherwise it will keep VBoxSVC running
132stop_init_script vboxweb-service
133
134# Now check if no VBoxSVC daemon is running
135check_running
136
137log "VirtualBox $VERSION r$SVNREV installer, built $BUILD."
138log ""
139log "Testing system setup..."
140
141# Sanity check: figure out whether build arch matches uname arch
142cpu=`uname -m`;
143case "$cpu" in
144 i[3456789]86|x86)
145 cpu="x86"
146 ;;
147 x86_64)
148 cpu="amd64"
149 ;;
150esac
151if [ "$cpu" != "$ARCH" ]; then
152 info "Detected unsupported $cpu environment."
153 log "Detected unsupported $cpu environment."
154 exit 1
155fi
156
157# Check that the system is setup correctly for the installation
158have_bzip2="`check_bzip2; echo $?`" # Do we have bzip2?
159have_gmake="`check_gmake; echo $?`" # Do we have GNU make?
160have_ksource="`check_ksource; echo $?`" # Can we find the kernel source?
161have_gcc="`check_gcc; echo $?`" # Is GCC installed?
162
163if [ $have_bzip2 -eq 1 -o $have_gmake -eq 1 -o $have_ksource -eq 1 \
164 -o $have_gcc -eq 1 ]; then
165 info "Problems were found which would prevent VirtualBox from installing."
166 info "Please correct these problems and try again."
167 log "Giving up due to the problems mentioned above."
168 exit 1
169else
170 log "System setup appears correct."
171 log ""
172fi
173
174# Sensible default actions
175ACTION="install"
176BUILD_MODULE="true"
177while true
178do
179 if [ "$2" = "" ]; then
180 break
181 fi
182 shift
183 case "$1" in
184 install)
185 ACTION="install"
186 ;;
187
188 uninstall)
189 ACTION="uninstall"
190 ;;
191
192 force)
193 FORCE_UPGRADE=1
194 ;;
195 license_accepted_unconditionally)
196 # Legacy option
197 ;;
198 no_module)
199 BUILD_MODULE=""
200 ;;
201 *)
202 if [ "$ACTION" = "" ]; then
203 info "Unknown command '$1'."
204 usage
205 fi
206 info "Specifying an installation path is not allowed -- using /opt/VirtualBox!"
207 ;;
208 esac
209done
210
211if [ "$ACTION" = "install" ]; then
212 # Find previous installation
213 if [ ! -r $CONFIG_DIR/$CONFIG ]; then
214 mkdir -p -m 755 $CONFIG_DIR
215 touch $CONFIG_DIR/$CONFIG
216 else
217 . $CONFIG_DIR/$CONFIG
218 PREV_INSTALLATION=$INSTALL_DIR
219 fi
220 if ! check_previous $INSTALL_DIR
221 then
222 info
223 info "You appear to have a version of VirtualBox on your system which was installed"
224 info "from a different source or using a different type of installer (or a damaged"
225 info "installation of VirtualBox). We strongly recommend that you remove it before"
226 info "installing this version of VirtualBox."
227 info
228 info "Do you wish to continue anyway? [yes or no]"
229 read reply dummy
230 if ! expr "$reply" : [yY] && ! expr "$reply" : [yY][eE][sS]
231 then
232 info
233 info "Cancelling installation."
234 log "User requested cancellation of the installation"
235 exit 1
236 fi
237 fi
238
239 # Terminate Server and VBoxNetDHCP if running
240 terminate_proc VBoxSVC
241 terminate_proc VBoxNetDHCP
242
243 # Remove previous installation
244 if [ -n "$PREV_INSTALLATION" -a -z "$FORCE_UPGRADE" -a ! "$VERSION" = "$INSTALL_VER" ] &&
245 expr "$INSTALL_VER" "<" "1.6.0" > /dev/null 2>&1
246 then
247 info
248 info "If you are upgrading from VirtualBox 1.5 or older and if some of your virtual"
249 info "machines have saved states, then the saved state information will be lost"
250 info "after the upgrade and will have to be discarded. If you do not want this then"
251 info "you can cancel the upgrade now."
252 info
253 info "Do you wish to continue? [yes or no]"
254 read reply dummy
255 if ! expr "$reply" : [yY] && ! expr "$reply" : [yY][eE][sS]
256 then
257 info
258 info "Cancelling upgrade."
259 log "User requested cancellation of the installation"
260 exit 1
261 fi
262 fi
263
264 if [ ! "$VERSION" = "$INSTALL_VER" -a ! "$BUILD_MODULE" = "true" -a -n "$DKMS" ]
265 then
266 # Not doing this can confuse dkms
267 info "Rebuilding the kernel module after version change"
268 BUILD_MODULE=true
269 fi
270
271 if [ -n "$PREV_INSTALLATION" ]; then
272 [ -n "$INSTALL_REV" ] && INSTALL_REV=" r$INSTALL_REV"
273 info "Removing previous installation of VirtualBox $INSTALL_VER$INSTALL_REV from $PREV_INSTALLATION"
274 log "Removing previous installation of VirtualBox $INSTALL_VER$INSTALL_REV from $PREV_INSTALLATION"
275 log ""
276
277 stop_init_script vboxnet
278 delrunlevel vboxnet > /dev/null 2>&1
279 if [ "$BUILD_MODULE" = "true" ]; then
280 stop_init_script vboxdrv
281 if [ -n "$DKMS" ]
282 then
283 $DKMS remove -m vboxhost -v $INSTALL_VER --all > /dev/null 2>&1
284 $DKMS remove -m vboxdrv -v $INSTALL_VER --all > /dev/null 2>&1
285 $DKMS remove -m vboxnetflt -v $INSTALL_VER --all > /dev/null 2>&1
286 $DKMS remove -m vboxnetadp -v $INSTALL_VER --all > /dev/null 2>&1
287 fi
288 # OSE doesn't always have the initscript
289 rmmod vboxpci > /dev/null 2>&1
290 rmmod vboxnetadp > /dev/null 2>&1
291 rmmod vboxnetflt > /dev/null 2>&1
292 rmmod vboxdrv > /dev/null 2>&1
293
294 module_loaded && {
295 info "Warning: could not stop VirtualBox kernel module."
296 info "Please restart your system to apply changes."
297 log "Unable to remove the old VirtualBox kernel module."
298 log " An old version of VirtualBox may be running."
299 }
300 else
301 VBOX_DONT_REMOVE_OLD_MODULES=1
302 fi
303
304 VBOX_NO_UNINSTALL_MESSAGE=1
305 . ./uninstall.sh
306
307 fi
308
309 info "Installing VirtualBox to $INSTALLATION_DIR"
310 log "Installing VirtualBox to $INSTALLATION_DIR"
311 log ""
312
313 # Verify the archive
314 mkdir -p -m 755 $INSTALLATION_DIR
315 bzip2 -d -c VirtualBox.tar.bz2 | tar -tf - > $CONFIG_DIR/$CONFIG_FILES
316 RETVAL=$?
317 if [ $RETVAL != 0 ]; then
318 rmdir $INSTALLATION_DIR 2> /dev/null
319 rm -f $CONFIG_DIR/$CONFIG 2> /dev/null
320 rm -f $CONFIG_DIR/$CONFIG_FILES 2> /dev/null
321 log 'Error running "bzip2 -d -c VirtualBox.tar.bz2 | tar -tf - > '"$CONFIG_DIR/$CONFIG_FILES"'".'
322 abort "Error installing VirtualBox. Installation aborted"
323 fi
324
325 # Create installation directory and install
326 bzip2 -d -c VirtualBox.tar.bz2 | tar -xf - -C $INSTALLATION_DIR
327 RETVAL=$?
328 if [ $RETVAL != 0 ]; then
329 cwd=`pwd`
330 cd $INSTALLATION_DIR
331 rm -f `cat $CONFIG_DIR/$CONFIG_FILES` 2> /dev/null
332 cd $pwd
333 rmdir $INSTALLATION_DIR 2> /dev/null
334 rm -f $CONFIG_DIR/$CONFIG 2> /dev/null
335 log 'Error running "bzip2 -d -c VirtualBox.tar.bz2 | tar -xf - -C '"$INSTALLATION_DIR"'".'
336 abort "Error installing VirtualBox. Installation aborted"
337 fi
338
339 cp uninstall.sh routines.sh $INSTALLATION_DIR
340 echo "routines.sh" >> $CONFIG_DIR/$CONFIG_FILES
341 echo "uninstall.sh" >> $CONFIG_DIR/$CONFIG_FILES
342
343 # XXX SELinux: allow text relocation entries
344 set_selinux_permissions "$INSTALLATION_DIR" \
345 "$INSTALLATION_DIR"
346
347 # Hardened build: Mark selected binaries set-user-ID-on-execution,
348 # create symlinks for working around unsupported $ORIGIN/.. in VBoxC.so (setuid),
349 # and finally make sure the directory is only writable by the user (paranoid).
350 if [ -n "$HARDENED" ]; then
351 test -e $INSTALLATION_DIR/VirtualBox && chmod 4511 $INSTALLATION_DIR/VirtualBox
352 test -e $INSTALLATION_DIR/VBoxSDL && chmod 4511 $INSTALLATION_DIR/VBoxSDL
353 test -e $INSTALLATION_DIR/VBoxHeadless && chmod 4511 $INSTALLATION_DIR/VBoxHeadless
354 test -e $INSTALLATION_DIR/VBoxNetDHCP && chmod 4511 $INSTALLATION_DIR/VBoxNetDHCP
355
356 ln -sf $INSTALLATION_DIR/VBoxVMM.so $INSTALLATION_DIR/components/VBoxVMM.so
357 ln -sf $INSTALLATION_DIR/VBoxREM.so $INSTALLATION_DIR/components/VBoxREM.so
358 ln -sf $INSTALLATION_DIR/VBoxRT.so $INSTALLATION_DIR/components/VBoxRT.so
359 ln -sf $INSTALLATION_DIR/VBoxDDU.so $INSTALLATION_DIR/components/VBoxDDU.so
360 ln -sf $INSTALLATION_DIR/VBoxXPCOM.so $INSTALLATION_DIR/components/VBoxXPCOM.so
361
362 chmod go-w $INSTALLATION_DIR
363 fi
364
365 # This binary needs to be suid root in any case, even if not hardened
366 test -e $INSTALLATION_DIR/VBoxNetAdpCtl && chmod 4511 $INSTALLATION_DIR/VBoxNetAdpCtl
367
368 # Install runlevel scripts
369 # Note: vboxdrv is also handled by setup_init_script. This function will
370 # use chkconfig to adjust the sequence numbers, therefore vboxdrv
371 # numbers here should match the numbers in the vboxdrv.sh check
372 # header!
373 install_init_script vboxdrv.sh vboxdrv
374 install_init_script vboxballoonctrl-service.sh vboxballoonctrl-service
375 install_init_script vboxweb-service.sh vboxweb-service
376 delrunlevel vboxdrv > /dev/null 2>&1
377 addrunlevel vboxdrv 20 80 # This may produce useful output
378 delrunlevel vboxballoonctrl-service > /dev/null 2>&1
379 addrunlevel vboxballoonctrl-service 25 75 # This may produce useful output
380 delrunlevel vboxweb-service > /dev/null 2>&1
381 addrunlevel vboxweb-service 25 75 # This may produce useful output
382
383 # Create users group
384 groupadd $GROUPNAME 2> /dev/null
385
386 # Create symlinks to start binaries
387 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VirtualBox
388 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxManage
389 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxSDL
390 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxVRDP
391 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxHeadless
392 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxBalloonCtrl
393 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/vboxwebsrv
394 ln -sf $INSTALLATION_DIR/VBox.png /usr/share/pixmaps/VBox.png
395 # Unity and Nautilus seem to look here for their icons
396 ln -sf $INSTALLATION_DIR/icons/128x128/virtualbox.png /usr/share/pixmaps/virtualbox.png
397 ln -sf $INSTALLATION_DIR/virtualbox.desktop /usr/share/applications/virtualbox.desktop
398 ln -sf $INSTALLATION_DIR/virtualbox.xml /usr/share/mime/packages/virtualbox.xml
399 ln -sf $INSTALLATION_DIR/rdesktop-vrdp /usr/bin/rdesktop-vrdp
400 ln -sf $INSTALLATION_DIR/src/vboxhost /usr/src/vboxhost-_VERSION_
401
402 # Convenience symlinks. The creation fails if the FS is not case sensitive
403 ln -sf VirtualBox /usr/bin/virtualbox > /dev/null 2>&1
404 ln -sf VBoxManage /usr/bin/vboxmanage > /dev/null 2>&1
405 ln -sf VBoxSDL /usr/bin/vboxsdl > /dev/null 2>&1
406 ln -sf VBoxHeadless /usr/bin/vboxheadless > /dev/null 2>&1
407
408 # Icons
409 cur=`pwd`
410 cd $INSTALLATION_DIR/icons
411 for i in *; do
412 cd $i
413 if [ -d /usr/share/icons/hicolor/$i ]; then
414 for j in *; do
415 if [ "$j" = "virtualbox.png" ]; then
416 dst=apps
417 else
418 dst=mimetypes
419 fi
420 if [ -d /usr/share/icons/hicolor/$i/$dst ]; then
421 ln -s $INSTALLATION_DIR/icons/$i/$j /usr/share/icons/hicolor/$i/$dst/$j
422 echo /usr/share/icons/hicolor/$i/$dst/$j >> $CONFIG_DIR/$CONFIG_FILES
423 fi
424 done
425 fi
426 cd -
427 done
428 cd $cur
429
430 # Update the MIME database
431 update-mime-database /usr/share/mime 2>/dev/null
432
433 # Update the desktop database
434 update-desktop-database -q 2>/dev/null
435
436 # If Python is available, install Python bindings
437 if [ -n "$PYTHON" ]; then
438 maybe_run_python_bindings_installer $INSTALLATION_DIR
439 fi
440
441 install_device_node_setup "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR"
442
443 # Write the configuration. Do this before we call /etc/init.d/vboxdrv setup!
444 echo "# VirtualBox installation directory" > $CONFIG_DIR/$CONFIG
445 echo "INSTALL_DIR='$INSTALLATION_DIR'" >> $CONFIG_DIR/$CONFIG
446 echo "# VirtualBox version" >> $CONFIG_DIR/$CONFIG
447 echo "INSTALL_VER='$VERSION'" >> $CONFIG_DIR/$CONFIG
448 echo "INSTALL_REV='$SVNREV'" >> $CONFIG_DIR/$CONFIG
449 echo "# Build type and user name for logging purposes" >> $CONFIG_DIR/$CONFIG
450 echo "BUILD_TYPE='$BUILD_BUILDTYPE'" >> $CONFIG_DIR/$CONFIG
451 echo "USERNAME='$BUILD_USERNAME'" >> $CONFIG_DIR/$CONFIG
452
453 # Make kernel module
454 MODULE_FAILED="false"
455 if [ "$BUILD_MODULE" = "true" ]
456 then
457 info "Building the VirtualBox kernel modules"
458 log "Output from the module build process (the Linux kernel build system) follows:"
459 cur=`pwd`
460 log ""
461 setup_init_script vboxdrv
462 # Start VirtualBox kernel module
463 if [ $RETVAL -eq 0 ] && ! start_init_script vboxdrv; then
464 info "Failed to load the kernel module."
465 MODULE_FAILED="true"
466 RC_SCRIPT=1
467 fi
468 start_init_script vboxballoonctrl-service
469 start_init_script vboxweb-service
470 log ""
471 log "End of the output from the Linux kernel build system."
472 cd $cur
473 fi
474
475 info ""
476 if [ ! "$MODULE_FAILED" = "true" ]
477 then
478 info "VirtualBox has been installed successfully."
479 else
480 info "VirtualBox has been installed successfully, but the kernel module could not"
481 info "be built. When you have fixed the problems preventing this, execute"
482 info " /etc/init.d/vboxdrv setup"
483 info "as administrator to build it."
484 fi
485 info ""
486 info "You will find useful information about using VirtualBox in the user manual"
487 info " $INSTALLATION_DIR/UserManual.pdf"
488 info "and in the user FAQ"
489 info " http://www.virtualbox.org/wiki/User_FAQ"
490 info ""
491 info "We hope that you enjoy using VirtualBox."
492 info ""
493 log "Installation successful"
494elif [ "$ACTION" = "uninstall" ]; then
495 . ./uninstall.sh
496fi
497exit $RC_SCRIPT
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette