VirtualBox

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

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