VirtualBox

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

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

Ran the source code massager (scm).

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