VirtualBox

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

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

Solaris/Installer: vboxconfig.sh bits.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 KB
Line 
1#!/bin/sh
2# $Id: vboxconfig.sh 22067 2009-08-07 12:48:22Z 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`
24
25DIR_VBOXBASE=/opt/VirtualBox
26DIR_MOD_32="/platform/i86pc/kernel/drv"
27DIR_MOD_64=$DIR_MOD_32/amd64
28
29BIN_ADDDRV=/usr/sbin/add_drv
30BIN_REMDRV=/usr/sbin/rem_drv
31BIN_MODLOAD=/usr/sbin/modload
32BIN_MODUNLOAD=/usr/sbin/modunload
33BIN_MODINFO=/usr/sbin/modinfo
34BIN_DEVFSADM=/usr/sbin/devfsadm
35BIN_BOOTADM=/sbin/bootadm
36BIN_SVCADM=/usr/sbin/svcadm
37BIN_SVCCFG=/usr/sbin/svccfg
38BIN_IFCONFIG=/sbin/ifconfig
39
40# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
41MOD_VBOXDRV=vboxdrv
42MOD_VBOXNET=vboxnet
43MOD_VBOXFLT=vboxflt
44MOD_VBI=vbi
45MOD_VBOXUSBMON=vboxusbmon
46FATALOP=fatal
47
48
49infoprint()
50{
51 echo 1>&2 "$1"
52}
53
54warnprint()
55{
56 echo 1>&2 "* Warning!! $1"
57}
58
59success()
60{
61 echo 1>&2 "$1"
62}
63
64errorprint()
65{
66 echo 1>&2 "## $1"
67}
68
69
70# check_bin_path()
71# !! failure is always fatal
72check_bin_path()
73{
74 if test -z "$1"; then
75 errorprint "missing argument to check_bin_path()"
76 exit 50
77 fi
78
79 if test ! -x "$1"; then
80 errorprint "$1 missing or is not an executable"
81 exit 51
82 fi
83 return 0
84}
85
86# find_bins()
87# !! failure is always fatal
88find_bins()
89{
90 # Search only for binaries that might be in different locations
91 BIN_IFCONFIG=`which ifconfig 2> /dev/null`
92 BIN_SVCS=`which svcs 2> /dev/null`
93
94 check_bin_path "$BIN_ADDDRV"
95 check_bin_path "$BIN_REMDRV"
96 check_bin_path "$BIN_MODLOAD"
97 check_bin_path "$BIN_MODUNLOAD"
98 check_bin_path "$BIN_MODINFO"
99 check_bin_path "$BIN_DEVFSADM"
100 check_bin_path "$BIN_BOOTADM"
101 check_bin_path "$BIN_SVCADM"
102 check_bin_path "$BIN_SVCCFG"
103 check_bin_path "$BIN_SVCS"
104 check_bin_path "$BIN_IFCONFIG"
105}
106
107# check_root()
108# !! failure is always fatal
109check_root()
110{
111 idbin=/usr/xpg4/bin/id
112 if test ! -x "$idbin"; then
113 found=`which id`
114 if test ! -x "$found"; then
115 errorprint "Failed to find a suitable user id executable."
116 exit 1
117 else
118 idbin=$found
119 fi
120 fi
121
122 if test `$idbin -u` -ne 0; then
123 errorprint "This script must be run with administrator privileges."
124 exit 2
125 fi
126}
127
128# check_zone()
129# !! failure is always fatal
130check_zone()
131{
132 currentzone=`zonename`
133 if test "$currentzone" != "global"; then
134 errorprint "This script must be run from the global zone."
135 exit 3
136 fi
137}
138
139# check_isa()
140# !! failure is always fatal
141check_isa()
142{
143 currentisa=`uname -i`
144 if test "$currentisa" = "i86xpv"; then
145 errorprint "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
146 exit 4
147 fi
148}
149
150# check_module_arch()
151# !! failure is always fatal
152check_module_arch()
153{
154 cputype=`isainfo -k`
155 modulepath="$DIR_MOD_32/$MOD_VBOXDRV"
156 if test "$cputype" = "amd64"; then
157 modulepath="$DIR_MOD_64/$MOD_VBOXDRV"
158 elif test "$cputype" != "i386"; then
159 errorprint "VirtualBox works only on i386/amd64 architectures, not $cputype"
160 exit 98
161 fi
162
163 # If things are where they should be, return success
164 if test -f "$modulepath" || test -h "$modulepath"; then
165 return 0
166 fi
167
168 # Something's screwed, let us go a step further and check if user has mixed up x86/amd64
169 # amd64 ISA, x86 kernel module??
170 if test "$cputype" = "amd64"; then
171 modulepath="$DIR_MOD_32/$MOD_VBOXDRV"
172 if test -f "$modulepath"; then
173 errorprint "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
174 exit 97
175 fi
176 else
177 # x86 ISA, amd64 kernel module??
178 modulepath="$DIR_MOD_64/$MOD_VBOXDRV"
179 if test -f "$modulepath"; then
180 errorprint "Found 64-bit module instead of 32-bit. Please install the x86 package!"
181 exit 96
182 fi
183 fi
184
185 # Shouldn't really happen...
186 errorprint "VirtualBox Host kernel module NOT installed."
187 exit 99
188}
189
190# module_added(modname)
191# returns 0 if added, 1 otherwise
192module_added()
193{
194 if test -z "$1"; then
195 errorprint "missing argument to module_added()"
196 exit 5
197 fi
198
199 loadentry=`cat /etc/name_to_major | grep $1`
200 if test -z "$loadentry"; then
201 return 0
202 fi
203 return 1
204}
205
206# module_loaded(modname)
207# returns 1 if loaded, 0 otherwise
208module_loaded()
209{
210 if test -z "$1"; then
211 errorprint "missing argument to module_loaded()"
212 exit 6
213 fi
214
215 modname=$1
216 # modinfo should now work properly since we prevent module autounloading
217 loadentry=`$BIN_MODINFO | grep $modname`
218 if test -z "$loadentry"; then
219 return 0
220 fi
221 return 1
222}
223
224# add_driver(modname, [driverperm], [fatal])
225# failure: depends on [fatal]
226add_driver()
227{
228 if test -z "$1"; then
229 errorprint "missing argument to add_driver()"
230 exit 7
231 fi
232
233 modname=$1
234 modperm=$2
235 fatal=$3
236 if test -n "$modperm"; then
237 $BIN_ADDDRV -m'$modperm' $modname
238 else
239 $BIN_ADDDRV $modname
240 fi
241
242 if test $? -ne 0; then
243 errorprint "Failed to load: $modname"
244 if test "$fatal" = "$FATALOP"; then
245 exit 8
246 fi
247 return 1
248 fi
249 return 0
250}
251
252# rem_driver(modname, [fatal])
253# failure: depends on [fatal]
254rem_driver()
255{
256 if test -z "$1"; then
257 errorprint "missing argument to rem_driver()"
258 exit 9
259 fi
260
261 modname=$1
262 fatal=$2
263 module_added $modname
264 if test "$?" -eq 0; then
265 $BIN_REMDRV $modname
266 if test $? -eq 0; then
267 success "Removed: $modname successfully"
268 return 0
269 else
270 errorprint "Failed to remove: $modname"
271 if test "$fatal" = "$FATALOP"; then
272 exit 10
273 fi
274 return 1
275 fi
276 fi
277}
278
279# unload_module(modname, [fatal])
280# failure: fatal
281unload_module()
282{
283 if test -z "$1"; then
284 errorprint "missing argument to unload_module()"
285 exit 11
286 fi
287
288 modname=$1
289 fatal=$2
290 modid=`$BIN_MODINFO | grep $modname | cut -f 1 -d ' ' `
291 if test -n "$modid"; then
292 $BIN_MODUNLOAD -i $modid
293 if test $? -eq 0; then
294 success "Unloaded: $modname successfully"
295 else
296 errorprint "Failed to unload: $modname"
297 if test "$fatal" = "$FATALOP"; then
298 exit 12
299 fi
300 return 1
301 fi
302 fi
303 return 0
304}
305
306# load_module(modname)
307# pass "drv/modname" or "misc/vbi" etc.
308# failure: fatal
309load_module()
310{
311 if test -z "$1"; then
312 errorprint "missing argument to load_module()"
313 exit 14
314 fi
315
316 modname=$1
317 fatal=$2
318 $BIN_MODLOAD -p $modname
319 if test $? -eq 0; then
320 success "Loaded: $modname successfully"
321 return 0
322 else
323 errorprint "Failed to load: $modname"
324 if test "$fatal" = "$FATALOP"; then
325 exit 15
326 fi
327 return 1
328 fi
329}
330
331# install_drivers()
332# !! failure is always fatal
333install_drivers()
334{
335 infoprint "Loading Host Driver..."
336 add_driver $MOD_VBOXDRV "* 0600 root sys" fatal
337 load_module $MOD_VBOXDRV fatal
338
339 # Add vboxdrv to devlink.tab
340 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
341 echo "type=ddi_pseudo;name=vboxdrv \D" >> /etc/devlink.vbox
342 mv -f /etc/devlink.vbox /etc/devlink.tab
343
344 # Create the device link
345 /usr/sbin/devfsadm -i $MOD_VBOXDRV
346
347 if test $? -eq 0; then
348
349 if test -f /platform/i86pc/kernel/drv/vboxnet.conf; then
350 infoprint "Loading NetAdapter..."
351 add_drv $MOD_VBOXNET fatal
352 load_module $MOD_VBOXNET fatal
353 fi
354
355 if test -f /platform/i86pc/kernel/drv/vboxflt.conf; then
356 infoprint "Loading NetFilter..."
357 add_driver $MOD_VBOXFLT fatal
358 load_module $MOD_VBOXFLT fatal
359 fi
360
361 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
362 infoprint "Loading USBMonitor..."
363 add_driver $MOD_VBOXUSBMON fatal
364 load_module $MOD_VBOXUSBMON fatal
365
366 # Add vboxusbmon to devlink.tab
367 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
368 echo "type=ddi_pseudo;name=vboxusbmon \D" >> /etc/devlink.vbox
369
370 # Create the device link
371 /usr/sbin/devfsadm -i $MOD_VBOXUSBMON
372 if test $? -ne 0; then
373 errorprint "Failed to create device link for $MOD_VBOXUSBMON."
374 exit 16
375 fi
376 fi
377 else
378 errorprint "Failed to create device link for $MOD_VBOXDRV."
379 exit 17
380 fi
381
382 return $?
383}
384
385# remove_all([fatal])
386# failure: depends on [fatal]
387remove_drivers()
388{
389 $fatal=$1
390 # Remove vboxdrv from devlink.tab
391 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
392 mv -f /etc/devlink.vbox /etc/devlink.tab
393
394 # Remove vboxusbmon from devlink.tab
395 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
396 mv -f /etc/devlink.vbox /etc/devlink.tab
397
398 # USBMonitor might not even be installed, but anyway...
399 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
400 infoprint "Unloading USBMonitor..."
401 unload_module $MOD_VBOXUSBMON "$fatal"
402 rem_driver $MOD_VBOXUSBMON "$fatal"
403 fi
404
405 infoprint "Unloading NetFilter..."
406 unload_module $MOD_VBOXFLT "$fatal"
407 rem_driver $MOD_VBOXFLT "$fatal"
408
409 infoprint "Unloading NetAdapter..."
410 unload_module $MOD_VBOXNET "$fatal"
411 rem_driver $MOD_VBOXNET "$fatal"
412
413 infoprint "Unloading Host Driver..."
414 unload_module $MOD_VBOXDRV "$fatal"
415 rem_driver $MOD_VBOXDRV "$fatal"
416
417 infoprint "Unloading VBI..."
418 unload_module $MOD_VBI "$fatal"
419
420 return 0
421}
422
423# install_python_bindings(pythonbin)
424# remarks: changes pwd
425# failure: non fatal
426install_python_bindings()
427{
428 PYTHONBIN=$1
429 if test -x "$PYTHONBIN"; then
430 VBOX_INSTALL_PATH="$DIR_VBOXBASE"
431 export VBOX_INSTALL_PATH
432 cd $DIR_VBOXBASE/sdk/installer
433 $PYTHONBIN ./vboxapisetup.py install > /dev/null
434 return 0
435 fi
436 return 1
437}
438
439
440# cleanup_install([fatal])
441# failure: depends on [fatal]
442cleanup_install()
443{
444 fatal=$1
445
446 # stop and unregister webservice SMF
447 servicefound=`$BIN_SVCS -a | grep "virtualbox/webservice"`
448 if test ! -z "$servicefound"; then
449 $BIN_SVCADM disable -s svc:/application/virtualbox/webservice:default
450 $BIN_SVCCFG delete svc:/application/virtualbox/webservice:default
451 fi
452
453 # stop and unregister zoneaccess SMF
454 servicefound=`$BIN_SVCS -a | grep "virtualbox/zoneaccess"`
455 if test ! -z "$servicefound"; then
456 $BIN_SVCADM disable -s svc:/application/virtualbox/zoneaccess
457 $BIN_SVCCFG delete svc:/application/virtualbox/zoneaccess
458 fi
459
460 # unplumb vboxnet0
461 vboxnetup=`$BIN_IFCONFIG vboxnet0 >/dev/null 2>&1`
462 if test "$?" -eq 0; then
463 $BIN_IFCONFIG vboxnet0 unplumb
464 if test "$?" -ne 0; then
465 errorprint "VirtualBox NetAdapter 'vboxnet0' couldn't be unplumbed (probably in use)."
466 if test "$fatal" = "$FATALOP"; then
467 exit 33
468 fi
469 fi
470 fi
471}
472
473
474# post_install()
475# !! failure is always fatal
476post_install()
477{
478 infoprint "Loading VirtualBox kernel modules..."
479 install_drivers
480
481 if test "$?" -eq 0; then
482 if test -f /platform/i86pc/kernel/drv/vboxnet.conf; then
483 # nwam/dhcpagent fix
484 nwamfile=/etc/nwam/llp
485 nwambackupfile=$nwamfile.vbox
486 if test -f "$nwamfile"; then
487 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
488 echo "vboxnet0 static 192.168.56.1" >> $nwambackupfile
489 mv -f $nwambackupfile $nwamfile
490 fi
491
492 # plumb and configure vboxnet0
493 $BIN_IFCONFIG vboxnet0 plumb up
494 if test "$?" -eq 0; then
495 $BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
496 else
497 warnprint "Failed to bring up vboxnet0!!"
498 fi
499 fi
500
501 # Install python bindings
502 if test -f "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py" || test -h "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py"; then
503 PYTHONBIN=`which python 2> /dev/null`
504 if test -f "$PYTHONBIN" || test -h "$PYTHONBIN"; then
505 infoprint "Installing Python bindings..."
506
507 INSTALLEDIT=1
508 PYTHONBIN=`which python2.4 2>/dev/null`
509 install_python_bindings "$PYTHONBIN"
510 if test "$?" -eq 0; then
511 INSTALLEDIT=0
512 fi
513 PYTHONBIN=`which python2.5 2>/dev/null`
514 install_python_bindings "$PYTHONBIN"
515 if test "$?" -eq 0; then
516 INSTALLEDIT=0
517 fi
518 PYTHONBIN=`which python2.6 2>/dev/null`
519 install_python_bindings "$PYTHONBIN"
520 if test "$?" -eq 0; then
521 INSTALLEDIT=0
522 fi
523
524 # remove files installed by Python build
525 rm -rf $DIR_VBOXBASE/sdk/installer/build
526
527 if test "$INSTALLEDIT" -ne 0; then
528 warnprint "No suitable Python version found. Required Python 2.4, 2.5 or 2.6."
529 fi
530 else
531 warnprint "Python not found, skipped installed Python bindings."
532 fi
533 fi
534
535 # Update boot archive
536 infoprint "Updating the boot archive..."
537 $BIN_BOOTADM update-archive > /dev/null
538
539 return 0
540 else
541 errorprint "Failed to update boot-archive"
542 exit 666
543 fi
544 return 1
545}
546
547
548# pre_remove([fatal])
549# failure: depends on [fatal]
550pre_remove()
551{
552 fatal=$1
553
554 cleanup_install
555
556 remove_drivers "$fatal"
557 if test "$?" -eq 0; then
558 return 0;
559 fi
560 return 1
561}
562
563
564
565# And it begins...
566check_root
567check_isa
568check_zone
569find_bins
570
571drvop=$1
572fatal=$2
573case "$drvop" in
574post_install)
575 check_module_arch
576 post_install
577 ;;
578pre_remove)
579 pre_remove "$fatal"
580 ;;
581install_drivers)
582 check_module_arch
583 install_drivers
584 ;;
585remove_drivers)
586 remove_drivers "$fatal"
587 ;;
588*)
589 echo "Usage: $0 post_install|pre_remove|install_drivers|remove_drivers [fatal]"
590 exit 13
591esac
592
593if test "$?" -eq 0; then
594 exit 0
595fi
596
597exit 1
598
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