VirtualBox

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

最後變更 在這個檔案從92503是 92503,由 vboxsync 提交於 3 年 前

Installer/solaris, Additions/solaris/Installer: Fix handing of /etc/devlink.tab group membership in the driver install. Automatically adjusts to the group which should be used on the respective OS update version. Done in a way which automatically repairs the incorrect group membership on the next install/uninstall.

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 49.5 KB
 
1#!/bin/sh
2# $Id: vboxconfig.sh 92503 2021-11-18 17:43:22Z vboxsync $
3## @file
4# VirtualBox Configuration Script, Solaris host.
5#
6
7#
8# Copyright (C) 2009-2020 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.alldomusa.eu.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19# Never use exit 2 or exit 20 etc., the return codes are used in
20# SRv4 postinstall procedures which carry special meaning. Just use exit 1 for failure.
21
22# LC_ALL should take precedence over LC_* and LANG but whatever...
23LC_ALL=C
24export LC_ALL
25
26LANG=C
27export LANG
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_SVCS=/usr/bin/svcs
45BIN_IFCONFIG=/sbin/ifconfig
46BIN_SVCS=/usr/bin/svcs
47BIN_ID=/usr/bin/id
48BIN_PKILL=/usr/bin/pkill
49BIN_PGREP=/usr/bin/pgrep
50BIN_IPADM=/usr/sbin/ipadm
51
52# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
53MOD_VBOXDRV=vboxdrv
54DESC_VBOXDRV="Host"
55
56MOD_VBOXNET=vboxnet
57DESC_VBOXNET="NetAdapter"
58MOD_VBOXNET_INST=8
59
60MOD_VBOXFLT=vboxflt
61DESC_VBOXFLT="NetFilter (STREAMS)"
62
63MOD_VBOXBOW=vboxbow
64DESC_VBOXBOW="NetFilter (Crossbow)"
65
66MOD_VBOXUSBMON=vboxusbmon
67DESC_VBOXUSBMON="USBMonitor"
68
69MOD_VBOXUSB=vboxusb
70DESC_VBOXUSB="USB"
71
72UPDATEBOOTARCHIVE=0
73REMOTEINST=0
74FATALOP=fatal
75NULLOP=nulloutput
76SILENTOP=silent
77IPSOP=ips
78ISSILENT=
79ISIPS=
80
81infoprint()
82{
83 if test "x$ISSILENT" != "x$SILENTOP"; then
84 echo 1>&2 "$1"
85 fi
86}
87
88subprint()
89{
90 if test "x$ISSILENT" != "x$SILENTOP"; then
91 echo 1>&2 " - $1"
92 fi
93}
94
95warnprint()
96{
97 if test "x$ISSILENT" != "x$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 if test ! -x "$BIN_PGREP"; then
210 BIN_PGREP=`find_bin_path "$BIN_PGREP"`
211 fi
212
213 if test ! -x "$BIN_IPADM"; then
214 BIN_IPADM=`find_bin_path "$BIN_IPADM"`
215 fi
216}
217
218# check_root()
219# !! failure is always fatal
220check_root()
221{
222 # Don't use "-u" option as some id binaries don't support it, instead
223 # rely on "uid=101(username) gid=10(groupname) groups=10(staff)" output
224 curuid=`$BIN_ID | cut -f 2 -d '=' | cut -f 1 -d '('`
225 if test "$curuid" -ne 0; then
226 errorprint "This script must be run with administrator privileges."
227 exit 1
228 fi
229}
230
231# get_unofficial_sysinfo()
232# cannot fail
233get_unofficial_sysinfo()
234{
235 HOST_OS_MAJORVERSION="11"
236 HOST_OS_MINORVERSION="151"
237}
238
239# get_s11_4_sysinfo()
240# cannot fail
241get_s11_4_sysinfo()
242{
243 # See check in plumb_net for why this is > 174. The alternative is we declare 11.4+ as S12 with
244 # a more accurate minor (build) version number. For now this is sufficient to workaround the ever
245 # changing version numbering policy.
246 HOST_OS_MAJORVERSION="11"
247 HOST_OS_MINORVERSION="175"
248}
249
250# get_s11_5_or_newer_sysinfo()
251# cannot fail
252get_s11_5_or_newer_sysinfo()
253{
254 # See check in plumb_net for why this is 176.
255 HOST_OS_MAJORVERSION="11"
256 HOST_OS_MINORVERSION="176"
257}
258
259# get_sysinfo()
260# cannot fail
261get_sysinfo()
262{
263 STR_OSVER=`uname -v`
264 case "$STR_OSVER" in
265 # First check 'uname -v' and weed out the recognized, unofficial distros of Solaris
266 omnios*|oi_*|illumos*)
267 get_unofficial_sysinfo
268 return 0
269 ;;
270 # Quick escape workaround for Solaris 11.4, changes the pkg FMRI (yet again). See BugDB #26494983.
271 11.4.*)
272 get_s11_4_sysinfo
273 return 0
274 ;;
275 # Quick escape workaround for Solaris 11.5. See BugDB #26494983.
276 11.5.*)
277 get_s11_5_or_newer_sysinfo
278 return 0
279 esac
280
281 BIN_PKG=`which pkg 2> /dev/null`
282 if test -x "$BIN_PKG"; then
283 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -a name=pkg.fmri -o pkg.fmri pkg:/system/kernel 2> /dev/null`
284 if test -z "$PKGFMRI"; then
285 # Perhaps this is old pkg without '-a' option and/or system/kernel is missing and it's part of 'entire'
286 # Try fallback.
287 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -o pkg.fmri entire | head -1 2> /dev/null`
288 if test -z "$PKGFMRI"; then
289 # Perhaps entire is conflicting. Try using opensolaris/entire.
290 # Last fallback try.
291 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -o pkg.fmri opensolaris.org/entire | head -1 2> /dev/null`
292 fi
293 fi
294 if test ! -z "$PKGFMRI"; then
295 # The format is "pkg://solaris/system/[email protected],5.11-0.161:20110315T070332Z"
296 # or "pkg://solaris/system/[email protected],5.11-5.12.0.0.0.4.1:20120908T030246Z"
297 # or "pkg://solaris/system/[email protected],5.11-0.175.0.0.0.1.0:20111012T032837Z"
298 # or "pkg://solaris/system/[email protected]:20121012T032837Z" [1]
299 # [1]: The sed below doesn't handle this. It's instead parsed below in the PSARC/2012/240 case.
300 STR_KERN_MAJOR=`echo "$PKGFMRI" | sed 's/^.*\@//;s/\,.*//'`
301 if test ! -z "$STR_KERN_MAJOR"; then
302 # The format is "0.5.11" or "5.12"
303 # Let us just hardcode these for now, instead of trying to do things more generically. It's not
304 # worth trying to bring more order to chaos as it's clear that the version numbering is subject to breakage
305 # as it has been seen in the past.
306 if test "x$STR_KERN_MAJOR" = "x5.12"; then
307 HOST_OS_MAJORVERSION="12"
308 elif test "x$STR_KERN_MAJOR" = "x0.5.11" || test "x$STR_KERN_MAJOR" = "x5.11"; then
309 HOST_OS_MAJORVERSION="11"
310 else
311 # This could be the PSARC/2012/240 naming scheme for S12.
312 # The format is "pkg://solaris/system/[email protected]:20121012T032837Z"
313 # The "5.12" following the "@" is the nominal version which we ignore for now as it is
314 # not set by most pkg(5) tools...
315 # STR_KERN_MAJOR is now of the format "5.12-5.12.0.0.0.9.1.3.0:20121012T032837Z" with '9' representing
316 # the build number.
317 BRANCH_VERSION=$STR_KERN_MAJOR
318 HOST_OS_MAJORVERSION=`echo "$BRANCH_VERSION" | cut -f2 -d'-' | cut -f1,2 -d'.'`
319 if test "x$HOST_OS_MAJORVERSION" = "x5.12"; then
320 HOST_OS_MAJORVERSION="12"
321 HOST_OS_MINORVERSION=`echo "$BRANCH_VERSION" | cut -f2 -d'-' | cut -f6 -d'.'`
322 return 0
323 else
324 errorprint "Failed to parse the Solaris kernel major version."
325 exit 1
326 fi
327 fi
328
329 # This applies only to S11 and S12 where the transitional "@5.12," component version is
330 # still part of the pkg(5) package FMRI. The regular S12 will follow the PSARC/2012/240 naming scheme above.
331 STR_KERN_MINOR=`echo "$PKGFMRI" | sed 's/^.*\@//;s/\:.*//;s/.*,//'`
332 if test ! -z "$STR_KERN_MINOR"; then
333 # The HOST_OS_MINORVERSION is represented as follows:
334 # For S12 it represents the build numbers. e.g. for 4 : "5.11-5.12.0.0.0.4.1"
335 # For S11 as the "nevada" version numbers. e.g. for 175: "5.11-0.161" or "5.11-0.175.0.0.0.1.0"
336 if test "$HOST_OS_MAJORVERSION" -eq 12; then
337 HOST_OS_MINORVERSION=`echo "$STR_KERN_MINOR" | cut -f2 -d'-' | cut -f6 -d'.'`
338 elif test "$HOST_OS_MAJORVERSION" -eq 11; then
339 HOST_OS_MINORVERSION=`echo "$STR_KERN_MINOR" | cut -f2 -d'-' | cut -f2 -d'.'`
340 else
341 errorprint "Solaris kernel major version $HOST_OS_MAJORVERSION not supported."
342 exit 1
343 fi
344 else
345 errorprint "Failed to parse the Solaris kernel minor version."
346 exit 1
347 fi
348 else
349 errorprint "Failed to parse the Solaris kernel package version."
350 exit 1
351 fi
352 else
353 errorprint "Failed to detect the Solaris kernel package FMRI."
354 exit 1
355 fi
356 else
357 HOST_OS_MAJORVERSION=`uname -r`
358 if test -z "$HOST_OS_MAJORVERSION" || test "x$HOST_OS_MAJORVERSION" != "x5.10"; then
359 # S11 without 'pkg'?? Something's wrong... bail.
360 errorprint "Solaris $HOST_OS_MAJORVERSION detected without executable $BIN_PKG !? I are confused."
361 exit 1
362 fi
363 HOST_OS_MAJORVERSION="10"
364 if test "$REMOTEINST" -eq 0; then
365 # Use uname to verify it's S10.
366 # Major version is S10, Minor version is no longer relevant (or used), use uname -v so it gets something
367 # like "Generic_blah" for purely cosmetic purposes
368 HOST_OS_MINORVERSION=`uname -v`
369 else
370 # Remote installs from S10 local.
371 BIN_PKGCHK=`which pkgchk 2> /dev/null`
372 if test ! -x "$BIN_PKGCHK"; then
373 errorprint "Failed to find an executable pkgchk binary $BIN_PKGCHK."
374 errorprint "Cannot determine Solaris version on remote target $PKG_INSTALL_ROOT"
375 exit 1
376 fi
377
378 REMOTE_S10=`$BIN_PKGCHK -l -p /kernel/amd64/genunix $BASEDIR_PKGOPT 2> /dev/null | grep SUNWckr | tr -d ' \t'`
379 if test ! -z "$REMOTE_S10" && test "x$REMOTE_S10" = "xSUNWckr"; then
380 HOST_OS_MAJORVERSION="10"
381 HOST_OS_MINORVERSION=""
382 else
383 errorprint "Remote target $PKG_INSTALL_ROOT is not Solaris 10."
384 errorprint "Will not attempt to install to an unidentified remote target."
385 exit 1
386 fi
387 fi
388 fi
389}
390
391# check_zone()
392# !! failure is always fatal
393check_zone()
394{
395 currentzone=`zonename`
396 if test "x$currentzone" != "xglobal"; then
397 errorprint "This script must be run from the global zone."
398 exit 1
399 fi
400}
401
402# check_isa()
403# !! failure is always fatal
404check_isa()
405{
406 currentisa=`uname -i`
407 if test "x$currentisa" = "xi86xpv"; then
408 errorprint "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
409 exit 1
410 fi
411}
412
413# check_module_arch()
414# !! failure is always fatal
415check_module_arch()
416{
417 cputype=`isainfo -k`
418 if test "x$cputype" != "xamd64" && test "x$cputype" != "xi386"; then
419 errorprint "VirtualBox works only on i386/amd64 hosts, not $cputype"
420 exit 1
421 fi
422}
423
424# update_boot_archive()
425# cannot fail
426update_boot_archive()
427{
428 infoprint "Updating the boot archive..."
429 if test "$REMOTEINST" -eq 0; then
430 $BIN_BOOTADM update-archive > /dev/null
431 else
432 $BIN_BOOTADM update-archive -R "$PKG_INSTALL_ROOT" > /dev/null
433 fi
434 UPDATEBOOTARCHIVE=0
435}
436
437
438# module_added(modname)
439# returns 1 if added, 0 otherwise
440module_added()
441{
442 if test -z "$1"; then
443 errorprint "missing argument to module_added()"
444 exit 1
445 fi
446
447 # Add a space at end of module name to make sure we have a perfect match to avoid
448 # any substring matches: e.g "vboxusb" & "vboxusbmon"
449 loadentry=`cat "$PKG_INSTALL_ROOT/etc/name_to_major" | grep "$1 "`
450 if test -z "$loadentry"; then
451 return 1
452 fi
453 return 0
454}
455
456# module_loaded(modname)
457# returns 1 if loaded, 0 otherwise
458module_loaded()
459{
460 if test -z "$1"; then
461 errorprint "missing argument to module_loaded()"
462 exit 1
463 fi
464
465 modname=$1
466 # modinfo should now work properly since we prevent module autounloading.
467 loadentry=`$BIN_MODINFO | grep "$modname "`
468 if test -z "$loadentry"; then
469 return 1
470 fi
471 return 0
472}
473
474# add_driver(modname, moddesc, fatal, nulloutput, [driverperm])
475# failure: depends on "fatal"
476add_driver()
477{
478 if test -z "$1" || test -z "$2"; then
479 errorprint "missing argument to add_driver()"
480 exit 1
481 fi
482
483 modname="$1"
484 moddesc="$2"
485 fatal="$3"
486 nullop="$4"
487 modperm="$5"
488
489 if test -n "$modperm"; then
490 if test "x$nullop" = "x$NULLOP"; then
491 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname >/dev/null 2>&1
492 else
493 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname
494 fi
495 else
496 if test "x$nullop" = "x$NULLOP"; then
497 $BIN_ADDDRV $BASEDIR_OPT $modname >/dev/null 2>&1
498 else
499 $BIN_ADDDRV $BASEDIR_OPT $modname
500 fi
501 fi
502
503 if test "$?" -ne 0; then
504 subprint "Adding: $moddesc module ...FAILED!"
505 if test "x$fatal" = "x$FATALOP"; then
506 exit 1
507 fi
508 return 1
509 fi
510 subprint "Added: $moddesc driver"
511 return 0
512}
513
514# rem_driver(modname, moddesc, [fatal])
515# failure: depends on [fatal]
516rem_driver()
517{
518 if test -z "$1" || test -z "$2"; then
519 errorprint "missing argument to rem_driver()"
520 exit 1
521 fi
522
523 modname=$1
524 moddesc=$2
525 fatal=$3
526
527 module_added $modname
528 if test "$?" -eq 0; then
529 UPDATEBOOTARCHIVE=1
530 if test "x$ISIPS" != "x$IPSOP"; then
531 $BIN_REMDRV $BASEDIR_OPT $modname
532 else
533 $BIN_REMDRV $BASEDIR_OPT $modname >/dev/null 2>&1
534 fi
535 # for remote installs, don't bother with return values of rem_drv
536 if test "$?" -eq 0 || test "$REMOTEINST" -eq 1; then
537 subprint "Removed: $moddesc driver"
538 return 0
539 else
540 subprint "Removing: $moddesc ...FAILED!"
541 if test "x$fatal" = "x$FATALOP"; then
542 exit 1
543 fi
544 return 1
545 fi
546 fi
547}
548
549# unload_module(modname, moddesc, retry, [fatal])
550# failure: fatal
551unload_module()
552{
553 if test -z "$1" || test -z "$2"; then
554 errorprint "missing argument to unload_module()"
555 exit 1
556 fi
557
558 # No-OP for non-root installs
559 if test "$REMOTEINST" -eq 1; then
560 return 0
561 fi
562
563 modname=$1
564 moddesc=$2
565 retry=$3
566 fatal=$4
567 modid=`$BIN_MODINFO | grep "$modname " | cut -f 1 -d ' ' `
568 if test -n "$modid"; then
569 $BIN_MODUNLOAD -i $modid
570 if test "$?" -eq 0; then
571 subprint "Unloaded: $moddesc module"
572 else
573 #
574 # Hack for vboxdrv. Delayed removing when VMM thread-context hooks are used.
575 # Our automated tests are probably too quick... Fix properly later.
576 #
577 result="$?"
578 if test "$retry" -eq 1; then
579 cmax=15
580 cslept=0
581 while test "$result" -ne 0;
582 do
583 subprint "Unloading: $moddesc module ...FAILED! Busy? Retrying in 3 seconds..."
584 sleep 3
585 cslept=`expr $cslept + 3`
586 if test "$cslept" -ge "$cmax"; then
587 break
588 fi
589 $BIN_MODUNLOAD -i $modid
590 result="$?"
591 done
592 fi
593
594 if test "$result" -ne 0; then
595 subprint "Unloading: $moddesc module ...FAILED!"
596 if test "x$fatal" = "x$FATALOP"; then
597 exit 1
598 fi
599 else
600 subprint "Unloaded: $moddesc module"
601 fi
602 return 1
603 fi
604 fi
605 return 0
606}
607
608# load_module(modname, moddesc, [fatal])
609# pass "drv/modname" or "misc/vbi" etc.
610# failure: fatal
611load_module()
612{
613 if test -z "$1" || test -z "$2"; then
614 errorprint "missing argument to load_module()"
615 exit 1
616 fi
617
618 # No-OP for non-root installs
619 if test "$REMOTEINST" -eq 1; then
620 return 0
621 fi
622
623 modname=$1
624 moddesc=$2
625 fatal=$3
626 $BIN_MODLOAD -p $modname
627 if test "$?" -eq 0; then
628 return 0
629 else
630 subprint "Loading: $moddesc module ...FAILED!"
631 if test "x$fatal" = "x$FATALOP"; then
632 exit 1
633 fi
634 return 1
635 fi
636}
637
638load_vboxflt()
639{
640 if test -f "$DIR_CONF/vboxflt.conf"; then
641 add_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
642 load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
643 else
644 # For custom pkgs that optionally ship this module, let's not fail but just warn
645 warnprint "$DESC_VBOXFLT installation requested but not shipped in this package."
646 fi
647}
648
649load_vboxbow()
650{
651 if test -f "$DIR_CONF/vboxbow.conf"; then
652 add_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
653 load_module "drv/$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
654 else
655 # For custom pkgs that optionally ship this module, let's not fail but just warn
656 warnprint "$DESC_VBOXBOW installation requested but not shipped in this package."
657 fi
658}
659
660# install_drivers()
661# !! failure is always fatal
662install_drivers()
663{
664 if test -f "$DIR_CONF/vboxdrv.conf"; then
665 if test -n "_HARDENED_"; then
666 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0600 root sys','vboxdrvu 0666 root sys'"
667 else
668 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0666 root sys','vboxdrvu 0666 root sys'"
669 fi
670 load_module "drv/$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP"
671 else
672 errorprint "Extreme error! Missing $DIR_CONF/vboxdrv.conf, aborting."
673 return 1
674 fi
675
676 # Figure out group to use for /etc/devlink.tab (before Solaris 11 SRU6
677 # it was always using group sys)
678 group=sys
679 if [ -f "$PKG_INSTALL_ROOT/etc/dev/reserved_devnames" ]; then
680 # Solaris 11 SRU6 and later use group root (check a file which isn't
681 # tainted by VirtualBox install scripts and allow no other group)
682 refgroup=$(LC_ALL=C /usr/bin/ls -lL "$PKG_INSTALL_ROOT/etc/dev/reserved_devnames" | awk '{ print $4 }' 2>/dev/null)
683 if [ $? -eq 0 -a "x$refgroup" = "xroot" ]; then
684 group=root
685 fi
686 unset refgroup
687 fi
688
689 ## Add vboxdrv to devlink.tab (KEEP TABS!)
690 if test -f "$PKG_INSTALL_ROOT/etc/devlink.tab"; then
691 sed -e '/name=vboxdrv/d' -e '/name=vboxdrvu/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
692 echo "type=ddi_pseudo;name=vboxdrv;minor=vboxdrv \D" >> "$PKG_INSTALL_ROOT/etc/devlink.vbox"
693 echo "type=ddi_pseudo;name=vboxdrv;minor=vboxdrvu \M0" >> "$PKG_INSTALL_ROOT/etc/devlink.vbox"
694 chmod 0644 "$PKG_INSTALL_ROOT/etc/devlink.vbox"
695 chown root:$group "$PKG_INSTALL_ROOT/etc/devlink.vbox"
696 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
697 else
698 errorprint "Missing $PKG_INSTALL_ROOT/etc/devlink.tab, aborting install"
699 return 1
700 fi
701
702 # Create the device link for non-remote installs (not really relevant any more)
703 if test "$REMOTEINST" -eq 0; then
704 /usr/sbin/devfsadm -i "$MOD_VBOXDRV"
705 if test "$?" -ne 0 || test ! -h "/dev/vboxdrv" || test ! -h "/dev/vboxdrvu" ; then
706 errorprint "Failed to create device link for $MOD_VBOXDRV."
707 exit 1
708 fi
709 fi
710
711 # Load VBoxNetAdp
712 if test -f "$DIR_CONF/vboxnet.conf"; then
713 add_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
714 load_module "drv/$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
715 fi
716
717 # If both vboxinst_vboxbow and vboxinst_vboxflt exist, bail.
718 if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt" && test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow"; then
719 errorprint "Force-install files '$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt' and '$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow' both exist."
720 errorprint "Cannot load $DESC_VBOXFLT and $DESC_VBOXBOW drivers at the same time."
721 return 1
722 fi
723
724 # If the force-install files exists, install blindly
725 if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt"; then
726 subprint "Detected: Force-load file $PKG_INSTALL_ROOT/etc/vboxinst_vboxflt."
727 load_vboxflt
728 elif test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow"; then
729 subprint "Detected: Force-load file $PKG_INSTALL_ROOT/etc/vboxinst_vboxbow."
730 load_vboxbow
731 else
732 # If host is S10 or S11 (< snv_159) or vboxbow isn't shipped, then load vboxflt
733 if test "$HOST_OS_MAJORVERSION" -eq 10 \
734 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -lt 159) \
735 || test ! -f "$DIR_CONF/vboxbow.conf"; then
736 load_vboxflt
737 else
738 # For S11 snv_159+ load vboxbow
739 load_vboxbow
740 fi
741 fi
742
743 # Load VBoxUSBMon, VBoxUSB
744 try_vboxusb="no"
745 if test -f "$DIR_CONF/vboxusbmon.conf"; then
746 if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxusb"; then
747 subprint "Detected: Force-load file $PKG_INSTALL_ROOT/etc/vboxinst_vboxusb."
748 try_vboxusb="yes"
749 else
750 # For VirtualBox 3.1 the new USB code requires Nevada > 123 i.e. S12+ or S11 b124+
751 if test "$HOST_OS_MAJORVERSION" -gt 11 \
752 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -gt 123); then
753 try_vboxusb="yes"
754 else
755 warnprint "Solaris 11 build 124 or higher required for USB support. Skipped installing USB support."
756 fi
757 fi
758 fi
759 if test "x$try_vboxusb" = "xyes"; then
760 # Add a group "vboxuser" (8-character limit) for USB access.
761 # All users which need host USB-passthrough support will have to be added to this group.
762 groupadd vboxuser >/dev/null 2>&1
763
764 add_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
765 load_module "drv/$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP"
766
767 chown root:vboxuser "/devices/pseudo/vboxusbmon@0:vboxusbmon"
768
769 # Add vboxusbmon to devlink.tab
770 sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
771 echo "type=ddi_pseudo;name=vboxusbmon \D" >> "$PKG_INSTALL_ROOT/etc/devlink.vbox"
772 chmod 0644 "$PKG_INSTALL_ROOT/etc/devlink.vbox"
773 chown root:$group "$PKG_INSTALL_ROOT/etc/devlink.vbox"
774 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
775
776 # Create the device link for non-remote installs
777 if test "$REMOTEINST" -eq 0; then
778 /usr/sbin/devfsadm -i "$MOD_VBOXUSBMON"
779 if test "$?" -ne 0; then
780 errorprint "Failed to create device link for $MOD_VBOXUSBMON."
781 exit 1
782 fi
783 fi
784
785 # Add vboxusb if present
786 # This driver is special, we need it in the boot-archive but since there is no
787 # USB device to attach to now (it's done at runtime) it will fail to attach so
788 # redirect attaching failure output to /dev/null
789 if test -f "$DIR_CONF/vboxusb.conf"; then
790 add_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP" "$NULLOP"
791 load_module "drv/$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP"
792 fi
793 fi
794
795 return $?
796}
797
798# remove_drivers([fatal])
799# failure: depends on [fatal]
800remove_drivers()
801{
802 fatal=$1
803
804 # Figure out group to use for /etc/devlink.tab (before Solaris 11 SRU6
805 # it was always using group sys)
806 group=sys
807 if [ -f "$PKG_INSTALL_ROOT/etc/dev/reserved_devnames" ]; then
808 # Solaris 11 SRU6 and later use group root (check a file which isn't
809 # tainted by VirtualBox install scripts and allow no other group)
810 refgroup=$(LC_ALL=C /usr/bin/ls -lL "$PKG_INSTALL_ROOT/etc/dev/reserved_devnames" | awk '{ print $4 }' 2>/dev/null)
811 if [ $? -eq 0 -a "x$refgroup" = "xroot" ]; then
812 group=root
813 fi
814 unset refgroup
815 fi
816
817 # Remove vboxdrv[u] from devlink.tab
818 if test -f "$PKG_INSTALL_ROOT/etc/devlink.tab"; then
819 devlinkfound=`cat "$PKG_INSTALL_ROOT/etc/devlink.tab" | grep vboxdrv`
820 if test -n "$devlinkfound"; then
821 sed -e '/name=vboxdrv/d' -e '/name=vboxdrvu/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
822 chmod 0644 "$PKG_INSTALL_ROOT/etc/devlink.vbox"
823 chown root:$group "$PKG_INSTALL_ROOT/etc/devlink.vbox"
824 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
825 fi
826
827 # Remove vboxusbmon from devlink.tab
828 devlinkfound=`cat "$PKG_INSTALL_ROOT/etc/devlink.tab" | grep vboxusbmon`
829 if test -n "$devlinkfound"; then
830 sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
831 chmod 0644 "$PKG_INSTALL_ROOT/etc/devlink.vbox"
832 chown root:$group "$PKG_INSTALL_ROOT/etc/devlink.vbox"
833 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
834 fi
835 fi
836
837 unload_module "$MOD_VBOXUSB" "$DESC_VBOXUSB" 0 "$fatal"
838 rem_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$fatal"
839
840 unload_module "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" 0 "$fatal"
841 rem_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$fatal"
842
843 unload_module "$MOD_VBOXFLT" "$DESC_VBOXFLT" 0 "$fatal"
844 rem_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$fatal"
845
846 unload_module "$MOD_VBOXBOW" "$DESC_VBOXBOW" 0 "$fatal"
847 rem_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$fatal"
848
849 unload_module "$MOD_VBOXNET" "$DESC_VBOXNET" 0 "$fatal"
850 rem_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$fatal"
851
852 unload_module "$MOD_VBOXDRV" "$DESC_VBOXDRV" 1 "$fatal"
853 rem_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$fatal"
854
855 # remove devlinks
856 if test -h "$PKG_INSTALL_ROOT/dev/vboxdrv" || test -f "$PKG_INSTALL_ROOT/dev/vboxdrv"; then
857 rm -f "$PKG_INSTALL_ROOT/dev/vboxdrv"
858 fi
859 if test -h "$PKG_INSTALL_ROOT/dev/vboxdrvu" || test -f "$PKG_INSTALL_ROOT/dev/vboxdrvu"; then
860 rm -f "$PKG_INSTALL_ROOT/dev/vboxdrvu"
861 fi
862 if test -h "$PKG_INSTALL_ROOT/dev/vboxusbmon" || test -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"; then
863 rm -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"
864 fi
865
866 # unpatch nwam/dhcpagent fix
867 nwamfile="$PKG_INSTALL_ROOT/etc/nwam/llp"
868 nwambackupfile=$nwamfile.vbox
869 if test -f "$nwamfile"; then
870 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
871 mv -f $nwambackupfile $nwamfile
872 fi
873
874 # remove netmask configuration
875 if test -h "$PKG_INSTALL_ROOT/etc/netmasks"; then
876 nmaskfile="$PKG_INSTALL_ROOT/etc/inet/netmasks"
877 else
878 nmaskfile="$PKG_INSTALL_ROOT/etc/netmasks"
879 fi
880 nmaskbackupfile=$nmaskfile.vbox
881 if test -f "$nmaskfile"; then
882 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
883 mv -f $nmaskbackupfile $nmaskfile
884 fi
885
886 if test $UPDATEBOOTARCHIVE -eq 1; then
887 update_boot_archive
888 fi
889
890 return 0
891}
892
893# install_python_bindings(pythonbin)
894# remarks: changes pwd
895# failure: non fatal
896install_python_bindings()
897{
898 # The python binary might not be there, so just exit silently
899 if test -z "$1"; then
900 return 0
901 fi
902
903 if test -z "$2"; then
904 errorprint "missing argument to install_python_bindings"
905 exit 1
906 fi
907
908 pythonbin=$1
909 pythondesc=$2
910 if test -x "$pythonbin"; then
911 # check if python has working distutils
912 $pythonbin -c "from distutils.core import setup" > /dev/null 2>&1
913 if test "$?" -ne 0; then
914 subprint "Skipped: $pythondesc install is unusable"
915 return 0
916 fi
917
918 VBOX_INSTALL_PATH="$DIR_VBOXBASE"
919 export VBOX_INSTALL_PATH
920 cd $DIR_VBOXBASE/sdk/installer
921 $pythonbin ./vboxapisetup.py install > /dev/null
922 if test "$?" -eq 0; then
923 subprint "Installed: Bindings for $pythondesc"
924 fi
925 return 0
926 fi
927 return 1
928}
929
930# is_process_running(processname)
931# returns 1 if the process is running, 0 otherwise
932is_process_running()
933{
934 if test -z "$1"; then
935 errorprint "missing argument to is_process_running()"
936 exit 1
937 fi
938
939 procname="$1"
940 $BIN_PGREP "$procname" > /dev/null 2>&1
941 if test "$?" -eq 0; then
942 return 1
943 fi
944 return 0
945}
946
947
948# stop_process(processname)
949# failure: depends on [fatal]
950stop_process()
951{
952 if test -z "$1"; then
953 errorprint "missing argument to stop_process()"
954 exit 1
955 fi
956
957 procname="$1"
958 is_process_running "$procname"
959 if test "$?" -eq 1; then
960 $BIN_PKILL "$procname"
961 sleep 2
962 is_process_running "$procname"
963 if test "$?" -eq 1; then
964 subprint "Terminating: $procname ...FAILED!"
965 if test "x$fatal" = "x$FATALOP"; then
966 exit 1
967 fi
968 else
969 subprint "Terminated: $procname"
970 fi
971 fi
972}
973
974# start_service(servicename, shortFMRI pretty printing, full FMRI, log-file path)
975# failure: non-fatal
976start_service()
977{
978 if test -z "$1" || test -z "$2" || test -z "$3" || test -z "$4"; then
979 errorprint "missing argument to enable_service()"
980 exit 1
981 fi
982
983 # Since S11 the way to import a manifest is via restarting manifest-import which is asynchronous and can
984 # take a while to complete, using disable/enable -s doesn't work either. So we restart it, and poll in
985 # 1 second intervals to see if our service has been successfully imported and timeout after 'cmax' seconds.
986 cmax=32
987 cslept=0
988 success=0
989
990 $BIN_SVCS "$3" >/dev/null 2>&1
991 while test "$?" -ne 0;
992 do
993 sleep 1
994 cslept=`expr $cslept + 1`
995 if test "$cslept" -eq "$cmax"; then
996 success=1
997 break
998 fi
999 $BIN_SVCS "$3" >/dev/null 2>&1
1000 done
1001 if test "$success" -eq 0; then
1002 $BIN_SVCADM enable -s "$3"
1003 if test "$?" -eq 0; then
1004 subprint "Enabled: $1"
1005 return 0
1006 else
1007 warnprint "Enabling $1 ...FAILED."
1008 warnprint "Refer $4 for details."
1009 fi
1010 else
1011 warnprint "Importing $1 ...FAILED."
1012 warnprint "Refer /var/svc/log/system-manifest-import:default.log for details."
1013 fi
1014 return 1
1015}
1016
1017
1018# stop_service(servicename, shortFMRI-suitable for grep, full FMRI)
1019# failure: non fatal
1020stop_service()
1021{
1022 if test -z "$1" || test -z "$2" || test -z "$3"; then
1023 errorprint "missing argument to stop_service()"
1024 exit 1
1025 fi
1026 servicefound=`$BIN_SVCS -H "$2" 2>/dev/null | grep '^online'`
1027 if test ! -z "$servicefound"; then
1028 $BIN_SVCADM disable -s "$3"
1029 # Don't delete the manifest, this is handled by the manifest class action
1030 # $BIN_SVCCFG delete "$3"
1031 if test "$?" -eq 0; then
1032 subprint "Disabled: $1"
1033 else
1034 subprint "Disabling: $1 ...ERROR(S)."
1035 fi
1036 fi
1037}
1038
1039
1040# plumb vboxnet0 instance
1041# failure: non fatal
1042plumb_net()
1043{
1044 # S11 175a renames vboxnet0 as 'netX', undo this and rename it back (Solaris 12, Solaris 11.4 or newer)
1045 if test "$HOST_OS_MAJORVERSION" -ge 12 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -ge 175); then
1046 vanityname=`dladm show-phys -po link,device | grep vboxnet0 | cut -f1 -d':'`
1047 if test "$?" -eq 0 && test ! -z "$vanityname" && test "x$vanityname" != "xvboxnet0"; then
1048 dladm rename-link "$vanityname" vboxnet0
1049 if test "$?" -ne 0; then
1050 errorprint "Failed to rename vanity interface ($vanityname) to vboxnet0"
1051 fi
1052 fi
1053 fi
1054
1055 # use ipadm for Solaris 12, Solaris 11.5 or newer
1056 if test "$HOST_OS_MAJORVERSION" -ge 12 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -ge 176); then
1057 $BIN_IPADM create-ip vboxnet0
1058 if test "$?" -eq 0; then
1059 $BIN_IPADM create-addr -T static -a local="192.168.56.1/24" "vboxnet0/v4addr"
1060 if test "$?" -eq 0; then
1061 subprint "Configured: NetAdapter 'vboxnet0'"
1062 else
1063 warnprint "Failed to create local address for vboxnet0!"
1064 fi
1065 else
1066 warnprint "Failed to create IP instance for vboxnet0!"
1067 fi
1068 else
1069 $BIN_IFCONFIG vboxnet0 plumb
1070 $BIN_IFCONFIG vboxnet0 up
1071 if test "$?" -eq 0; then
1072 $BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
1073
1074 # /etc/netmasks is a symlink, older installers replaced this with
1075 # a copy of the actual file, repair that behaviour here.
1076 recreatelink=0
1077 if test -h "$PKG_INSTALL_ROOT/etc/netmasks"; then
1078 nmaskfile="$PKG_INSTALL_ROOT/etc/inet/netmasks"
1079 else
1080 nmaskfile="$PKG_INSTALL_ROOT/etc/netmasks"
1081 recreatelink=1
1082 fi
1083
1084 # add the netmask to stay persistent across host reboots
1085 nmaskbackupfile=$nmaskfile.vbox
1086 if test -f $nmaskfile; then
1087 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
1088
1089 if test "$recreatelink" -eq 1; then
1090 # Check after removing our settings if /etc/netmasks is identifcal to /etc/inet/netmasks
1091 anydiff=`diff $nmaskbackupfile "$PKG_INSTALL_ROOT/etc/inet/netmasks"`
1092 if test ! -z "$anydiff"; then
1093 # User may have some custom settings in /etc/netmasks, don't overwrite /etc/netmasks!
1094 recreatelink=2
1095 fi
1096 fi
1097
1098 echo "#VirtualBox_SectionStart" >> $nmaskbackupfile
1099 inst=0
1100 networkn=56
1101 while test "$inst" -ne 1; do
1102 echo "192.168.$networkn.0 255.255.255.0" >> $nmaskbackupfile
1103 inst=`expr $inst + 1`
1104 networkn=`expr $networkn + 1`
1105 done
1106 echo "#VirtualBox_SectionEnd" >> $nmaskbackupfile
1107 mv -f $nmaskbackupfile $nmaskfile
1108
1109 # Recreate /etc/netmasks as a link if necessary
1110 if test "$recreatelink" -eq 1; then
1111 cp -f "$PKG_INSTALL_ROOT/etc/netmasks" "$PKG_INSTALL_ROOT/etc/inet/netmasks"
1112 ln -sf ./inet/netmasks "$PKG_INSTALL_ROOT/etc/netmasks"
1113 elif test "$recreatelink" -eq 2; then
1114 warnprint "/etc/netmasks is a symlink (to /etc/inet/netmasks) that older"
1115 warnprint "VirtualBox installers incorrectly overwrote. Now the contents"
1116 warnprint "of /etc/netmasks and /etc/inet/netmasks differ, therefore "
1117 warnprint "VirtualBox will not attempt to overwrite /etc/netmasks as a"
1118 warnprint "symlink to /etc/inet/netmasks. Please resolve this manually"
1119 warnprint "by updating /etc/inet/netmasks and creating /etc/netmasks as a"
1120 warnprint "symlink to /etc/inet/netmasks"
1121 fi
1122 fi
1123 else
1124 # Should this be fatal?
1125 warnprint "Failed to bring up vboxnet0!"
1126 fi
1127 fi
1128}
1129
1130
1131# unplumb all vboxnet instances
1132# failure: fatal
1133unplumb_net()
1134{
1135 inst=0
1136 # use ipadm for Solaris 12, Solaris 11.5 or newer
1137 if test "$HOST_OS_MAJORVERSION" -ge 12 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -ge 176); then
1138 while test "$inst" -ne $MOD_VBOXNET_INST; do
1139 vboxnetup=`$BIN_IPADM show-addr -p -o addrobj vboxnet$inst >/dev/null 2>&1`
1140 if test "$?" -eq 0; then
1141 $BIN_IPADM delete-addr vboxnet$inst/v4addr
1142 $BIN_IPADM delete-ip vboxnet$inst
1143 if test "$?" -ne 0; then
1144 errorprint "VirtualBox NetAdapter 'vboxnet$inst' couldn't be removed (probably in use)."
1145 if test "x$fatal" = "x$FATALOP"; then
1146 exit 1
1147 fi
1148 fi
1149 fi
1150
1151 inst=`expr $inst + 1`
1152 done
1153 else
1154 inst=0
1155 while test "$inst" -ne $MOD_VBOXNET_INST; do
1156 vboxnetup=`$BIN_IFCONFIG vboxnet$inst >/dev/null 2>&1`
1157 if test "$?" -eq 0; then
1158 $BIN_IFCONFIG vboxnet$inst unplumb
1159 if test "$?" -ne 0; then
1160 errorprint "VirtualBox NetAdapter 'vboxnet$inst' couldn't be unplumbed (probably in use)."
1161 if test "x$fatal" = "x$FATALOP"; then
1162 exit 1
1163 fi
1164 fi
1165 fi
1166
1167 # unplumb vboxnet0 ipv6
1168 vboxnetup=`$BIN_IFCONFIG vboxnet$inst inet6 >/dev/null 2>&1`
1169 if test "$?" -eq 0; then
1170 $BIN_IFCONFIG vboxnet$inst inet6 unplumb
1171 if test "$?" -ne 0; then
1172 errorprint "VirtualBox NetAdapter 'vboxnet$inst' IPv6 couldn't be unplumbed (probably in use)."
1173 if test "x$fatal" = "x$FATALOP"; then
1174 exit 1
1175 fi
1176 fi
1177 fi
1178
1179 inst=`expr $inst + 1`
1180 done
1181 fi
1182}
1183
1184
1185# cleanup_install([fatal])
1186# failure: depends on [fatal]
1187cleanup_install()
1188{
1189 fatal=$1
1190
1191 # No-Op for remote installs
1192 if test "$REMOTEINST" -eq 1; then
1193 return 0
1194 fi
1195
1196 # stop the services
1197 stop_service "Web service" "virtualbox/webservice" "svc:/application/virtualbox/webservice:default"
1198 stop_service "Balloon control service" "virtualbox/balloonctrl" "svc:/application/virtualbox/balloonctrl:default"
1199 stop_service "Autostart service" "virtualbox/autostart" "svc:/application/virtualbox/autostart:default"
1200 stop_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default"
1201
1202 # DEBUG x4600b: verify that the ZoneAccess process is really gone
1203 is_process_running "VBoxZoneAccess"
1204 if test "$?" -eq 1; then
1205 warnprint "VBoxZoneAccess is alive despite its service being dead. Killing..."
1206 stop_process "VBoxZoneAccess"
1207 fi
1208
1209 # unplumb all vboxnet instances for non-remote installs
1210 unplumb_net
1211
1212 # Stop our other daemons, non-fatal
1213 stop_process "VBoxNetDHCP"
1214 stop_process "VBoxNetNAT"
1215
1216 # Stop VBoxSVC quickly using SIGUSR1
1217 procname="VBoxSVC"
1218 procpid=`ps -eo pid,fname | grep $procname | grep -v grep | awk '{ print $1 }'`
1219 if test ! -z "$procpid" && test "$procpid" -ge 0; then
1220 kill -USR1 $procpid
1221
1222 # Sleep a while and check if VBoxSVC is still running, if so fail uninstallation.
1223 sleep 2
1224 is_process_running "VBoxSVC"
1225 if test "$?" -eq 1; then
1226 errorprint "Cannot uninstall VirtualBox while VBoxSVC (pid $procpid) is still running."
1227 errorprint "Please shutdown all VMs and VirtualBox frontends before uninstalling VirtualBox."
1228 exit 1
1229 fi
1230
1231 # Some VMs might still be alive after VBoxSVC as they poll less frequently before killing themselves
1232 # Just check for VBoxHeadless & VirtualBox frontends for now.
1233 is_process_running "VBoxHeadless"
1234 if test "$?" -eq 1; then
1235 errorprint "Cannot uninstall VirtualBox while VBoxHeadless is still running."
1236 errorprint "Please shutdown all VMs and VirtualBox frontends before uninstalling VirtualBox."
1237 exit 1
1238 fi
1239
1240 is_process_running "VirtualBox"
1241 if test "$?" -eq 1; then
1242 errorprint "Cannot uninstall VirtualBox while any VM is still running."
1243 errorprint "Please shutdown all VMs and VirtualBox frontends before uninstalling VirtualBox."
1244 exit 1
1245 fi
1246 fi
1247}
1248
1249
1250# postinstall()
1251# !! failure is always fatal
1252postinstall()
1253{
1254 infoprint "Detected Solaris $HOST_OS_MAJORVERSION Version $HOST_OS_MINORVERSION"
1255
1256 # Install the S10 legacy library links.
1257 # We do this early so that when we invoke services or other VirtualBox processes, the dependent libraries are resolved.
1258 if test -d "/opt/VirtualBox/legacy/"; then
1259 if test "$HOST_OS_MAJORVERSION" -eq 10; then
1260 for lib in `ls -1 /opt/VirtualBox/legacy/`; do
1261 /usr/sbin/installf -c none $PKGINST /opt/VirtualBox/$lib=legacy/$lib s
1262 done
1263 for lib in `ls -1 /opt/VirtualBox/amd64/legacy/`; do
1264 /usr/sbin/installf -c none $PKGINST /opt/VirtualBox/amd64/$lib=legacy/$lib s
1265 done
1266 fi
1267 fi
1268
1269 infoprint "Loading VirtualBox kernel modules..."
1270 install_drivers
1271
1272 if test "$?" -eq 0; then
1273 if test -f "$DIR_CONF/vboxnet.conf"; then
1274 # nwam/dhcpagent fix
1275 nwamfile="$PKG_INSTALL_ROOT/etc/nwam/llp"
1276 nwambackupfile=$nwamfile.vbox
1277 if test -f "$nwamfile"; then
1278 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
1279
1280 # add all vboxnet instances as static to nwam
1281 inst=0
1282 networkn=56
1283 while test "$inst" -ne 1; do
1284 echo "vboxnet$inst static 192.168.$networkn.1" >> $nwambackupfile
1285 inst=`expr $inst + 1`
1286 networkn=`expr $networkn + 1`
1287 done
1288 mv -f $nwambackupfile $nwamfile
1289 fi
1290
1291 # plumb and configure vboxnet0 for non-remote installs
1292 if test "$REMOTEINST" -eq 0; then
1293 plumb_net
1294 fi
1295 fi
1296
1297 if test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml" \
1298 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml" \
1299 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"\
1300 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-autostart.xml"; then
1301 infoprint "Configuring services..."
1302 if test "$REMOTEINST" -eq 1; then
1303 subprint "Skipped for targetted installs."
1304 else
1305 # Since S11 the way to import a manifest is via restarting manifest-import which is asynchronous and can
1306 # take a while to complete, using disable/enable -s doesn't work either. So we restart it, and poll in
1307 # 1 second intervals to see if our service has been successfully imported and timeout after 'cmax' seconds.
1308 $BIN_SVCADM restart svc:system/manifest-import:default
1309
1310 # Start ZoneAccess service, other services are disabled by default.
1311 start_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default" \
1312 "/var/svc/log/application-virtualbox-zoneaccess:default.log"
1313 fi
1314 fi
1315
1316 # Update mime and desktop databases to get the right menu entries
1317 # and icons. There is still some delay until the GUI picks it up,
1318 # but that cannot be helped.
1319 if test -d "$PKG_INSTALL_ROOT/usr/share/icons"; then
1320 infoprint "Installing MIME types and icons..."
1321 if test "$REMOTEINST" -eq 0; then
1322 /usr/bin/update-mime-database /usr/share/mime >/dev/null 2>&1
1323 /usr/bin/update-desktop-database -q 2>/dev/null
1324 else
1325 subprint "Skipped for targetted installs."
1326 fi
1327 fi
1328
1329 # Install python bindings for non-remote installs
1330 if test "$REMOTEINST" -eq 0; then
1331 if test -f "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py" || test -h "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py"; then
1332 PYTHONBIN=`which python 2> /dev/null`
1333 if test -f "$PYTHONBIN" || test -h "$PYTHONBIN"; then
1334 infoprint "Installing Python bindings..."
1335
1336 INSTALLEDIT=1
1337 PYTHONBIN=`which python2.4 2>/dev/null`
1338 install_python_bindings "$PYTHONBIN" "Python 2.4"
1339 if test "$?" -eq 0; then
1340 INSTALLEDIT=0
1341 fi
1342 PYTHONBIN=`which python2.5 2>/dev/null`
1343 install_python_bindings "$PYTHONBIN" "Python 2.5"
1344 if test "$?" -eq 0; then
1345 INSTALLEDIT=0
1346 fi
1347 PYTHONBIN=`which python2.6 2>/dev/null`
1348 install_python_bindings "$PYTHONBIN" "Python 2.6"
1349 if test "$?" -eq 0; then
1350 INSTALLEDIT=0
1351 fi
1352 PYTHONBIN=`which python2.7 2>/dev/null`
1353 install_python_bindings "$PYTHONBIN" "Python 2.7"
1354 if test "$?" -eq 0; then
1355 INSTALLEDIT=0
1356 fi
1357
1358 # remove files installed by Python build
1359 rm -rf $DIR_VBOXBASE/sdk/installer/build
1360
1361 if test "$INSTALLEDIT" -ne 0; then
1362 warnprint "No suitable Python version found. Required Python 2.4, 2.5, 2.6 or 2.7"
1363 warnprint "Skipped installing the Python bindings."
1364 fi
1365 else
1366 warnprint "Python not found, skipped installed Python bindings."
1367 fi
1368 fi
1369 else
1370 warnprint "Skipped installing Python bindings. Run, as root, 'vboxapisetup.py install' manually from the booted system."
1371 fi
1372
1373 update_boot_archive
1374
1375 return 0
1376 else
1377 errorprint "Failed to install drivers"
1378 exit 666
1379 fi
1380 return 1
1381}
1382
1383# preremove([fatal])
1384# failure: depends on [fatal]
1385preremove()
1386{
1387 fatal=$1
1388
1389 cleanup_install "$fatal"
1390
1391 remove_drivers "$fatal"
1392 if test "$?" -eq 0; then
1393 return 0;
1394 fi
1395 return 1
1396}
1397
1398
1399# And it begins...
1400if test "x${PKG_INSTALL_ROOT:=/}" != "x/"; then
1401 BASEDIR_OPT="-b $PKG_INSTALL_ROOT"
1402 BASEDIR_PKGOPT="-R $PKG_INSTALL_ROOT"
1403 REMOTEINST=1
1404fi
1405find_bins
1406check_root
1407check_isa
1408check_zone
1409get_sysinfo
1410
1411
1412# Get command line options
1413while test $# -gt 0;
1414do
1415 case "$1" in
1416 --postinstall | --preremove | --installdrivers | --removedrivers | --setupdrivers)
1417 drvop="$1"
1418 ;;
1419 --fatal)
1420 fatal="$FATALOP"
1421 ;;
1422 --silent)
1423 ISSILENT="$SILENTOP"
1424 ;;
1425 --ips)
1426 ISIPS="$IPSOP"
1427 ;;
1428 --altkerndir)
1429 # Use alternate kernel driver config folder (dev only)
1430 DIR_CONF="/usr/kernel/drv"
1431 ;;
1432 --sh-trace) # forwarded pkgadd -v
1433 set -x
1434 ;;
1435 --help)
1436 printusage
1437 exit 1
1438 ;;
1439 *)
1440 # Take a hard line on invalid options.
1441 errorprint "Invalid command line option: \"$1\""
1442 exit 1;
1443 ;;
1444 esac
1445 shift
1446done
1447
1448case "$drvop" in
1449--postinstall)
1450 check_module_arch
1451 postinstall
1452 ;;
1453--preremove)
1454 preremove "$fatal"
1455 ;;
1456--installdrivers)
1457 check_module_arch
1458 install_drivers
1459 ;;
1460--removedrivers)
1461 remove_drivers "$fatal"
1462 ;;
1463--setupdrivers)
1464 remove_drivers "$fatal"
1465 infoprint "Installing VirtualBox drivers:"
1466 install_drivers
1467 ;;
1468*)
1469 printusage
1470 exit 1
1471esac
1472
1473exit "$?"
1474
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette