VirtualBox

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

Last change on this file since 103131 was 98681, checked in by vboxsync, 20 months ago

Installer/*: Similar adjustments for VBOX_WITH_WEBSERVICES. Fix for solaris typo two commits back. bugref:10030

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