VirtualBox

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

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