VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

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