VirtualBox

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

最後變更 在這個檔案從31638是 31638,由 vboxsync 提交於 15 年 前

Linux installer: export some files

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

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