VirtualBox

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

Last change on this file since 39121 was 38767, checked in by vboxsync, 13 years ago

Linux installer: fixed default sequence number for the vboxdrv script to be in shape with the chkconfig header. Fixes xtracker 5818.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 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-utils.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 if [ -x /usr/bin/chcon ]; then
341 chcon -t texrel_shlib_t $INSTALLATION_DIR/VBox* > /dev/null 2>&1
342 chcon -t texrel_shlib_t $INSTALLATION_DIR/VBoxAuth.so > /dev/null 2>&1
343 chcon -t texrel_shlib_t $INSTALLATION_DIR/VirtualBox.so > /dev/null 2>&1
344 chcon -t texrel_shlib_t $INSTALLATION_DIR/components/VBox*.so > /dev/null 2>&1
345 chcon -t java_exec_t $INSTALLATION_DIR/VirtualBox > /dev/null 2>&1
346 chcon -t java_exec_t $INSTALLATION_DIR/VBoxSDL > /dev/null 2>&1
347 chcon -t java_exec_t $INSTALLATION_DIR/VBoxHeadless > /dev/null 2>&1
348 chcon -t java_exec_t $INSTALLATION_DIR/VBoxNetDHCP > /dev/null 2>&1
349 chcon -t java_exec_t $INSTALLATION_DIR/VBoxExtPackHelperApp > /dev/null 2>&1
350 chcon -t java_exec_t $INSTALLATION_DIR/vboxwebsrv > /dev/null 2>&1
351 chcon -t java_exec_t $INSTALLATION_DIR/webtest > /dev/null 2>&1
352 fi
353
354 # Hardened build: Mark selected binaries set-user-ID-on-execution,
355 # create symlinks for working around unsupported $ORIGIN/.. in VBoxC.so (setuid),
356 # and finally make sure the directory is only writable by the user (paranoid).
357 if [ -n "$HARDENED" ]; then
358 test -e $INSTALLATION_DIR/VirtualBox && chmod 4511 $INSTALLATION_DIR/VirtualBox
359 test -e $INSTALLATION_DIR/VBoxSDL && chmod 4511 $INSTALLATION_DIR/VBoxSDL
360 test -e $INSTALLATION_DIR/VBoxHeadless && chmod 4511 $INSTALLATION_DIR/VBoxHeadless
361 test -e $INSTALLATION_DIR/VBoxNetDHCP && chmod 4511 $INSTALLATION_DIR/VBoxNetDHCP
362
363 ln -sf $INSTALLATION_DIR/VBoxVMM.so $INSTALLATION_DIR/components/VBoxVMM.so
364 ln -sf $INSTALLATION_DIR/VBoxREM.so $INSTALLATION_DIR/components/VBoxREM.so
365 ln -sf $INSTALLATION_DIR/VBoxRT.so $INSTALLATION_DIR/components/VBoxRT.so
366 ln -sf $INSTALLATION_DIR/VBoxDDU.so $INSTALLATION_DIR/components/VBoxDDU.so
367 ln -sf $INSTALLATION_DIR/VBoxXPCOM.so $INSTALLATION_DIR/components/VBoxXPCOM.so
368
369 chmod go-w $INSTALLATION_DIR
370 fi
371
372 # This binary needs to be suid root in any case, even if not hardened
373 test -e $INSTALLATION_DIR/VBoxNetAdpCtl && chmod 4511 $INSTALLATION_DIR/VBoxNetAdpCtl
374
375 # Install runlevel scripts
376 # Note: vboxdrv is also handled by setup_init_script. This function will
377 # use chkconfig to adjust the sequence numbers, therefore vboxdrv
378 # numbers here should match the numbers in the vboxdrv.sh check
379 # header!
380 install_init_script vboxdrv.sh vboxdrv
381 install_init_script vboxballoonctrl-service.sh vboxballoonctrl-service
382 install_init_script vboxweb-service.sh vboxweb-service
383 delrunlevel vboxdrv > /dev/null 2>&1
384 addrunlevel vboxdrv 20 80 # This may produce useful output
385 delrunlevel vboxballoonctrl-service > /dev/null 2>&1
386 addrunlevel vboxballoonctrl-service 25 75 # This may produce useful output
387 delrunlevel vboxweb-service > /dev/null 2>&1
388 addrunlevel vboxweb-service 25 75 # This may produce useful output
389
390 # Create users group
391 groupadd $GROUPNAME 2> /dev/null
392
393 # Create symlinks to start binaries
394 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VirtualBox
395 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxManage
396 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxSDL
397 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxVRDP
398 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxHeadless
399 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxBalloonCtrl
400 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/vboxwebsrv
401 ln -sf $INSTALLATION_DIR/VBox.png /usr/share/pixmaps/VBox.png
402 # Unity and Nautilus seem to look here for their icons
403 ln -sf $INSTALLATION_DIR/icons/128x128/virtualbox.png /usr/share/pixmaps/virtualbox.png
404 ln -sf $INSTALLATION_DIR/virtualbox.desktop /usr/share/applications/virtualbox.desktop
405 ln -sf $INSTALLATION_DIR/virtualbox.xml /usr/share/mime/packages/virtualbox.xml
406 ln -sf $INSTALLATION_DIR/rdesktop-vrdp /usr/bin/rdesktop-vrdp
407 ln -sf $INSTALLATION_DIR/src/vboxhost /usr/src/vboxhost-_VERSION_
408
409 # Convenience symlinks. The creation fails if the FS is not case sensitive
410 ln -sf VirtualBox /usr/bin/virtualbox > /dev/null 2>&1
411 ln -sf VBoxManage /usr/bin/vboxmanage > /dev/null 2>&1
412 ln -sf VBoxSDL /usr/bin/vboxsdl > /dev/null 2>&1
413 ln -sf VBoxHeadless /usr/bin/vboxheadless > /dev/null 2>&1
414
415 # Icons
416 cur=`pwd`
417 cd $INSTALLATION_DIR/icons
418 for i in *; do
419 cd $i
420 if [ -d /usr/share/icons/hicolor/$i ]; then
421 for j in *; do
422 if [ "$j" = "virtualbox.png" ]; then
423 dst=apps
424 else
425 dst=mimetypes
426 fi
427 if [ -d /usr/share/icons/hicolor/$i/$dst ]; then
428 ln -s $INSTALLATION_DIR/icons/$i/$j /usr/share/icons/hicolor/$i/$dst/$j
429 echo /usr/share/icons/hicolor/$i/$dst/$j >> $CONFIG_DIR/$CONFIG_FILES
430 fi
431 done
432 fi
433 cd -
434 done
435 cd $cur
436
437 # Update the MIME database
438 update-mime-database /usr/share/mime 2>/dev/null
439
440 # Update the desktop database
441 update-desktop-database -q 2>/dev/null
442
443 # If Python is available, install Python bindings
444 if [ -n "$PYTHON" ]; then
445 maybe_run_python_bindings_installer $INSTALLATION_DIR
446 fi
447
448 install_device_node_setup "$VBOXDRV_GRP" "$VBOXDRV_MODE" "$INSTALLATION_DIR"
449
450 # Write the configuration. Do this before we call /etc/init.d/vboxdrv setup!
451 echo "# VirtualBox installation directory" > $CONFIG_DIR/$CONFIG
452 echo "INSTALL_DIR='$INSTALLATION_DIR'" >> $CONFIG_DIR/$CONFIG
453 echo "# VirtualBox version" >> $CONFIG_DIR/$CONFIG
454 echo "INSTALL_VER='$VERSION'" >> $CONFIG_DIR/$CONFIG
455 echo "INSTALL_REV='$SVNREV'" >> $CONFIG_DIR/$CONFIG
456
457 # Make kernel module
458 MODULE_FAILED="false"
459 if [ "$BUILD_MODULE" = "true" ]
460 then
461 info "Building the VirtualBox kernel modules"
462 log "Output from the module build process (the Linux kernel build system) follows:"
463 cur=`pwd`
464 log ""
465 setup_init_script vboxdrv
466 # Start VirtualBox kernel module
467 if [ $RETVAL -eq 0 ] && ! start_init_script vboxdrv; then
468 info "Failed to load the kernel module."
469 MODULE_FAILED="true"
470 RC_SCRIPT=1
471 fi
472 start_init_script vboxballoonctrl-service
473 start_init_script vboxweb-service
474 log ""
475 log "End of the output from the Linux kernel build system."
476 cd $cur
477 fi
478
479 info ""
480 if [ ! "$MODULE_FAILED" = "true" ]
481 then
482 info "VirtualBox has been installed successfully."
483 else
484 info "VirtualBox has been installed successfully, but the kernel module could not"
485 info "be built. When you have fixed the problems preventing this, execute"
486 info " /etc/init.d/vboxdrv setup"
487 info "as administrator to build it."
488 fi
489 info ""
490 info "You will find useful information about using VirtualBox in the user manual"
491 info " $INSTALLATION_DIR/UserManual.pdf"
492 info "and in the user FAQ"
493 info " http://www.virtualbox.org/wiki/User_FAQ"
494 info ""
495 info "We hope that you enjoy using VirtualBox."
496 info ""
497 log "Installation successful"
498elif [ "$ACTION" = "uninstall" ]; then
499 . ./uninstall.sh
500fi
501exit $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