VirtualBox

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

Last change on this file since 58097 was 58090, checked in by vboxsync, 9 years ago

Installers/linux: provide clean-up mechanism for upgrade hiccups from 5.0.4 and earlier to later versions.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use