VirtualBox

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

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

Installer/Linux: bugref:9049: Support for split GUI functionality.

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 14.9 KB
 
1#!/bin/sh
2#
3# Oracle VM VirtualBox
4# VirtualBox linux installation script
5
6#
7# Copyright (C) 2007-2017 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.alldomusa.eu.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
18# Testing:
19# * After successful installation, 0 is returned if the vboxdrv module version
20# built matches the one loaded.
21# * If the kernel modules cannot be built (run the installer with KERN_VER=none)
22# or loaded (run with KERN_VER=<installed non-current version>)
23# then 1 is returned.
24
25PATH=$PATH:/bin:/sbin:/usr/sbin
26
27# Include routines and utilities needed by the installer
28. ./routines.sh
29
30LOG="/var/log/vbox-install.log"
31VERSION="_VERSION_"
32SVNREV="_SVNREV_"
33BUILD="_BUILD_"
34ARCH="_ARCH_"
35HARDENED="_HARDENED_"
36GUI_WITH_SHARED_LIBRARY="_GUI_WITH_SHARED_LIBRARY_"
37# The "BUILD_" prefixes prevent the variables from being overwritten when we
38# read the configuration from the previous installation.
39BUILD_BUILDTYPE="_BUILDTYPE_"
40BUILD_USERNAME="_USERNAME_"
41CONFIG_DIR="/etc/vbox"
42CONFIG="vbox.cfg"
43CONFIG_FILES="filelist"
44DEFAULT_FILES=`pwd`/deffiles
45GROUPNAME="vboxusers"
46INSTALLATION_DIR="_INSTALLATION_DIR_"
47LICENSE_ACCEPTED=""
48PREV_INSTALLATION=""
49PYTHON="_PYTHON_"
50ACTION=""
51SELF=$1
52RC_SCRIPT=0
53if [ -n "$HARDENED" ]; then
54 VBOXDRV_MODE=0600
55 VBOXDRV_GRP="root"
56else
57 VBOXDRV_MODE=0660
58 VBOXDRV_GRP=$GROUPNAME
59fi
60VBOXUSB_MODE=0664
61VBOXUSB_GRP=$GROUPNAME
62
63## Were we able to stop any previously running Additions kernel modules?
64MODULES_STOPPED=1
65
66
67##############################################################################
68# Helper routines #
69##############################################################################
70
71usage() {
72 info ""
73 info "Usage: install | uninstall"
74 info ""
75 info "Example:"
76 info "$SELF install"
77 exit 1
78}
79
80module_loaded() {
81 lsmod | grep -q "vboxdrv[^_-]"
82}
83
84# This routine makes sure that there is no previous installation of
85# VirtualBox other than one installed using this install script or a
86# compatible method. We do this by checking for any of the VirtualBox
87# applications in /usr/bin. If these exist and are not symlinks into
88# the installation directory, then we assume that they are from an
89# incompatible previous installation.
90
91## Helper routine: test for a particular VirtualBox binary and see if it
92## is a link into a previous installation directory
93##
94## Arguments: 1) the binary to search for and
95## 2) the installation directory (if any)
96## Returns: false if an incompatible version was detected, true otherwise
97check_binary() {
98 binary=$1
99 install_dir=$2
100 test ! -e $binary 2>&1 > /dev/null ||
101 ( test -n "$install_dir" &&
102 readlink $binary 2>/dev/null | grep "$install_dir" > /dev/null
103 )
104}
105
106## Main routine
107##
108## Argument: the directory where the previous installation should be
109## located. If this is empty, then we will assume that any
110## installation of VirtualBox found is incompatible with this one.
111## Returns: false if an incompatible installation was found, true otherwise
112check_previous() {
113 install_dir=$1
114 # These should all be symlinks into the installation folder
115 check_binary "/usr/bin/VirtualBox" "$install_dir" &&
116 check_binary "/usr/bin/VBoxManage" "$install_dir" &&
117 check_binary "/usr/bin/VBoxSDL" "$install_dir" &&
118 check_binary "/usr/bin/VBoxVRDP" "$install_dir" &&
119 check_binary "/usr/bin/VBoxHeadless" "$install_dir" &&
120 check_binary "/usr/bin/VBoxDTrace" "$install_dir" &&
121 check_binary "/usr/bin/VBoxBugReport" "$install_dir" &&
122 check_binary "/usr/bin/VBoxBalloonCtrl" "$install_dir" &&
123 check_binary "/usr/bin/VBoxAutostart" "$install_dir" &&
124 check_binary "/usr/bin/vboxwebsrv" "$install_dir" &&
125 check_binary "/usr/bin/vbox-img" "$install_dir" &&
126 check_binary "/sbin/rcvboxdrv" "$install_dir"
127}
128
129##############################################################################
130# Main script #
131##############################################################################
132
133info "VirtualBox Version $VERSION r$SVNREV ($BUILD) installer"
134
135
136# Make sure that we were invoked as root...
137check_root
138
139# Set up logging before anything else
140create_log $LOG
141
142log "VirtualBox $VERSION r$SVNREV installer, built $BUILD."
143log ""
144log "Testing system setup..."
145
146# Sanity check: figure out whether build arch matches uname arch
147cpu=`uname -m`;
148case "$cpu" in
149 i[3456789]86|x86)
150 cpu="x86"
151 ;;
152 x86_64)
153 cpu="amd64"
154 ;;
155esac
156if [ "$cpu" != "$ARCH" ]; then
157 info "Detected unsupported $cpu environment."
158 log "Detected unsupported $cpu environment."
159 exit 1
160fi
161
162# Sensible default actions
163ACTION="install"
164BUILD_MODULE="true"
165while true
166do
167 if [ "$2" = "" ]; then
168 break
169 fi
170 shift
171 case "$1" in
172 install)
173 ACTION="install"
174 ;;
175
176 uninstall)
177 ACTION="uninstall"
178 ;;
179
180 force)
181 FORCE_UPGRADE=1
182 ;;
183 license_accepted_unconditionally)
184 # Legacy option
185 ;;
186 no_module)
187 BUILD_MODULE=""
188 ;;
189 *)
190 if [ "$ACTION" = "" ]; then
191 info "Unknown command '$1'."
192 usage
193 fi
194 info "Specifying an installation path is not allowed -- using _INSTALLATION_DIR_!"
195 ;;
196 esac
197done
198
199if [ "$ACTION" = "install" ]; then
200 # Choose a proper umask
201 umask 022
202
203 # Find previous installation
204 if test -r "$CONFIG_DIR/$CONFIG"; then
205 . $CONFIG_DIR/$CONFIG
206 PREV_INSTALLATION=$INSTALL_DIR
207 fi
208 if ! check_previous $INSTALL_DIR
209 then
210 info
211 info "You appear to have a version of VirtualBox on your system which was installed"
212 info "from a different source or using a different type of installer (or a damaged"
213 info "installation of VirtualBox). We strongly recommend that you remove it before"
214 info "installing this version of VirtualBox."
215 info
216 info "Do you wish to continue anyway? [yes or no]"
217 read reply dummy
218 if ! expr "$reply" : [yY] && ! expr "$reply" : [yY][eE][sS]
219 then
220 info
221 info "Cancelling installation."
222 log "User requested cancellation of the installation"
223 exit 1
224 fi
225 fi
226
227 # Do additional clean-up in case some-one is running from a build folder.
228 ./prerm-common.sh || exit 1
229
230 # Remove previous installation
231 test "${BUILD_MODULE}" = true || VBOX_DONT_REMOVE_OLD_MODULES=1
232
233 if [ -n "$PREV_INSTALLATION" ]; then
234 [ -n "$INSTALL_REV" ] && INSTALL_REV=" r$INSTALL_REV"
235 info "Removing previous installation of VirtualBox $INSTALL_VER$INSTALL_REV from $PREV_INSTALLATION"
236 log "Removing previous installation of VirtualBox $INSTALL_VER$INSTALL_REV from $PREV_INSTALLATION"
237 log ""
238
239 VBOX_NO_UNINSTALL_MESSAGE=1
240 # This also checks $BUILD_MODULE and $VBOX_DONT_REMOVE_OLD_MODULES
241 . ./uninstall.sh
242 fi
243
244 mkdir -p -m 755 $CONFIG_DIR
245 touch $CONFIG_DIR/$CONFIG
246
247 info "Installing VirtualBox to $INSTALLATION_DIR"
248 log "Installing VirtualBox to $INSTALLATION_DIR"
249 log ""
250
251 # Verify the archive
252 mkdir -p -m 755 $INSTALLATION_DIR
253 bzip2 -d -c VirtualBox.tar.bz2 > VirtualBox.tar
254 if ! tar -tf VirtualBox.tar > $CONFIG_DIR/$CONFIG_FILES; then
255 rmdir $INSTALLATION_DIR 2> /dev/null
256 rm -f $CONFIG_DIR/$CONFIG 2> /dev/null
257 rm -f $CONFIG_DIR/$CONFIG_FILES 2> /dev/null
258 log 'Error running "bzip2 -d -c VirtualBox.tar.bz2" or "tar -tf VirtualBox.tar".'
259 abort "Error installing VirtualBox. Installation aborted"
260 fi
261
262 # Create installation directory and install
263 if ! tar -xf VirtualBox.tar -C $INSTALLATION_DIR; then
264 cwd=`pwd`
265 cd $INSTALLATION_DIR
266 rm -f `cat $CONFIG_DIR/$CONFIG_FILES` 2> /dev/null
267 cd $pwd
268 rmdir $INSTALLATION_DIR 2> /dev/null
269 rm -f $CONFIG_DIR/$CONFIG 2> /dev/null
270 log 'Error running "tar -xf VirtualBox.tar -C '"$INSTALLATION_DIR"'".'
271 abort "Error installing VirtualBox. Installation aborted"
272 fi
273
274 cp uninstall.sh $INSTALLATION_DIR
275 echo "uninstall.sh" >> $CONFIG_DIR/$CONFIG_FILES
276
277 # Hardened build: Mark selected binaries set-user-ID-on-execution,
278 # create symlinks for working around unsupported $ORIGIN/.. in VBoxC.so (setuid),
279 # and finally make sure the directory is only writable by the user (paranoid).
280 if [ -n "$HARDENED" ]; then
281 if [ -n "$GUI_WITH_SHARED_LIBRARY" ]; then
282 test -e $INSTALLATION_DIR/VirtualBoxVM && chmod 4511 $INSTALLATION_DIR/VirtualBoxVM
283 else
284 test -e $INSTALLATION_DIR/VirtualBox && chmod 4511 $INSTALLATION_DIR/VirtualBox
285 fi
286 test -e $INSTALLATION_DIR/VBoxSDL && chmod 4511 $INSTALLATION_DIR/VBoxSDL
287 test -e $INSTALLATION_DIR/VBoxHeadless && chmod 4511 $INSTALLATION_DIR/VBoxHeadless
288 test -e $INSTALLATION_DIR/VBoxNetDHCP && chmod 4511 $INSTALLATION_DIR/VBoxNetDHCP
289 test -e $INSTALLATION_DIR/VBoxNetNAT && chmod 4511 $INSTALLATION_DIR/VBoxNetNAT
290
291 ln -sf $INSTALLATION_DIR/VBoxVMM.so $INSTALLATION_DIR/components/VBoxVMM.so
292 ln -sf $INSTALLATION_DIR/VBoxRT.so $INSTALLATION_DIR/components/VBoxRT.so
293
294 chmod go-w $INSTALLATION_DIR
295 fi
296
297 # This binaries need to be suid root in any case, even if not hardened
298 test -e $INSTALLATION_DIR/VBoxNetAdpCtl && chmod 4511 $INSTALLATION_DIR/VBoxNetAdpCtl
299 test -e $INSTALLATION_DIR/VBoxVolInfo && chmod 4511 $INSTALLATION_DIR/VBoxVolInfo
300
301 # Write the configuration. Needs to be done before the vboxdrv service is
302 # started.
303 echo "# VirtualBox installation directory" > $CONFIG_DIR/$CONFIG
304 echo "INSTALL_DIR='$INSTALLATION_DIR'" >> $CONFIG_DIR/$CONFIG
305 echo "# VirtualBox version" >> $CONFIG_DIR/$CONFIG
306 echo "INSTALL_VER='$VERSION'" >> $CONFIG_DIR/$CONFIG
307 echo "INSTALL_REV='$SVNREV'" >> $CONFIG_DIR/$CONFIG
308 echo "# Build type and user name for logging purposes" >> $CONFIG_DIR/$CONFIG
309 echo "BUILD_TYPE='$BUILD_BUILDTYPE'" >> $CONFIG_DIR/$CONFIG
310 echo "USERNAME='$BUILD_USERNAME'" >> $CONFIG_DIR/$CONFIG
311
312 # Create users group
313 groupadd -r -f $GROUPNAME 2> /dev/null
314
315 # Create symlinks to start binaries
316 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VirtualBox
317 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxManage
318 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxSDL
319 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxVRDP
320 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxHeadless
321 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxBalloonCtrl
322 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxBugReport
323 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxAutostart
324 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/vboxwebsrv
325 ln -sf $INSTALLATION_DIR/vbox-img /usr/bin/vbox-img
326 ln -sf $INSTALLATION_DIR/VBox.png /usr/share/pixmaps/VBox.png
327 if [ -f $INSTALLATION_DIR/VBoxDTrace ]; then
328 ln -sf $INSTALLATION_DIR/VBox.sh /usr/bin/VBoxDTrace
329 fi
330 # Unity and Nautilus seem to look here for their icons
331 ln -sf $INSTALLATION_DIR/icons/128x128/virtualbox.png /usr/share/pixmaps/virtualbox.png
332 ln -sf $INSTALLATION_DIR/virtualbox.desktop /usr/share/applications/virtualbox.desktop
333 ln -sf $INSTALLATION_DIR/virtualbox.xml /usr/share/mime/packages/virtualbox.xml
334 ln -sf $INSTALLATION_DIR/rdesktop-vrdp /usr/bin/rdesktop-vrdp
335 ln -sf $INSTALLATION_DIR/src/vboxhost /usr/src/vboxhost-_VERSION_
336
337 # Convenience symlinks. The creation fails if the FS is not case sensitive
338 ln -sf VirtualBox /usr/bin/virtualbox > /dev/null 2>&1
339 ln -sf VBoxManage /usr/bin/vboxmanage > /dev/null 2>&1
340 ln -sf VBoxSDL /usr/bin/vboxsdl > /dev/null 2>&1
341 ln -sf VBoxHeadless /usr/bin/vboxheadless > /dev/null 2>&1
342 ln -sf VBoxBugReport /usr/bin/vboxbugreport > /dev/null 2>&1
343 if [ -f $INSTALLATION_DIR/VBoxDTrace ]; then
344 ln -sf VBoxDTrace /usr/bin/vboxdtrace > /dev/null 2>&1
345 fi
346
347 # Create legacy symlinks if necesary for Qt5/xcb stuff.
348 if [ -d $INSTALLATION_DIR/legacy ]; then
349 if ! /sbin/ldconfig -p | grep -q "\<libxcb\.so\.1\>"; then
350 for f in `ls -1 $INSTALLATION_DIR/legacy/`; do
351 ln -s $INSTALLATION_DIR/legacy/$f $INSTALLATION_DIR/$f
352 echo $INSTALLATION_DIR/$f >> $CONFIG_DIR/$CONFIG_FILES
353 done
354 fi
355 fi
356
357 # Icons
358 cur=`pwd`
359 cd $INSTALLATION_DIR/icons
360 for i in *; do
361 cd $i
362 if [ -d /usr/share/icons/hicolor/$i ]; then
363 for j in *; do
364 if expr "$j" : "virtualbox\..*" > /dev/null; then
365 dst=apps
366 else
367 dst=mimetypes
368 fi
369 if [ -d /usr/share/icons/hicolor/$i/$dst ]; then
370 ln -s $INSTALLATION_DIR/icons/$i/$j /usr/share/icons/hicolor/$i/$dst/$j
371 echo /usr/share/icons/hicolor/$i/$dst/$j >> $CONFIG_DIR/$CONFIG_FILES
372 fi
373 done
374 fi
375 cd -
376 done
377 cd $cur
378
379 # Update the MIME database
380 update-mime-database /usr/share/mime 2>/dev/null
381
382 # Update the desktop database
383 update-desktop-database -q 2>/dev/null
384
385 # If Python is available, install Python bindings
386 if [ -n "$PYTHON" ]; then
387 maybe_run_python_bindings_installer $INSTALLATION_DIR $CONFIG_DIR $CONFIG_FILES
388 fi
389
390 # Do post-installation common to all installer types, currently service
391 # script set-up.
392 if test "${BUILD_MODULE}" = "true"; then
393 START_SERVICES=
394 else
395 START_SERVICES="--nostart"
396 fi
397 "${INSTALLATION_DIR}/prerm-common.sh" >> "${LOG}"
398
399 # Now check whether the kernel modules were stopped.
400 lsmod | grep -q vboxdrv && MODULES_STOPPED=
401
402 "${INSTALLATION_DIR}/postinst-common.sh" ${START_SERVICES} >> "${LOG}"
403
404 info ""
405 info "VirtualBox has been installed successfully."
406 info ""
407 info "You will find useful information about using VirtualBox in the user manual"
408 info " $INSTALLATION_DIR/UserManual.pdf"
409 info "and in the user FAQ"
410 info " http://www.alldomusa.eu.org/wiki/User_FAQ"
411 info ""
412 info "We hope that you enjoy using VirtualBox."
413 info ""
414
415 # And do a final test as to whether the kernel modules were properly created
416 # and loaded. Return 0 if both are true, 1 if not.
417 test -n "${MODULES_STOPPED}" &&
418 modinfo vboxdrv >/dev/null 2>&1 &&
419 lsmod | grep -q vboxdrv ||
420 abort "The installation log file is at ${LOG}."
421
422 log "Installation successful"
423elif [ "$ACTION" = "uninstall" ]; then
424 . ./uninstall.sh
425fi
426exit $RC_SCRIPT
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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