VirtualBox

source: vbox/trunk/src/VBox/Installer/solaris/vboxconfig.sh@ 21845

Last change on this file since 21845 was 21775, checked in by vboxsync, 16 years ago

Solaris/Installer: vboxconfig.sh update.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1#!/bin/sh
2# $Id: vboxconfig.sh 21775 2009-07-23 12:01:01Z vboxsync $
3
4# Sun VirtualBox
5# VirtualBox Configuration Script, Solaris host.
6#
7# Copyright (C) 2009 Sun Microsystems, Inc.
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# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18# Clara, CA 95054 USA or visit http://www.sun.com if you need
19# additional information or have any questions.
20#
21
22
23HOST_OS_VERSION=`uname -r`
24BIN_ADDDRV=/usr/sbin/add_drv
25BIN_REMDRV=/usr/sbin/rem_drv
26BIN_MODLOAD=/usr/sbin/modload
27BIN_MODUNLOAD=/usr/sbin/modunload
28BIN_MODINFO=/usr/sbin/modinfo
29BIN_DEVFSADM=/usr/sbin/devfsadm
30BIN_BOOTADM=/sbin/bootadm
31BIN_IFCONFIG=/sbin/ifconfig
32
33# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
34MOD_VBOXDRV=vboxdrv
35MOD_VBOXNET=vboxnet
36MOD_VBOXFLT=vboxflt
37MOD_VBI=vbi
38MOD_VBOXUSBMON=vboxusbmon
39FATALOP=fatal
40
41MODDIR32="/platform/i86pc/kernel/drv"
42MODDIR64=$MODDIR32/amd64
43
44
45infoprint()
46{
47 echo 1>&2 "$1"
48}
49
50warnprint()
51{
52 echo 1>&2 "* Warning!! $1"
53}
54
55success()
56{
57 echo 1>&2 "$1"
58}
59
60error()
61{
62 echo 1>&2 "## $1"
63}
64
65# check_bin_path()
66# !! failure is always fatal
67check_bin_paths()
68{
69 if test -z "$1"; then
70 error "missing argument to check_bin_path()"
71 exit 50
72 fi
73
74 if test ! -x "$1"; then
75 error "$1 missing or is not an executable"
76 exit 51
77 fi
78 return 0
79}
80
81# check_root()
82# !! failure is always fatal
83check_root()
84{
85 idbin=/usr/xpg4/bin/id
86 if test ! -f "$idbin"; then
87 found=`which id`
88 if test ! -f "$found" || test ! -h "$found"; then
89 error "Failed to find a suitable user id binary."
90 exit 1
91 else
92 idbin=$found
93 fi
94 fi
95
96 if test `$idbin -u` -ne 0; then
97 error "This script must be run with administrator privileges."
98 exit 2
99 fi
100}
101
102# check_zone()
103# !! failure is always fatal
104check_zone()
105{
106 currentzone=`zonename`
107 if test "$currentzone" != "global"; then
108 error "This script must be run from the global zone."
109 exit 3
110 fi
111}
112
113# check_isa()
114# !! failure is always fatal
115check_isa()
116{
117 currentisa=`uname -i`
118 if test "$currentisa" = "i86xpv"; then
119 error "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
120 exit 4
121 fi
122}
123
124# check_module_arch()
125# !! failure is always fatal
126check_module_arch()
127{
128 cputype=`isainfo -k`
129 modulepath="$MODDIR32/$MOD_VBOXDRV"
130 if test "$cputype" = "amd64"; then
131 modulepath="$MODDIR64/$MOD_VBOXDRV"
132 elif test "$cputype" != "i386"; then
133 error "VirtualBox works only on i386/amd64 architectures, not $cputype"
134 exit 98
135 fi
136
137 # If things are where they should be, return success
138 if test -f "$modulepath" || test -h "$modulepath"; then
139 return 0
140 fi
141
142 # Something's screwed, let us go a step further and check if user has mixed up x86/amd64
143 # amd64 ISA, x86 kernel module??
144 if test "$cputype" = "amd64"; then
145 modulepath="$MODDIR32/$MOD_VBOXDRV"
146 if test -f "$modulepath"; then
147 error "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
148 exit 97
149 fi
150 else
151 # x86 ISA, amd64 kernel module??
152 modulepath="$MODDIR64/$MOD_VBOXDRV"
153 if test -f "$modulepath"; then
154 error "Found 64-bit module instead of 32-bit. Please install the x86 package!"
155 exit 96
156 fi
157 fi
158
159 # Shouldn't really happen...
160 error "VirtualBox Host kernel module NOT installed."
161 exit 99
162}
163
164# module_added(modname)
165# returns 0 if added, 1 otherwise
166module_added()
167{
168 if test -z "$1"; then
169 error "missing argument to module_added()"
170 exit 5
171 fi
172
173 loadentry=`cat /etc/name_to_major | grep $1`
174 if test -z "$loadentry"; then
175 return 0
176 fi
177 return 1
178}
179
180# module_loaded(modname)
181# returns 1 if loaded, 0 otherwise
182module_loaded()
183{
184 if test -z "$1"; then
185 error "missing argument to module_loaded()"
186 exit 6
187 fi
188
189 modname=$1
190 # modinfo should now work properly since we prevent module autounloading
191 loadentry=`$BIN_MODINFO | grep $modname`
192 if test -z "$loadentry"; then
193 return 0
194 fi
195 return 1
196}
197
198# add_driver(modname, [driverperm], [fatal])
199# failure: depends on [fatal]
200add_driver()
201{
202 if test -z "$1"; then
203 error "missing argument to add_driver()"
204 exit 7
205 fi
206
207 modname=$1
208 modperm=$2
209 fatal=$3
210 if test -n "$modperm"; then
211 $BIN_ADDDRV -m'$modperm' $modname
212 else
213 $BIN_ADDDRV $modname
214 fi
215
216 if test $? -ne 0; then
217 error "Failed to load: $modname"
218 if test "$fatal" = "$FATALOP"; then
219 exit 8
220 fi
221 return 1
222 fi
223 return 0
224}
225
226# rem_driver(modname, [fatal])
227# failure: depends on [fatal]
228rem_driver()
229{
230 if test -z "$1"; then
231 error "missing argument to rem_driver()"
232 exit 9
233 fi
234
235 modname=$1
236 fatal=$2
237 module_added $modname
238 if test "$?" -eq 0; then
239 $BIN_REMDRV $modname
240 if test $? -eq 0; then
241 success "Removed: $modname successfully"
242 return 0
243 else
244 error "Failed to remove: $modname"
245 if test "$fatal" = "$FATALOP"; then
246 exit 10
247 fi
248 return 1
249 fi
250 fi
251}
252
253# unload_module(modname, [fatal])
254# failure: fatal
255unload_module()
256{
257 if test -z "$1"; then
258 error "missing argument to unload_module()"
259 exit 11
260 fi
261
262 modname=$1
263 fatal=$2
264 modid=`$BIN_MODINFO | grep $modname | cut -f 1 -d ' ' `
265 if test -n "$modid"; then
266 $BIN_MODUNLOAD -i $modid
267 if test $? -eq 0; then
268 success "Unloaded: $modname successfully"
269 else
270 error "Failed to unload: $modname"
271 if test "$fatal" = "$FATALOP"; then
272 exit 12
273 fi
274 return 1
275 fi
276 fi
277 return 0
278}
279
280# load_module(modname)
281# pass "drv/modname" or "misc/vbi" etc.
282# failure: fatal
283load_module()
284{
285 if test -z "$1"; then
286 error "missing argument to load_module()"
287 exit 14
288 fi
289
290 modname=$1
291 fatal=$2
292 $BIN_MODLOAD -p $modname
293 if test $? -eq 0; then
294 success "Loaded: $modname successfully"
295 return 0
296 else
297 error "Failed to load: $modname"
298 if test "$fatal" = "$FATALOP"; then
299 exit 15
300 fi
301 return 1
302 fi
303}
304
305# install_drivers()
306# !! failure is always fatal
307install_drivers()
308{
309 infoprint "Loading Host Driver..."
310 add_driver $MOD_VBOXDRV "* 0600 root sys" fatal
311 load_module $MOD_VBOXDRV fatal
312
313 # Add vboxdrv to devlink.tab
314 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
315 echo "type=ddi_pseudo;name=vboxdrv \D" >> /etc/devlink.vbox
316 mv -f /etc/devlink.vbox /etc/devlink.tab
317
318 # Create the device link
319 /usr/sbin/devfsadm -i $MOD_VBOXDRV
320
321 if test $? -eq 0; then
322
323 if test -f /platform/i86pc/kernel/drv/vboxnet.conf; then
324 infoprint "Loading NetAdapter..."
325 add_drv $MOD_VBOXNET fatal
326 load_module $MOD_VBOXNET fatal
327 fi
328
329 if test -f /platform/i86pc/kernel/drv/vboxflt.conf; then
330 infoprint "Loading NetFilter..."
331 add_driver $MOD_VBOXFLT fatal
332 load_module $MOD_VBOXFLT fatal
333 fi
334
335 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
336 infoprint "Loading USBMonitor..."
337 add_driver $MOD_VBOXUSBMON fatal
338 load_module $MOD_VBOXUSBMON fatal
339
340 # Add vboxusbmon to devlink.tab
341 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
342 echo "type=ddi_pseudo;name=vboxusbmon \D" >> /etc/devlink.vbox
343
344 # Create the device link
345 /usr/sbin/devfsadm -i $MOD_VBOXUSBMON
346 if test $? -ne 0; then
347 error "Failed to create device link for $MOD_VBOXUSBMON."
348 exit 16
349 fi
350 fi
351 else
352 error "Failed to create device link for $MOD_VBOXDRV."
353 exit 17
354 fi
355
356 return $?
357}
358
359# remove_all([fatal])
360# failure: depends on [fatal]
361remove_drivers()
362{
363 $fatal=$1
364 # Remove vboxdrv from devlink.tab
365 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
366 mv -f /etc/devlink.vbox /etc/devlink.tab
367
368 # Remove vboxusbmon from devlink.tab
369 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
370 mv -f /etc/devlink.vbox /etc/devlink.tab
371
372 # USBMonitor might not even be installed, but anyway...
373 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
374 infoprint "Unloading USBMonitor..."
375 unload_module $MOD_VBOXUSBMON "$fatal"
376 rem_driver $MOD_VBOXUSBMON "$fatal"
377 fi
378
379 infoprint "Unloading NetFilter..."
380 unload_module $MOD_VBOXFLT "$fatal"
381 rem_driver $MOD_VBOXFLT "$fatal"
382
383 infoprint "Unloading NetAdapter..."
384 unload_module $MOD_VBOXNET "$fatal"
385 rem_driver $MOD_VBOXNET "$fatal"
386
387 infoprint "Unloading Host Driver..."
388 unload_module $MOD_VBOXDRV "$fatal"
389 rem_driver $MOD_VBOXDRV "$fatal"
390
391 infoprint "Unloading VBI..."
392 unload_module $MOD_VBI "$fatal"
393
394 return 0
395}
396
397
398# post_install()
399# !! failure is always fatal
400post_install()
401{
402 # @todo install_drivers, update boot-archive start services, patch_files, update boot archive
403 infoprint "Loading VirtualBox kernel modules..."
404 install_drivers
405
406 infoprint "Updating the boot archive..."
407 $BIN_BOOTADM update-archive > /dev/null
408
409 if test "$?" -eq 0; then
410
411 if test -f /platform/i86pc/kernel/drv/vboxnet.conf; then
412 # nwam/dhcpagent fix
413 nwamfile=/etc/nwam/llp
414 nwambackupfile=$nwamfile.vbox
415 if test -f "$nwamfile"; then
416 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
417 echo "vboxnet0 static 192.168.56.1" >> $nwambackupfile
418 mv -f $nwambackupfile $nwamfile
419 fi
420
421 # plumb and configure vboxnet0
422 $BIN_IFCONFIG vboxnet0 plumb up
423 if test "$?" -eq 0; then
424 $BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
425 else
426 warnprint "Failed to bring up vboxnet0!!"
427 fi
428 fi
429
430 return 0
431 else
432 error "Failed to update boot-archive"
433 exit 666
434 fi
435 return 1
436}
437
438# pre_remove([fatal])
439# failure: depends on [fatal]
440pre_remove()
441{
442 fatal=$1
443
444 # @todo halt services, remove_drivers, unpatch_files
445}
446
447
448# And it begins...
449check_root
450check_isa
451check_zone
452
453check_bin_path $BIN_ADDDRV
454check_bin_path $BIN_REMDRV
455check_bin_path $BIN_MODLOAD
456check_bin_path $BIN_MODUNLOAD
457check_bin_path $BIN_MODINFO
458check_bin_path $BIN_DEVFSADM
459check_bin_path $BIN_BOOTADM
460check_bin_path $BIN_IFCONFIG
461
462drvop=$1
463fatal=$2
464case "$drvop" in
465post_install)
466 check_module_arch
467 post_install
468 ;;
469pre_remove)
470 pre_remove "$fatal"
471 ;;
472install_drivers)
473 check_module_arch
474 install_drivers
475 ;;
476remove_drivers)
477 remove_drivers "$fatal"
478 ;;
479*)
480 echo "Usage: $0 post_install|pre_remove|install_drivers|remove_drivers [fatal]"
481 exit 13
482esac
483
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