VirtualBox

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

Last change on this file since 37338 was 37338, checked in by vboxsync, 14 years ago

Solaris/Installer: Install netbow driver changes.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 29.0 KB
Line 
1#!/bin/sh
2# $Id: vboxconfig.sh 37338 2011-06-07 09:20:50Z vboxsync $
3
4#
5# VirtualBox Configuration Script, Solaris host.
6#
7# Copyright (C) 2009-2010 Oracle Corporation
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
18# Never use exit 2 or exit 20 etc., the return codes are used in
19# SRv4 postinstall procedures which carry special meaning. Just use exit 1 for failure.
20
21# S10 or OpenSoalris
22HOST_OS_MAJORVERSION=`uname -r`
23# Which OpenSolaris version (snv_xxx or oi_xxx)?
24HOST_OS_MINORVERSION=`uname -v | egrep 'snv|oi' | sed -e "s/snv_//" -e "s/oi_//" -e "s/[^0-9]//"`
25
26DIR_VBOXBASE="$PKG_INSTALL_ROOT/opt/VirtualBox"
27DIR_CONF="$PKG_INSTALL_ROOT/platform/i86pc/kernel/drv"
28DIR_MOD_32="$PKG_INSTALL_ROOT/platform/i86pc/kernel/drv"
29DIR_MOD_64="$DIR_MOD_32/amd64"
30
31# Default paths, these will be overridden by 'which' if they don't exist
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
42BIN_SVCS=/usr/bin/svcs
43BIN_ID=/usr/bin/id
44BIN_PKILL=/usr/bin/pkill
45
46# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
47MOD_VBOXDRV=vboxdrv
48DESC_VBOXDRV="Host"
49
50MOD_VBOXNET=vboxnet
51DESC_VBOXNET="NetAdapter"
52MOD_VBOXNET_INST=32
53
54MOD_VBOXFLT=vboxflt
55DESC_VBOXFLT="NetFilter (STREAMS)"
56
57MOD_VBOXBOW=vboxbow
58DESC_VBOXBOW="NetFilter (Crossbow)"
59
60# No Separate VBI since (3.1)
61#MOD_VBI=vbi
62#DESC_VBI="Kernel Interface"
63
64MOD_VBOXUSBMON=vboxusbmon
65DESC_VBOXUSBMON="USBMonitor"
66
67MOD_VBOXUSB=vboxusb
68DESC_VBOXUSB="USB"
69
70REMOTEINST=0
71FATALOP=fatal
72NULLOP=nulloutput
73SILENTOP=silent
74IPSOP=ips
75ISSILENT=
76ISIPS=
77
78infoprint()
79{
80 if test "$ISSILENT" != "$SILENTOP"; then
81 echo 1>&2 "$1"
82 fi
83}
84
85subprint()
86{
87 if test "$ISSILENT" != "$SILENTOP"; then
88 echo 1>&2 " - $1"
89 fi
90}
91
92warnprint()
93{
94 if test "$ISSILENT" != "$SILENTOP"; then
95 echo 1>&2 " * Warning!! $1"
96 fi
97}
98
99errorprint()
100{
101 echo 1>&2 "## $1"
102}
103
104helpprint()
105{
106 echo 1>&2 "$1"
107}
108
109printusage()
110{
111 helpprint "VirtualBox Configuration Script"
112 helpprint "usage: $0 <operation> [options]"
113 helpprint
114 helpprint "<operation> must be one of the following:"
115 helpprint " --postinstall Perform full post installation procedure"
116 helpprint " --preremove Perform full pre remove procedure"
117 helpprint " --installdrivers Only install the drivers"
118 helpprint " --removedrivers Only remove the drivers"
119 helpprint " --setupdrivers Setup drivers, reloads existing drivers"
120 helpprint
121 helpprint "[options] are one or more of the following:"
122 helpprint " --silent Silent mode"
123 helpprint " --fatal Don't continue on failure (required for postinstall)"
124 helpprint " --ips This is an IPS package postinstall/preremove"
125 helpprint " --altkerndir Use /usr/kernel/drv as the driver directory"
126 helpprint
127}
128
129# find_bin_path()
130# !! failure is always fatal
131find_bin_path()
132{
133 if test -z "$1"; then
134 errorprint "missing argument to find_bin_path()"
135 exit 1
136 fi
137
138 binfilename=`basename $1`
139 binfilepath=`which $binfilename 2> /dev/null`
140 if test -x "$binfilepath"; then
141 echo "$binfilepath"
142 return 0
143 else
144 errorprint "$1 missing or is not an executable"
145 exit 1
146 fi
147}
148
149# find_bins()
150# !! failure is always fatal
151find_bins()
152{
153 # Search only for binaries that might be in different locations
154 if test ! -x "$BIN_ID"; then
155 BIN_ID=`find_bin_path "$BIN_ID"`
156 fi
157
158 if test ! -x "$BIN_ADDDRV"; then
159 BIN_ADDDRV=`find_bin_path "$BIN_ADDDRV"`
160 fi
161
162 if test ! -x "$BIN_REMDRV"; then
163 BIN_REMDRV=`find_bin_path "$BIN_REMDRV"`
164 fi
165
166 if test ! -x "$BIN_MODLOAD"; then
167 BIN_MODLOAD=`check_bin_path "$BIN_MODLOAD"`
168 fi
169
170 if test ! -x "$BIN_MODUNLOAD"; then
171 BIN_MODUNLOAD=`find_bin_path "$BIN_MODUNLOAD"`
172 fi
173
174 if test ! -x "$BIN_MODINFO"; then
175 BIN_MODINFO=`find_bin_path "$BIN_MODINFO"`
176 fi
177
178 if test ! -x "$BIN_DEVFSADM"; then
179 BIN_DEVFSADM=`find_bin_path "$BIN_DEVFSADM"`
180 fi
181
182 if test ! -x "$BIN_BOOTADM"; then
183 BIN_BOOTADM=`find_bin_path "$BIN_BOOTADM"`
184 fi
185
186 if test ! -x "$BIN_SVCADM"; then
187 BIN_SVCADM=`find_bin_path "$BIN_SVCADM"`
188 fi
189
190 if test ! -x "$BIN_SVCCFG"; then
191 BIN_SVCCFG=`find_bin_path "$BIN_SVCCFG"`
192 fi
193
194 if test ! -x "$BIN_SVCS"; then
195 BIN_SVCS=`find_bin_path "$BIN_SVCS"`
196 fi
197
198 if test ! -x "$BIN_IFCONFIG"; then
199 BIN_IFCONFIG=`find_bin_path "$BIN_IFCONFIG"`
200 fi
201
202 if test ! -x "$BIN_PKILL"; then
203 BIN_PKILL=`find_bin_path "$BIN_PKILL"`
204 fi
205}
206
207# check_root()
208# !! failure is always fatal
209check_root()
210{
211 # Don't use "-u" option as some id binaries don't support it, instead
212 # rely on "uid=101(username) gid=10(groupname) groups=10(staff)" output
213 curuid=`$BIN_ID | cut -f 2 -d '=' | cut -f 1 -d '('`
214 if test "$curuid" -ne 0; then
215 errorprint "This script must be run with administrator privileges."
216 exit 1
217 fi
218}
219
220# get_sysinfo
221# cannot fail
222get_sysinfo()
223{
224 if test "$REMOTEINST" -eq 1 || test -z "$HOST_OS_MINORVERSION" || test -z "$HOST_OS_MAJORVERSION"; then
225 if test -f "$PKG_INSTALL_ROOT/etc/release"; then
226 HOST_OS_MAJORVERSION=`cat $PKG_INSTALL_ROOT/etc/release | grep "Solaris 10"`
227 if test -n "$HOST_OS_MAJORVERSION"; then
228 HOST_OS_MAJORVERSION="5.10"
229 else
230 HOST_OS_MAJORVERSION=`cat $PKG_INSTALL_ROOT/etc/release | egrep "snv_|oi_"`
231 if test -n "$HOST_OS_MAJORVERSION"; then
232 HOST_OS_MAJORVERSION="5.11"
233 fi
234 fi
235 if test "$HOST_OS_MAJORVERSION" != "5.10"; then
236 HOST_OS_MINORVERSION=`cat $PKG_INSTALL_ROOT/etc/release | tr ' ' '\n' | egrep 'snv_|oi_' | sed -e "s/snv_//" -e "s/oi_//" -e "s/[^0-9]//"`
237 else
238 HOST_OS_MINORVERSION=""
239 fi
240 else
241 HOST_OS_MAJORVERSION=""
242 HOST_OS_MINORVERSION=""
243 fi
244 fi
245}
246
247# check_zone()
248# !! failure is always fatal
249check_zone()
250{
251 currentzone=`zonename`
252 if test "$currentzone" != "global"; then
253 errorprint "This script must be run from the global zone."
254 exit 1
255 fi
256}
257
258# check_isa()
259# !! failure is always fatal
260check_isa()
261{
262 currentisa=`uname -i`
263 if test "$currentisa" = "i86xpv"; then
264 errorprint "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
265 exit 1
266 fi
267}
268
269# check_module_arch()
270# !! failure is always fatal
271check_module_arch()
272{
273 cputype=`isainfo -k`
274 if test "$cputype" != "amd64" && test "$cputype" != "i386"; then
275 errorprint "VirtualBox works only on i386/amd64 hosts, not $cputype"
276 exit 1
277 fi
278}
279
280# module_added(modname)
281# returns 1 if added, 0 otherwise
282module_added()
283{
284 if test -z "$1"; then
285 errorprint "missing argument to module_added()"
286 exit 1
287 fi
288
289 # Add a space at end of module name to make sure we have a perfect match to avoid
290 # any substring matches: e.g "vboxusb" & "vboxusbmon"
291 loadentry=`cat $PKG_INSTALL_ROOT/etc/name_to_major | grep "$1 "`
292 if test -z "$loadentry"; then
293 return 1
294 fi
295 return 0
296}
297
298# module_loaded(modname)
299# returns 1 if loaded, 0 otherwise
300module_loaded()
301{
302 if test -z "$1"; then
303 errorprint "missing argument to module_loaded()"
304 exit 1
305 fi
306
307 modname=$1
308 # modinfo should now work properly since we prevent module autounloading.
309 loadentry=`$BIN_MODINFO | grep "$modname "`
310 if test -z "$loadentry"; then
311 return 1
312 fi
313 return 0
314}
315
316# add_driver(modname, moddesc, fatal, nulloutput, [driverperm])
317# failure: depends on "fatal"
318add_driver()
319{
320 if test -z "$1" || test -z "$2"; then
321 errorprint "missing argument to add_driver()"
322 exit 1
323 fi
324
325 modname="$1"
326 moddesc="$2"
327 fatal="$3"
328 nullop="$4"
329 modperm="$5"
330
331 if test -n "$modperm"; then
332 if test "$nullop" = "$NULLOP"; then
333 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname >/dev/null 2>&1
334 else
335 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname
336 fi
337 else
338 if test "$nullop" = "$NULLOP"; then
339 $BIN_ADDDRV $BASEDIR_OPT $modname >/dev/null 2>&1
340 else
341 $BIN_ADDDRV $BASEDIR_OPT $modname
342 fi
343 fi
344
345 if test $? -ne 0; then
346 subprint "Adding: $moddesc module ...FAILED!"
347 if test "$fatal" = "$FATALOP"; then
348 exit 1
349 fi
350 return 1
351 elif test "$REMOTEINST" -eq 1 && test "$?" -eq 0; then
352 subprint "Added: $moddesc driver"
353 fi
354 return 0
355}
356
357# rem_driver(modname, moddesc, [fatal])
358# failure: depends on [fatal]
359rem_driver()
360{
361 if test -z "$1" || test -z "$2"; then
362 errorprint "missing argument to rem_driver()"
363 exit 1
364 fi
365
366 modname=$1
367 moddesc=$2
368 fatal=$3
369
370 module_added $modname
371 if test "$?" -eq 0; then
372 if test "$ISIPS" != "$IPSOP"; then
373 $BIN_REMDRV $BASEDIR_OPT $modname
374 else
375 $BIN_REMDRV $BASEDIR_OPT $modname >/dev/null 2>&1
376 fi
377 # for remote installs, don't bother with return values of rem_drv
378 if test $? -eq 0; then
379 subprint "Removed: $moddesc module"
380 return 0
381 else
382 subprint "Removing: $moddesc ...FAILED!"
383 if test "$fatal" = "$FATALOP"; then
384 exit 1
385 fi
386 return 1
387 fi
388 fi
389}
390
391# unload_module(modname, moddesc, [fatal])
392# failure: fatal
393unload_module()
394{
395 if test -z "$1" || test -z "$2"; then
396 errorprint "missing argument to unload_module()"
397 exit 1
398 fi
399
400 # No-OP for non-root installs
401 if test "$REMOTEINST" -eq 1; then
402 return 0
403 fi
404
405 modname=$1
406 moddesc=$2
407 fatal=$3
408 modid=`$BIN_MODINFO | grep "$modname " | cut -f 1 -d ' ' `
409 if test -n "$modid"; then
410 $BIN_MODUNLOAD -i $modid
411 if test $? -eq 0; then
412 subprint "Unloaded: $moddesc module"
413 else
414 subprint "Unloading: $moddesc module ...FAILED!"
415 if test "$fatal" = "$FATALOP"; then
416 exit 1
417 fi
418 return 1
419 fi
420 fi
421 return 0
422}
423
424# load_module(modname, moddesc, [fatal])
425# pass "drv/modname" or "misc/vbi" etc.
426# failure: fatal
427load_module()
428{
429 if test -z "$1" || test -z "$2"; then
430 errorprint "missing argument to load_module()"
431 exit 1
432 fi
433
434 # No-OP for non-root installs
435 if test "$REMOTEINST" -eq 1; then
436 return 0
437 fi
438
439 modname=$1
440 moddesc=$2
441 fatal=$3
442 $BIN_MODLOAD -p $modname
443 if test $? -eq 0; then
444 subprint "Loaded: $moddesc module"
445 return 0
446 else
447 subprint "Loading: $moddesc ...FAILED!"
448 if test "$fatal" = "$FATALOP"; then
449 exit 1
450 fi
451 return 1
452 fi
453}
454
455# install_drivers()
456# !! failure is always fatal
457install_drivers()
458{
459 if test -f "$DIR_CONF/vboxdrv.conf"; then
460 if test -n "_HARDENED_"; then
461 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0600 root sys'"
462 else
463 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
464 fi
465 load_module "drv/$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP"
466 else
467 errorprint "Extreme error! Missing $DIR_CONF/vboxdrv.conf, aborting."
468 return 1
469 fi
470
471 # Add vboxdrv to devlink.tab
472 if test -f "$PKG_INSTALL_ROOT/etc/devlink.tab"; then
473 sed -e '/name=vboxdrv/d' $PKG_INSTALL_ROOT/etc/devlink.tab > $PKG_INSTALL_ROOT/etc/devlink.vbox
474 echo "type=ddi_pseudo;name=vboxdrv \D" >> $PKG_INSTALL_ROOT/etc/devlink.vbox
475 mv -f $PKG_INSTALL_ROOT/etc/devlink.vbox $PKG_INSTALL_ROOT/etc/devlink.tab
476 else
477 errorprint "Missing $PKG_INSTALL_ROOT/etc/devlink.tab, aborting install"
478 return 1
479 fi
480
481 # Create the device link for non-remote installs
482 if test "$REMOTEINST" -eq 0; then
483 /usr/sbin/devfsadm -i "$MOD_VBOXDRV"
484 if test $? -ne 0 || test ! -h "/dev/vboxdrv"; then
485 errorprint "Failed to create device link for $MOD_VBOXDRV."
486 exit 1
487 fi
488 fi
489
490 # Load VBoxNetAdp
491 if test -f "$DIR_CONF/vboxnet.conf"; then
492 add_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
493 load_module "drv/$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
494 fi
495
496 # If "/etc/vboxinst_vboxflt" exists or if host is Solaris 10 or S11 versions < snv_159 then load vboxflt driver.
497 if test -f /etc/vboxinst_vboxflt || test "$HOST_OS_MAJORVERSION" = "5.10" || test "$HOST_OS_MINORVERSION" -lt 159 || test ! -f "$DIR_CONF/vboxbow.conf"; then
498 # Load VBoxNetFlt
499 if test -f "$DIR_CONF/vboxflt.conf"; then
500 add_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
501 load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
502 fi
503 else
504 # Load VBoxNetBow
505 if test -f "$DIR_CONF/vboxbow.conf"; then
506 add_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
507 load_module "drv/$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
508 fi
509 fi
510
511 # Load VBoxUSBMon, VBoxUSB
512 if test -f "$DIR_CONF/vboxusbmon.conf" && test "$HOST_OS_MAJORVERSION" != "5.10"; then
513 # For VirtualBox 3.1 the new USB code requires Nevada > 123
514 if test "$HOST_OS_MINORVERSION" -gt 123; then
515 add_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
516 load_module "drv/$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP"
517
518 # Add vboxusbmon to devlink.tab
519 sed -e '/name=vboxusbmon/d' $PKG_INSTALL_ROOT/etc/devlink.tab > $PKG_INSTALL_ROOT/etc/devlink.vbox
520 echo "type=ddi_pseudo;name=vboxusbmon \D" >> $PKG_INSTALL_ROOT/etc/devlink.vbox
521 mv -f $PKG_INSTALL_ROOT/etc/devlink.vbox $PKG_INSTALL_ROOT/etc/devlink.tab
522
523 # Create the device link for non-remote installs
524 if test "$REMOTEINST" -eq 0; then
525 /usr/sbin/devfsadm -i "$MOD_VBOXUSBMON"
526 if test $? -ne 0; then
527 errorprint "Failed to create device link for $MOD_VBOXUSBMON."
528 exit 1
529 fi
530 fi
531
532 # Add vboxusb if present
533 # This driver is special, we need it in the boot-archive but since there is no
534 # USB device to attach to now (it's done at runtime) it will fail to attach so
535 # redirect attaching failure output to /dev/null
536 if test -f "$DIR_CONF/vboxusb.conf"; then
537 add_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP" "$NULLOP"
538 load_module "drv/$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP"
539 fi
540 else
541 if test -n "$HOST_OS_MINORVERSION"; then
542 warnprint "Solaris 5.11 build 124 or higher required for USB support. Skipped installing USB support."
543 else
544 warnprint "Failed to determine Solaris 5.11 snv version. Skipped installing USB support."
545 fi
546 fi
547 fi
548
549 return $?
550}
551
552# remove_drivers([fatal])
553# failure: depends on [fatal]
554remove_drivers()
555{
556 fatal=$1
557
558 # Remove vboxdrv from devlink.tab
559 if test -f $PKG_INSTALL_ROOT/etc/devlink.tab; then
560 devlinkfound=`cat $PKG_INSTALL_ROOT/etc/devlink.tab | grep vboxdrv`
561 if test -n "$devlinkfound"; then
562 sed -e '/name=vboxdrv/d' $PKG_INSTALL_ROOT/etc/devlink.tab > $PKG_INSTALL_ROOT/etc/devlink.vbox
563 mv -f $PKG_INSTALL_ROOT/etc/devlink.vbox $PKG_INSTALL_ROOT/etc/devlink.tab
564 fi
565
566 # Remove vboxusbmon from devlink.tab
567 devlinkfound=`cat $PKG_INSTALL_ROOT/etc/devlink.tab | grep vboxusbmon`
568 if test -n "$devlinkfound"; then
569 sed -e '/name=vboxusbmon/d' $PKG_INSTALL_ROOT/etc/devlink.tab > $PKG_INSTALL_ROOT/etc/devlink.vbox
570 mv -f $PKG_INSTALL_ROOT/etc/devlink.vbox $PKG_INSTALL_ROOT/etc/devlink.tab
571 fi
572 fi
573
574 unload_module "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$fatal"
575 rem_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$fatal"
576
577 unload_module "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$fatal"
578 rem_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$fatal"
579
580 unload_module "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$fatal"
581 rem_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$fatal"
582
583 unload_module "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$fatal"
584 rem_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$fatal"
585
586 unload_module "$MOD_VBOXNET" "$DESC_VBOXNET" "$fatal"
587 rem_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$fatal"
588
589 unload_module "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$fatal"
590 rem_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$fatal"
591
592# No separate VBI since 3.1
593# unload_module "$MOD_VBI" "$DESC_VBI" "$fatal"
594
595 # remove devlinks
596 if test -h "$PKG_INSTALL_ROOT/dev/vboxdrv" || test -f "$PKG_INSTALL_ROOT/dev/vboxdrv"; then
597 rm -f $PKG_INSTALL_ROOT/dev/vboxdrv
598 fi
599 if test -h "$PKG_INSTALL_ROOT/dev/vboxusbmon" || test -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"; then
600 rm -f $PKG_INSTALL_ROOT/dev/vboxusbmon
601 fi
602
603 # unpatch nwam/dhcpagent fix
604 nwamfile=$PKG_INSTALL_ROOT/etc/nwam/llp
605 nwambackupfile=$nwamfile.vbox
606 if test -f "$nwamfile"; then
607 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
608 mv -f $nwambackupfile $nwamfile
609 fi
610
611 # remove netmask configuration
612 nmaskfile=$PKG_INSTALL_ROOT/etc/netmasks
613 nmaskbackupfile=$nmaskfile.vbox
614 if test -f "$nmaskfile"; then
615 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
616 mv -f $nmaskbackupfile $nmaskfile
617 fi
618
619 return 0
620}
621
622# install_python_bindings(pythonbin)
623# remarks: changes pwd
624# failure: non fatal
625install_python_bindings()
626{
627 # The python binary might not be there, so just exit silently
628 if test -z "$1"; then
629 return 0
630 fi
631
632 if test -z "$2"; then
633 errorprint "missing argument to install_python_bindings"
634 exit 1
635 fi
636
637 pythonbin=$1
638 pythondesc=$2
639 if test -x "$pythonbin"; then
640 VBOX_INSTALL_PATH="$DIR_VBOXBASE"
641 export VBOX_INSTALL_PATH
642 cd $DIR_VBOXBASE/sdk/installer
643 $pythonbin ./vboxapisetup.py install > /dev/null
644 if test "$?" -eq 0; then
645 subprint "Installed: Bindings for $pythondesc"
646 fi
647 return 0
648 fi
649 return 1
650}
651
652# stop_process(processname)
653# failure: depends on [fatal]
654stop_process()
655{
656 if test -z "$1"; then
657 errorprint "missing argument to stop_process()"
658 exit 1
659 fi
660
661 procname=$1
662 procpid=`ps -eo pid,fname | grep $procname | grep -v grep | awk '{ print $1 }'`
663 if test ! -z "$procpid" && test "$procpid" -ge 0; then
664 $BIN_PKILL "$procname"
665 sleep 2
666 procpid=`ps -eo pid,fname | grep $procname | grep -v grep | awk '{ print $1 }'`
667 if test ! -z "$procpid" && test "$procpid" -ge 0; then
668 subprint "Terminating: $procname ...FAILED!"
669 if test "$fatal" = "$FATALOP"; then
670 exit 1
671 fi
672 else
673 subprint "Terminated: $procname"
674 fi
675 fi
676}
677
678
679# stop_service(servicename, shortFMRI-suitable for grep, full FMRI)
680# failure: non fatal
681stop_service()
682{
683 if test -z "$1" || test -z "$2" || test -z "$3"; then
684 errorprint "missing argument to stop_service()"
685 exit 1
686 fi
687 servicefound=`$BIN_SVCS -a | grep "$2" 2>/dev/null`
688 if test ! -z "$servicefound"; then
689 $BIN_SVCADM disable -s $3
690 # Don't delete the manifest, this is handled by the manifest class action
691 # $BIN_SVCCFG delete $3
692 if test "$?" -eq 0; then
693 subprint "Unloaded: $1"
694 else
695 subprint "Unloading: $1 ...ERROR(S)."
696 fi
697 fi
698}
699
700
701# cleanup_install([fatal])
702# failure: depends on [fatal]
703cleanup_install()
704{
705 fatal=$1
706
707 # No-Op for remote installs
708 if test "$REMOTEINST" -eq 1; then
709 return 0
710 fi
711
712 # stop the services
713 stop_service "Web service" "virtualbox/webservice" "svc:/application/virtualbox/webservice:default"
714 stop_service "Balloon control service" "virtualbox/balloonctrl" "svc:/application/virtualbox/balloonctrl:default"
715 stop_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default"
716
717 # unplumb all vboxnet instances for non-remote installs
718 inst=0
719 while test $inst -ne $MOD_VBOXNET_INST; do
720 vboxnetup=`$BIN_IFCONFIG vboxnet$inst >/dev/null 2>&1`
721 if test "$?" -eq 0; then
722 $BIN_IFCONFIG vboxnet$inst unplumb
723 if test "$?" -ne 0; then
724 errorprint "VirtualBox NetAdapter 'vboxnet$inst' couldn't be unplumbed (probably in use)."
725 if test "$fatal" = "$FATALOP"; then
726 exit 1
727 fi
728 fi
729 fi
730
731 # unplumb vboxnet0 ipv6
732 vboxnetup=`$BIN_IFCONFIG vboxnet$inst inet6 >/dev/null 2>&1`
733 if test "$?" -eq 0; then
734 $BIN_IFCONFIG vboxnet$inst inet6 unplumb
735 if test "$?" -ne 0; then
736 errorprint "VirtualBox NetAdapter 'vboxnet$inst' IPv6 couldn't be unplumbed (probably in use)."
737 if test "$fatal" = "$FATALOP"; then
738 exit 1
739 fi
740 fi
741 fi
742
743 inst=`expr $inst + 1`
744 done
745
746 # Stop our other daemons, non-fatal
747 stop_process VBoxSVC
748 stop_process VBoxNetDHCP
749}
750
751
752# postinstall()
753# !! failure is always fatal
754postinstall()
755{
756 infoprint "Loading VirtualBox kernel modules..."
757 install_drivers
758
759 if test "$?" -eq 0; then
760 if test -f "$DIR_CONF/vboxnet.conf"; then
761 # nwam/dhcpagent fix
762 nwamfile=$PKG_INSTALL_ROOT/etc/nwam/llp
763 nwambackupfile=$nwamfile.vbox
764 if test -f "$nwamfile"; then
765 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
766
767 # add all vboxnet instances as static to nwam
768 inst=0
769 networkn=56
770 while test $inst -ne 1; do
771 echo "vboxnet$inst static 192.168.$networkn.1" >> $nwambackupfile
772 inst=`expr $inst + 1`
773 networkn=`expr $networkn + 1`
774 done
775 mv -f $nwambackupfile $nwamfile
776 fi
777
778 # plumb and configure vboxnet0 for non-remote installs
779 if test "$REMOTEINST" -eq 0; then
780 $BIN_IFCONFIG vboxnet0 plumb up
781 if test "$?" -eq 0; then
782 $BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
783
784 # add the netmask to stay persistent across host reboots
785 nmaskfile=$PKG_INSTALL_ROOT/etc/netmasks
786 nmaskbackupfile=$nmaskfile.vbox
787 if test -f $nmaskfile; then
788 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
789 echo "#VirtualBox_SectionStart" >> $nmaskbackupfile
790 inst=0
791 networkn=56
792 while test $inst -ne 1; do
793 echo "192.168.$networkn.0 255.255.255.0" >> $nmaskbackupfile
794 inst=`expr $inst + 1`
795 networkn=`expr $networkn + 1`
796 done
797 echo "#VirtualBox_SectionEnd" >> $nmaskbackupfile
798 mv -f $nmaskbackupfile $nmaskfile
799 fi
800 else
801 # Should this be fatal?
802 warnprint "Failed to bring up vboxnet0!!"
803 fi
804 fi
805 fi
806
807 if test -f $PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml || test -f $PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml; then
808 infoprint "Configuring services..."
809 if test "$REMOTEINST" -eq 1; then
810 subprint "Skipped for targetted installs."
811 else
812 # Enable Zone access service for non-remote installs, other services (Webservice) are delivered disabled by the manifest class action
813 servicefound=`$BIN_SVCS -a | grep "virtualbox/zoneaccess" | grep "disabled" 2>/dev/null`
814 if test ! -z "$servicefound"; then
815 /usr/sbin/svcadm enable -s svc:/application/virtualbox/zoneaccess
816 if test "$?" -eq 0; then
817 subprint "Loaded: Zone access service"
818 else
819 subprint "Loading Zone access service ...FAILED."
820 fi
821 fi
822 fi
823 fi
824
825 # Update mime and desktop databases to get the right menu entries
826 # and icons. There is still some delay until the GUI picks it up,
827 # but that cannot be helped.
828 if test -d $PKG_INSTALL_ROOT/usr/share/icons; then
829 infoprint "Installing MIME types and icons..."
830 if test "$REMOTEINST" -eq 0; then
831 /usr/bin/update-mime-database /usr/share/mime >/dev/null 2>&1
832 /usr/bin/update-desktop-database -q 2>/dev/null
833 else
834 subprint "Skipped for targetted installs."
835 fi
836 fi
837
838 # Install python bindings for non-remote installs
839 if test "$REMOTEINST" -eq 0; then
840 if test -f "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py" || test -h "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py"; then
841 PYTHONBIN=`which python 2> /dev/null`
842 if test -f "$PYTHONBIN" || test -h "$PYTHONBIN"; then
843 infoprint "Installing Python bindings..."
844
845 INSTALLEDIT=1
846 PYTHONBIN=`which python2.4 2>/dev/null`
847 install_python_bindings "$PYTHONBIN" "Python 2.4"
848 if test "$?" -eq 0; then
849 INSTALLEDIT=0
850 fi
851 PYTHONBIN=`which python2.5 2>/dev/null`
852 install_python_bindings "$PYTHONBIN" "Python 2.5"
853 if test "$?" -eq 0; then
854 INSTALLEDIT=0
855 fi
856 PYTHONBIN=`which python2.6 2>/dev/null`
857 install_python_bindings "$PYTHONBIN" "Python 2.6"
858 if test "$?" -eq 0; then
859 INSTALLEDIT=0
860 fi
861
862 # remove files installed by Python build
863 rm -rf $DIR_VBOXBASE/sdk/installer/build
864
865 if test "$INSTALLEDIT" -ne 0; then
866 warnprint "No suitable Python version found. Required Python 2.4, 2.5 or 2.6."
867 warnprint "Skipped installing the Python bindings."
868 fi
869 else
870 warnprint "Python not found, skipped installed Python bindings."
871 fi
872 fi
873 else
874 warnprint "Skipped installing Python bindings. Run, as root, 'vboxapisetup.py install' manually from the booted system."
875 fi
876
877 # Update boot archive
878 infoprint "Updating the boot archive..."
879 if test "$REMOTEINST" -eq 0; then
880 $BIN_BOOTADM update-archive > /dev/null
881 else
882 $BIN_BOOTADM update-archive -R $PKG_INSTALL_ROOT > /dev/null
883 fi
884
885 return 0
886 else
887 errorprint "Failed to install drivers"
888 exit 666
889 fi
890 return 1
891}
892
893# preremove([fatal])
894# failure: depends on [fatal]
895preremove()
896{
897 fatal=$1
898
899 cleanup_install "$fatal"
900
901 remove_drivers "$fatal"
902 if test "$?" -eq 0; then
903 return 0;
904 fi
905 return 1
906}
907
908
909
910# And it begins...
911find_bins
912check_root
913check_isa
914check_zone
915get_sysinfo
916
917if test "x${PKG_INSTALL_ROOT:=/}" != "x/"; then
918 BASEDIR_OPT="-b $PKG_INSTALL_ROOT"
919 REMOTEINST=1
920fi
921
922# Get command line options
923while test $# -gt 0;
924do
925 case "$1" in
926 --postinstall | --preremove | --installdrivers | --removedrivers | --setupdrivers)
927 drvop="$1"
928 ;;
929 --fatal)
930 fatal="$FATALOP"
931 ;;
932 --silent)
933 ISSILENT="$SILENTOP"
934 ;;
935 --ips)
936 ISIPS="$IPSOP"
937 ;;
938 --altkerndir)
939 # Use alternate kernel driver config folder (dev only)
940 DIR_CONF="/usr/kernel/drv"
941 ;;
942 --help)
943 printusage
944 exit 1
945 ;;
946 *)
947 break
948 ;;
949 esac
950 shift
951done
952
953case "$drvop" in
954--postinstall)
955 check_module_arch
956 postinstall
957 ;;
958--preremove)
959 preremove "$fatal"
960 ;;
961--installdrivers)
962 check_module_arch
963 install_drivers
964 ;;
965--removedrivers)
966 remove_drivers "$fatal"
967 ;;
968--setupdrivers)
969 remove_drivers "$fatal"
970 infoprint "Installing VirtualBox drivers:"
971 install_drivers
972 ;;
973*)
974 printusage
975 exit 1
976esac
977
978exit "$?"
979
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