VirtualBox

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

Last change on this file since 56842 was 56842, checked in by vboxsync, 10 years ago

Installers/linux: do not depend on non-standard init script verbs.

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

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