VirtualBox

Ticket #758: install.sh

File install.sh, 11.9 KB (added by John Gnew, 17 years ago)

install.sh

Line 
1#!/bin/sh
2#
3# innotek VirtualBox
4# VirtualBox Guest Additions installation script for Linux
5
6#
7# Copyright (C) 2006-2007 innotek GmbH
8#
9# innotek GmbH confidential
10# All rights reserved
11
12PATH=$PATH:/bin:/sbin:/usr/sbin
13
14. ./routines.sh
15
16# Find the version of X installed
17x_version=$(X -version 2>&1 | sed -n 's/^X Window System Version \([0-9.]\+\)/\1/p')$(X -version 2>&1 | sed -n 's/^XFree86 Version \([0-9.]\+\)/\1/p')
18
19build_test_module() {
20 # Build a test module and try to load it
21 log "Building a test kernel module..."
22 log ""
23 if ! make --no-print-directory -C module/test >> $LOG 2>&1; then
24 info "Building a test kernel module failed. See the log file $LOG"
25 info "for more details."
26 log ""
27 log "Building the test kernel module failed."
28 return 1
29 else
30 if [ -f module/test/vboxadd_test.ko ]; then
31 test_module="module/test/vboxadd_test.ko"
32 else
33 test_module="module/test/vboxadd_test.o"
34 fi
35 if [ -f $test_module ]; then
36 log "Inserting the test module $test_module into the kernel."
37 insmod $test_module >> $LOG 2>&1
38 lsmod_line=`lsmod | grep vboxadd_test`
39 kernel_name=`expr "$lsmod_line" : '\([^ ]*\)'`
40 if [ "$kernel_name" = "" ]; then
41 info "Unable to insert a test module into your Linux kernel. This may be because"
42 info "the kernel was built with a different version of GCC to the one which is"
43 info "currently installed, or because the kernel header files are incorrectly"
44 info "installed. The command 'dmesg' may provide you with more information."
45 log "Failed to insert the test module."
46 return 1
47 else
48 rmmod $kernel_name > /dev/null 2>&1
49 make -C module/test clean > /dev/null 2>&1
50 fi
51 else
52 info "Building a test kernel module failed. The log file $LOG may provide more"
53 info "information."
54 log "Could not find the test kernel module we just built."
55 return 1
56 fi
57 fi
58 return 0
59}
60
61LOG="/var/log/vboxadd-install.log"
62VERSION="1.5.0"
63BUILD="Mon Sep 3 17:32:26 CEST 2007"
64OSE=""
65
66info "VirtualBox $VERSION Guest Additions installation"
67
68check_root
69
70# Initialise logging before all else
71create_log $LOG
72log "Installing VirtualBox $VERSION Guest Additions, built $BUILD"
73log ""
74
75# Parse arguments
76install_vfs=""
77install_clipboard=""
78install_timesync=""
79install_xdrivers=""
80if [ "$1" = "" ]; then
81 install_vfs="yes"
82 install_clipboard="yes"
83 install_timesync="yes"
84 install_xdrivers="yes"
85fi
86while [ ! -z "$1" ]; do
87 case "$1" in
88 kernel-module)
89 # Nothing to do - we install this whatever happens.
90 ;;
91 vfs-module)
92 install_vfs="yes"
93 ;;
94 timesync)
95 install_timesync="yes"
96 ;;
97 x11)
98 install_xdrivers="yes"
99 ;;
100 clipboard)
101 install_clipboard="yes"
102 ;;
103 all)
104 install_vfs="yes"
105 install_timesync="yes"
106 install_xdrivers="yes"
107 ;;
108 help)
109 info "Usage: sh VBoxLinuxAdditions.run <options...>"
110 info
111 info "The following options are recognized:"
112 info
113 info " all -- install all components of the Guest Additions"
114 info " kernel-module -- only install the core components in the Linux kernel"
115 info " vfs-module -- install the shared folder component"
116 info " timesync -- install the time synchronisation component"
117 info " x11 -- install guest drivers for the X Window System"
118 info
119 info "If you do not specify any options, all components will be installed."
120 info "Components which you do not install will be deactivated if they are already"
121 info "present in order to prevent possible problems due to mixing different versions"
122 info "of the Additions."
123 exit 1
124 ;;
125 *)
126 info "The option $1 is not known. You can use any of the following options:"
127 info
128 info " all -- install all components of the Guest Additions"
129 info " kernel-module -- only install the core components in the Linux kernel"
130 info " vfs-module -- install the shared folder component"
131 info " timesync -- install the time synchronisation component"
132 info " x11 -- install guest drivers for the X Window System"
133 info
134 info "If you do not specify any options, all components will be installed."
135 info "Components which you do not install will be deactivated if they are already"
136 info "present in order to prevent possible problems due to mixing different versions"
137 info "of the Additions."
138 exit 1
139 ;;
140 esac
141 shift
142done
143
144# Check that all the tools we need are available
145log "Testing the setup of the guest system"
146log ""
147
148have_gmake="`check_gmake; echo $?`" # Do we have GNU make?
149have_ksource="`check_ksource; echo $?`" # Can we find the kernel source?
150have_gcc="`check_gcc; echo $?`" # Is GCC installed?
151
152if [ ! "$install_xdrivers" = "" ]; then
153 perl_ok="`check_perl; echo $?`" # Is perl installed?
154else
155 perl_ok="-1" # We don't need it in this case.
156fi # we are installing the X11 drivers
157
158test_build=1
159if [ $have_gmake -eq 0 -a $have_ksource -eq 0 -a $have_gcc -eq 0 ]; then
160 test_build="`build_test_module; echo $?`" # Can we build a working kernel module?
161fi # no problems with GCC, Make or the kernel headers missing
162
163if [ $perl_ok -eq 1 -o $test_build -eq 1 ]; then
164 info "Problems were found which would prevent the Guest Additions from installing."
165 info "Please correct these problems and try again."
166 log "Giving up due to the problems mentioned above."
167 exit 1
168fi
169
170# Make kernel module
171# What the **** is this for? I took it from the old Makefile.
172pathdown_sh=/lib/modules/`uname -r`/build/scripts/pathdown.sh
173if [ -f $pathdown_sh -a ! -x $pathdown_sh ]; then
174 chmod +x $pathdown_sh
175fi
176log ""
177log "Building the VirtualBox Guest Additions kernel module."
178log ""
179echo "Building the VirtualBox Guest Additions kernel module..." 1>&2
180if ! module/vboxadd/build_in_tmp \
181 --save-module-symvers /var/log/vboxadd-Module.symvers \
182 --no-print-directory install >> $LOG 2>&1
183then
184 info "Unable to build the kernel module. See the log file $LOG"
185 info "for more details."
186 exit 1
187fi
188if [ ! "$install_vfs" = "" ]; then
189 log ""
190 log "Building the shared folder support kernel module."
191 log ""
192 echo "Building the shared folder support kernel module..." 1>&2
193 if ! module/vboxvfs/build_in_tmp \
194 --use-module-symvers /var/log/vboxadd-Module.symvers \
195 --no-print-directory install >> $LOG 2>&1
196 then
197 info "Unable to build the kernel module. See the log file $LOG"
198 info "for more details."
199 exit 1
200 fi
201fi
202
203# Remove previous installations
204mod_path=/lib/modules/`uname -r`
205find $mod_path -name vboxadd\* | grep -v $mod_path/misc/vboxadd | xargs rm 2> /dev/null
206find $mod_path -name vboxvfs\* | grep -v $mod_path/misc/vboxvfs | xargs rm 2> /dev/null
207# Get rid of empty directories to which we have installed in the past
208rmdir -p $mod_path/misc 2> /dev/null
209rmdir -p $mod_path/kernel/misc 2> /dev/null
210rmdir -p $mod_path/kernel/drivers/vbox 2> /dev/null
211rmdir -p $mod_path/drivers/vbox 2> /dev/null
212
213# Install scripts and binary drivers
214info "Installing the VirtualBox Guest Additions..."
215info ""
216install_init_script vboxadd.sh vboxadd
217log "Installing the Guest Additions kernel module system service."
218if ! addrunlevel vboxadd 1 99; then
219 info "Unable to install Guest Additions kernel module system service."
220 log "Failed."
221 exit 1
222fi
223if [ "$install_vfs" = "" ]; then
224 # make sure that no old version of the shared folder support is running
225 delrunlevel vboxvfs 2 98 > /dev/null 2>&1
226else
227 log "Installing the shared folder system service."
228 install_init_script vboxvfs.sh vboxvfs
229 if ! addrunlevel vboxvfs 2 98; then
230 info "Unable to install the shared folder system service."
231 log "Failed."
232 exit 1
233 fi
234 install -o 0 -g 0 -m 0755 mount.vboxsf /sbin/mount.vboxsf
235fi
236if [ "$install_timesync" = "" ]; then
237 # make sure that no old version of the time synchronisation support is running
238 delrunlevel vboxadd-timesync 2 98 > /dev/null 2>&1
239else
240 log "Installing the time synchronisation system service."
241 install -o 0 -g 0 -m 0755 vboxadd-timesync /usr/sbin/vboxadd-timesync
242 install_init_script vboxadd-timesync.sh vboxadd-timesync
243 if ! addrunlevel vboxadd-timesync 2 98; then
244 info "Unable to install the time synchronisation system service."
245 log "Failed."
246 exit 1
247 fi
248fi
249if [ "$install_clipboard" != "" ]; then
250 log "Installing the shared clipboard user service."
251 install -o 0 -g 0 -m 04755 vboxadd-xclient /usr/bin/vboxadd-xclient
252 if [ ! -z "$x_version" ]; then
253 install_x11_startup_app 98vboxadd-xclient "shared clipboard"
254 else
255 if [ "$install_xdrivers" = "" ]; then
256 # If the X drivers are to be installed then the user will be told that X is not there
257 # anyway
258 info "Could not find XFree86 or Xorg on your guest system. The shared clipboard"
259 info "will not be set up"
260 fi
261 log "X11 not found - not setting up the service"
262 fi
263fi
264
265# Create udev description file
266if [ -d /etc/udev/rules.d ]; then
267 log "Creating udev rule for the Guest Additions kernel module."
268 udev_out=`udevinfo -V 2> /dev/null`
269 if [ "$udev_out" = "" ]; then
270 udev_ver=1
271 else
272 udev_ver=`expr "$udev_out" : '[^0-9]*\([0-9]*\)'`
273 fi
274 if [ "$udev_ver" -lt 55 ]; then
275 echo "KERNEL=\"vboxadd\", NAME=\"vboxadd\", OWNER=\"root\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
276 else
277 echo "KERNEL==\"vboxadd\", NAME=\"vboxadd\", OWNER=\"root\", MODE=\"0660\"" > /etc/udev/rules.d/60-vboxadd.rules
278 fi
279fi
280
281depmod
282
283# Install the X Window drivers
284if [ ! "$install_xdrivers" = "" ]; then
285 log "Installing the X Window System drivers"
286
287 for dir in /usr/lib/X11/modules /usr/X11R6/lib/modules; do
288 if [ -d $dir ]; then
289 modules_dir=$dir
290 break
291 fi
292 done
293
294 if [ -z "$x_version" -o -z "$modules_dir" ]; then
295 info "Could not find X.org or XFree86 on the guest system. The X Window drivers"
296 info "will not be installed."
297 log "Could not find either x.org (/usr/lib/xorg) or XFree86 (/usr/X11R6/lib) on"
298 log " the guest system."
299 exit 1
300 fi
301
302 case $x_version in
303 6.9.* | 7.0.* )
304 install -o 0 -g 0 -m 0644 vboxvideo_drv_70.so $modules_dir/drivers/vboxvideo_drv.so
305 install -o 0 -g 0 -m 0644 vboxmouse_drv_70.so $modules_dir/input/vboxmouse_drv.so
306 ;;
307 7.1.* | 7.2.* )
308 install -o 0 -g 0 -m 0644 vboxvideo_drv_71.so $modules_dir/drivers/vboxvideo_drv.so
309 install -o 0 -g 0 -m 0644 vboxmouse_drv_71.so $modules_dir/input/vboxmouse_drv.so
310 ;;
311 1.3.* )
312 # Xorg have started using the server version number instead of
313 # the release version.
314 install -o 0 -g 0 -m 0644 vboxvideo_drv_13.so $modules_dir/drivers/vboxvideo_drv.so
315 install -o 0 -g 0 -m 0644 vboxmouse_drv_71.so $modules_dir/input/vboxmouse_drv.so
316 ;;
317 * )
318 # Assume X.Org 6.8.x or XFree86
319 install -o 0 -g 0 -m 0644 vboxvideo_drv.o $modules_dir/drivers/vboxvideo_drv.o
320 install -o 0 -g 0 -m 0644 vboxmouse_drv.o $modules_dir/input/vboxmouse_drv.o
321 ;;
322 esac
323 ./x11config.pl >> $LOG 2>&1
324fi # Install the X11 drivers
325
326info "Successfully installed the VirtualBox Guest Additions."
327info "You must restart your guest system in order to complete the installation."
328log ""
329log "Successfully completed."
330log ""

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy