VirtualBox

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

Last change on this file since 39323 was 39223, checked in by vboxsync, 13 years ago

Installer/linux: nomenclature.

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