VirtualBox

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

Last change on this file since 86782 was 84947, checked in by vboxsync, 4 years ago

/linux/Makefile*,++: BUILD_TYPE -> VBOX_KBUILD_TYPE; BUILD_TARGET_ARCH -> VBOX_KBUILD_TARGET_ARCH

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