VirtualBox

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

Last change on this file since 57940 was 57940, checked in by vboxsync, 10 years ago

Installers/linux: clean up the .run installer; remove legacy script; remove duplicate checks.

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

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