VirtualBox

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

Last change on this file since 43429 was 43427, checked in by vboxsync, 12 years ago

Solaris/installer: Try handle the proposed PSARC versioning scheme for Solaris 12 kernel packages. This is not yet being used in the transitional period.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 39.7 KB
Line 
1#!/bin/sh
2# $Id: vboxconfig.sh 43427 2012-09-25 11:56:06Z vboxsync $
3
4#
5# VirtualBox Configuration Script, Solaris host.
6#
7# Copyright (C) 2009-2010 Oracle Corporation
8#
9# This file is part of VirtualBox Open Source Edition (OSE), as
10# available from http://www.virtualbox.org. This file is free software;
11# you can redistribute it and/or modify it under the terms of the GNU
12# General Public License (GPL) as published by the Free Software
13# Foundation, in version 2 as it comes in the "COPYING" file of the
14# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16#
17
18# Never use exit 2 or exit 20 etc., the return codes are used in
19# SRv4 postinstall procedures which carry special meaning. Just use exit 1 for failure.
20
21# LC_ALL should take precedence over LC_* and LANG but whatever...
22LC_ALL=C
23export LC_ALL
24
25LANG=C
26export LANG
27
28DIR_VBOXBASE="$PKG_INSTALL_ROOT/opt/VirtualBox"
29DIR_CONF="$PKG_INSTALL_ROOT/platform/i86pc/kernel/drv"
30DIR_MOD_32="$PKG_INSTALL_ROOT/platform/i86pc/kernel/drv"
31DIR_MOD_64="$DIR_MOD_32/amd64"
32
33# Default paths, these will be overridden by 'which' if they don't exist
34BIN_ADDDRV=/usr/sbin/add_drv
35BIN_REMDRV=/usr/sbin/rem_drv
36BIN_MODLOAD=/usr/sbin/modload
37BIN_MODUNLOAD=/usr/sbin/modunload
38BIN_MODINFO=/usr/sbin/modinfo
39BIN_DEVFSADM=/usr/sbin/devfsadm
40BIN_BOOTADM=/sbin/bootadm
41BIN_SVCADM=/usr/sbin/svcadm
42BIN_SVCCFG=/usr/sbin/svccfg
43BIN_SVCS=/usr/bin/svcs
44BIN_IFCONFIG=/sbin/ifconfig
45BIN_SVCS=/usr/bin/svcs
46BIN_ID=/usr/bin/id
47BIN_PKILL=/usr/bin/pkill
48
49# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
50MOD_VBOXDRV=vboxdrv
51DESC_VBOXDRV="Host"
52
53MOD_VBOXNET=vboxnet
54DESC_VBOXNET="NetAdapter"
55MOD_VBOXNET_INST=32
56
57MOD_VBOXFLT=vboxflt
58DESC_VBOXFLT="NetFilter (STREAMS)"
59
60MOD_VBOXBOW=vboxbow
61DESC_VBOXBOW="NetFilter (Crossbow)"
62
63MOD_VBOXUSBMON=vboxusbmon
64DESC_VBOXUSBMON="USBMonitor"
65
66MOD_VBOXUSB=vboxusb
67DESC_VBOXUSB="USB"
68
69UPDATEBOOTARCHIVE=0
70REMOTEINST=0
71FATALOP=fatal
72NULLOP=nulloutput
73SILENTOP=silent
74IPSOP=ips
75ISSILENT=
76ISIPS=
77
78infoprint()
79{
80 if test "$ISSILENT" != "$SILENTOP"; then
81 echo 1>&2 "$1"
82 fi
83}
84
85subprint()
86{
87 if test "$ISSILENT" != "$SILENTOP"; then
88 echo 1>&2 " - $1"
89 fi
90}
91
92warnprint()
93{
94 if test "$ISSILENT" != "$SILENTOP"; then
95 echo 1>&2 " * Warning!! $1"
96 fi
97}
98
99errorprint()
100{
101 echo 1>&2 "## $1"
102}
103
104helpprint()
105{
106 echo 1>&2 "$1"
107}
108
109printusage()
110{
111 helpprint "VirtualBox Configuration Script"
112 helpprint "usage: $0 <operation> [options]"
113 helpprint
114 helpprint "<operation> must be one of the following:"
115 helpprint " --postinstall Perform full post installation procedure"
116 helpprint " --preremove Perform full pre remove procedure"
117 helpprint " --installdrivers Only install the drivers"
118 helpprint " --removedrivers Only remove the drivers"
119 helpprint " --setupdrivers Setup drivers, reloads existing drivers"
120 helpprint
121 helpprint "[options] are one or more of the following:"
122 helpprint " --silent Silent mode"
123 helpprint " --fatal Don't continue on failure (required for postinstall)"
124 helpprint " --ips This is an IPS package postinstall/preremove"
125 helpprint " --altkerndir Use /usr/kernel/drv as the driver directory"
126 helpprint
127}
128
129# find_bin_path()
130# !! failure is always fatal
131find_bin_path()
132{
133 if test -z "$1"; then
134 errorprint "missing argument to find_bin_path()"
135 exit 1
136 fi
137
138 binfilename=`basename $1`
139 binfilepath=`which $binfilename 2> /dev/null`
140 if test -x "$binfilepath"; then
141 echo "$binfilepath"
142 return 0
143 else
144 errorprint "$1 missing or is not an executable"
145 exit 1
146 fi
147}
148
149# find_bins()
150# !! failure is always fatal
151find_bins()
152{
153 # Search only for binaries that might be in different locations
154 if test ! -x "$BIN_ID"; then
155 BIN_ID=`find_bin_path "$BIN_ID"`
156 fi
157
158 if test ! -x "$BIN_ADDDRV"; then
159 BIN_ADDDRV=`find_bin_path "$BIN_ADDDRV"`
160 fi
161
162 if test ! -x "$BIN_REMDRV"; then
163 BIN_REMDRV=`find_bin_path "$BIN_REMDRV"`
164 fi
165
166 if test ! -x "$BIN_MODLOAD"; then
167 BIN_MODLOAD=`check_bin_path "$BIN_MODLOAD"`
168 fi
169
170 if test ! -x "$BIN_MODUNLOAD"; then
171 BIN_MODUNLOAD=`find_bin_path "$BIN_MODUNLOAD"`
172 fi
173
174 if test ! -x "$BIN_MODINFO"; then
175 BIN_MODINFO=`find_bin_path "$BIN_MODINFO"`
176 fi
177
178 if test ! -x "$BIN_DEVFSADM"; then
179 BIN_DEVFSADM=`find_bin_path "$BIN_DEVFSADM"`
180 fi
181
182 if test ! -x "$BIN_BOOTADM"; then
183 BIN_BOOTADM=`find_bin_path "$BIN_BOOTADM"`
184 fi
185
186 if test ! -x "$BIN_SVCADM"; then
187 BIN_SVCADM=`find_bin_path "$BIN_SVCADM"`
188 fi
189
190 if test ! -x "$BIN_SVCCFG"; then
191 BIN_SVCCFG=`find_bin_path "$BIN_SVCCFG"`
192 fi
193
194 if test ! -x "$BIN_SVCS"; then
195 BIN_SVCS=`find_bin_path "$BIN_SVCS"`
196 fi
197
198 if test ! -x "$BIN_IFCONFIG"; then
199 BIN_IFCONFIG=`find_bin_path "$BIN_IFCONFIG"`
200 fi
201
202 if test ! -x "$BIN_PKILL"; then
203 BIN_PKILL=`find_bin_path "$BIN_PKILL"`
204 fi
205}
206
207# check_root()
208# !! failure is always fatal
209check_root()
210{
211 # Don't use "-u" option as some id binaries don't support it, instead
212 # rely on "uid=101(username) gid=10(groupname) groups=10(staff)" output
213 curuid=`$BIN_ID | cut -f 2 -d '=' | cut -f 1 -d '('`
214 if test "$curuid" -ne 0; then
215 errorprint "This script must be run with administrator privileges."
216 exit 1
217 fi
218}
219
220# get_sysinfo
221# cannot fail
222get_sysinfo()
223{
224 BIN_PKG=`which pkg 2> /dev/null`
225 if test -x "$BIN_PKG"; then
226 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -a name=pkg.fmri -o pkg.fmri pkg:/system/kernel 2> /dev/null`
227 if test -z "$PKGFMRI"; then
228 # Perhaps this is old pkg without '-a' option and/or system/kernel is missing and it's part of 'entire'
229 # Try fallback.
230 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -o pkg.fmri entire | head -1 2> /dev/null`
231 if test -z "$PKGFMRI"; then
232 # Perhaps entire is conflicting. Try using opensolaris/entire.
233 # Last fallback try.
234 PKGFMRI=`$BIN_PKG $BASEDIR_PKGOPT contents -H -t set -o pkg.fmri opensolaris.org/entire | head -1 2> /dev/null`
235 fi
236 fi
237 if test ! -z "$PKGFMRI"; then
238 # The format is "pkg://solaris/system/kernel@0.5.11,5.11-0.161:20110315T070332Z"
239 # or "pkg://solaris/system/kernel@5.12,5.11-5.12.0.0.0.4.1:20120908T030246Z"
240 # or "pkg://solaris/system/kernel@0.5.11,5.11-0.175.0.0.0.1.0:20111012T032837Z"
241 # or "pkg://solaris/system/kernel@5.12-5.12.0.0.0.9.1.3.0:20121012T032837Z"
242 STR_KERN_MAJOR=`echo "$PKGFMRI" | sed 's/^.*\@//;s/\,.*//'`
243 if test ! -z "$STR_KERN_MAJOR"; then
244 # The format is "0.5.11" or "5.12"
245 # Let us just hardcode these for now, instead of trying to do things more generically. It's not
246 # worth trying to bring more order to chaos as it's clear that the version numbering is subject to breakage
247 # as it has been seen in the past.
248 if test "$STR_KERN_MAJOR" = "5.12"; then
249 HOST_OS_MAJORVERSION="12"
250 elif test "$STR_KERN_MAJOR" = "0.5.11" || test "$STR_KERN_MAJOR" = "5.11"; then
251 HOST_OS_MAJORVERSION="11"
252 else
253 # This could be the PSARC/2012/240 naming scheme for S12.
254 # The format is "pkg://solaris/system/kernel@5.12-5.12.0.0.0.9.1.3.0:20121012T032837Z"
255 # The "5.12" following the "@" is the nominal version which we ignore for now as it is
256 # not set by most pkg(5) tools...
257 # STR_KERN_MAJOR is now of the format "5.12-5.12.0.0.0.9.1.3.0:20121012T032837Z" with '9' representing
258 # the build number.
259 BRANCH_VERSION=STR_KERN_MAJOR
260 HOST_OS_MAJORVERSION=`echo "$BRANCH_VERSION" | cut -f2 -d'-' | cut -f1,2 -d'.'`
261 if test "HOST_OS_MAJORVERSION" = "5.12"; then
262 HOST_OS_MINORVERSION=`echo "$BRANCH_VERSION" | cut -f2 -d'-' | cut -f6 -d'.'`
263 return 0
264 else
265 errorprint "Failed to parse the Solaris kernel major version."
266 exit 1
267 fi
268 fi
269
270 # This applies only to S11 and S12 where the transitional "@5.12," component version is
271 # still part of the pkg(5) package FMRI. The regular S12 will follow the PSARC/2012/240 naming scheme above.
272 STR_KERN_MINOR=`echo "$PKGFMRI" | sed 's/^.*\@//;s/\:.*//;s/.*,//'`
273 if test ! -z "$STR_KERN_MINOR"; then
274 # The HOST_OS_MINORVERSION is represented as follows:
275 # For S12 it represents the build numbers. e.g. for 4 : "5.11-5.12.0.0.0.4.1"
276 # 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"
277 if test "$HOST_OS_MAJOR_VERSION" -eq 12; then
278 HOST_OS_MINORVERSION=`echo "$STR_KERN_MINOR" | cut -f2 -d'-' | cut -f6 -d '.'`
279 elif test "$HOST_OS_MAJORVERSION" -eq 11; then
280 HOST_OS_MINORVERSION=`echo "$STR_KERN_MINOR" | cut -f2 -d'-' | cut -f2 -d '.'`
281 fi
282 else
283 errorprint "Failed to parse the Solaris kernel minor version."
284 exit 1
285 fi
286 else
287 errorprint "Failed to parse the Solaris kernel package version."
288 exit 1
289 fi
290 else
291 errorprint "Failed to detect the Solaris kernel package FMRI."
292 exit 1
293 fi
294 else
295 HOST_OS_MAJORVERSION=`uname -r`
296 if test -z "$HOST_OS_MAJORVERSION" || test "$HOST_OS_MAJORVERSION" != "5.10"; then
297 # S11 without 'pkg'?? Something's wrong... bail.
298 errorprint "Solaris $HOST_OS_MAJOR_VERSION detected without executable $BIN_PKG !? I are confused."
299 exit 1
300 fi
301 HOST_OS_MAJORVERSION="10"
302 if test "$REMOTEINST" -eq 0; then
303 # Use uname to verify it's S10.
304 # Major version is S10, Minor version is no longer relevant (or used), use uname -v so it gets something
305 # like "Generic_blah" for purely cosmetic purposes
306 HOST_OS_MINORVERSION=`uname -v`
307 else
308 # Remote installs from S10 local.
309 BIN_PKGCHK=`which pkgchk 2> /dev/null`
310 if test ! -x "$BIN_PKGCHK"; then
311 errorprint "Failed to find an executable pkgchk binary $BIN_PKGCHK."
312 errorprint "Cannot determine Solaris version on remote target $PKG_INSTALL_ROOT"
313 exit 1
314 fi
315
316 REMOTE_S10=`$BIN_PKGCHK -l -p /kernel/amd64/genunix $BASEDIR_PKGOPT 2> /dev/null | grep SUNWckr | tr -d ' \t'`
317 if test ! -z "$REMOTE_S10" && test "$REMOTE_S10" = "SUNWckr"; then
318 HOST_OS_MAJORVERSION="10"
319 HOST_OS_MINORVERSION=""
320 else
321 errorprint "Remote target $PKG_INSTALL_ROOT is not Solaris 10."
322 errorprint "Will not attempt to install to an unidentified remote target."
323 exit 1
324 fi
325 fi
326 fi
327}
328
329# check_zone()
330# !! failure is always fatal
331check_zone()
332{
333 currentzone=`zonename`
334 if test "$currentzone" != "global"; then
335 errorprint "This script must be run from the global zone."
336 exit 1
337 fi
338}
339
340# check_isa()
341# !! failure is always fatal
342check_isa()
343{
344 currentisa=`uname -i`
345 if test "$currentisa" = "i86xpv"; then
346 errorprint "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
347 exit 1
348 fi
349}
350
351# check_module_arch()
352# !! failure is always fatal
353check_module_arch()
354{
355 cputype=`isainfo -k`
356 if test "$cputype" != "amd64" && test "$cputype" != "i386"; then
357 errorprint "VirtualBox works only on i386/amd64 hosts, not $cputype"
358 exit 1
359 fi
360}
361
362# update_boot_archive()
363# cannot fail
364update_boot_archive()
365{
366 infoprint "Updating the boot archive..."
367 if test "$REMOTEINST" -eq 0; then
368 $BIN_BOOTADM update-archive > /dev/null
369 else
370 $BIN_BOOTADM update-archive -R "$PKG_INSTALL_ROOT" > /dev/null
371 fi
372 UPDATEBOOTARCHIVE=0
373}
374
375
376# module_added(modname)
377# returns 1 if added, 0 otherwise
378module_added()
379{
380 if test -z "$1"; then
381 errorprint "missing argument to module_added()"
382 exit 1
383 fi
384
385 # Add a space at end of module name to make sure we have a perfect match to avoid
386 # any substring matches: e.g "vboxusb" & "vboxusbmon"
387 loadentry=`cat "$PKG_INSTALL_ROOT/etc/name_to_major" | grep "$1 "`
388 if test -z "$loadentry"; then
389 return 1
390 fi
391 return 0
392}
393
394# module_loaded(modname)
395# returns 1 if loaded, 0 otherwise
396module_loaded()
397{
398 if test -z "$1"; then
399 errorprint "missing argument to module_loaded()"
400 exit 1
401 fi
402
403 modname=$1
404 # modinfo should now work properly since we prevent module autounloading.
405 loadentry=`$BIN_MODINFO | grep "$modname "`
406 if test -z "$loadentry"; then
407 return 1
408 fi
409 return 0
410}
411
412# add_driver(modname, moddesc, fatal, nulloutput, [driverperm])
413# failure: depends on "fatal"
414add_driver()
415{
416 if test -z "$1" || test -z "$2"; then
417 errorprint "missing argument to add_driver()"
418 exit 1
419 fi
420
421 modname="$1"
422 moddesc="$2"
423 fatal="$3"
424 nullop="$4"
425 modperm="$5"
426
427 if test -n "$modperm"; then
428 if test "$nullop" = "$NULLOP"; then
429 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname >/dev/null 2>&1
430 else
431 $BIN_ADDDRV $BASEDIR_OPT -m"$modperm" $modname
432 fi
433 else
434 if test "$nullop" = "$NULLOP"; then
435 $BIN_ADDDRV $BASEDIR_OPT $modname >/dev/null 2>&1
436 else
437 $BIN_ADDDRV $BASEDIR_OPT $modname
438 fi
439 fi
440
441 if test $? -ne 0; then
442 subprint "Adding: $moddesc module ...FAILED!"
443 if test "$fatal" = "$FATALOP"; then
444 exit 1
445 fi
446 return 1
447 elif test "$REMOTEINST" -eq 1 && test "$?" -eq 0; then
448 subprint "Added: $moddesc driver"
449 fi
450 return 0
451}
452
453# rem_driver(modname, moddesc, [fatal])
454# failure: depends on [fatal]
455rem_driver()
456{
457 if test -z "$1" || test -z "$2"; then
458 errorprint "missing argument to rem_driver()"
459 exit 1
460 fi
461
462 modname=$1
463 moddesc=$2
464 fatal=$3
465
466 module_added $modname
467 if test "$?" -eq 0; then
468 UPDATEBOOTARCHIVE=1
469 if test "$ISIPS" != "$IPSOP"; then
470 $BIN_REMDRV $BASEDIR_OPT $modname
471 else
472 $BIN_REMDRV $BASEDIR_OPT $modname >/dev/null 2>&1
473 fi
474 # for remote installs, don't bother with return values of rem_drv
475 if test $? -eq 0; then
476 subprint "Removed: $moddesc module"
477 return 0
478 else
479 subprint "Removing: $moddesc ...FAILED!"
480 if test "$fatal" = "$FATALOP"; then
481 exit 1
482 fi
483 return 1
484 fi
485 fi
486}
487
488# unload_module(modname, moddesc, [fatal])
489# failure: fatal
490unload_module()
491{
492 if test -z "$1" || test -z "$2"; then
493 errorprint "missing argument to unload_module()"
494 exit 1
495 fi
496
497 # No-OP for non-root installs
498 if test "$REMOTEINST" -eq 1; then
499 return 0
500 fi
501
502 modname=$1
503 moddesc=$2
504 fatal=$3
505 modid=`$BIN_MODINFO | grep "$modname " | cut -f 1 -d ' ' `
506 if test -n "$modid"; then
507 $BIN_MODUNLOAD -i $modid
508 if test $? -eq 0; then
509 subprint "Unloaded: $moddesc module"
510 else
511 subprint "Unloading: $moddesc module ...FAILED!"
512 if test "$fatal" = "$FATALOP"; then
513 exit 1
514 fi
515 return 1
516 fi
517 fi
518 return 0
519}
520
521# load_module(modname, moddesc, [fatal])
522# pass "drv/modname" or "misc/vbi" etc.
523# failure: fatal
524load_module()
525{
526 if test -z "$1" || test -z "$2"; then
527 errorprint "missing argument to load_module()"
528 exit 1
529 fi
530
531 # No-OP for non-root installs
532 if test "$REMOTEINST" -eq 1; then
533 return 0
534 fi
535
536 modname=$1
537 moddesc=$2
538 fatal=$3
539 $BIN_MODLOAD -p $modname
540 if test $? -eq 0; then
541 subprint "Loaded: $moddesc module"
542 return 0
543 else
544 subprint "Loading: $moddesc ...FAILED!"
545 if test "$fatal" = "$FATALOP"; then
546 exit 1
547 fi
548 return 1
549 fi
550}
551
552load_vboxflt()
553{
554 if test -f "$DIR_CONF/vboxflt.conf"; then
555 add_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
556 load_module "drv/$MOD_VBOXFLT" "$DESC_VBOXFLT" "$FATALOP"
557 else
558 # For custom pkgs that optionally ship this module, let's not fail but just warn
559 warnprint "$DESC_VBOXFLT installation requested but not shipped in this package."
560 fi
561}
562
563load_vboxbow()
564{
565 if test -f "$DIR_CONF/vboxbow.conf"; then
566 add_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
567 load_module "drv/$MOD_VBOXBOW" "$DESC_VBOXBOW" "$FATALOP"
568 else
569 # For custom pkgs that optionally ship this module, let's not fail but just warn
570 warnprint "$DESC_VBOXBOW installation requested but not shipped in this package."
571 fi
572}
573
574# install_drivers()
575# !! failure is always fatal
576install_drivers()
577{
578 if test -f "$DIR_CONF/vboxdrv.conf"; then
579 if test -n "_HARDENED_"; then
580 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0600 root sys'"
581 else
582 add_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
583 fi
584 load_module "drv/$MOD_VBOXDRV" "$DESC_VBOXDRV" "$FATALOP"
585 else
586 errorprint "Extreme error! Missing $DIR_CONF/vboxdrv.conf, aborting."
587 return 1
588 fi
589
590 # Add vboxdrv to devlink.tab
591 if test -f "$PKG_INSTALL_ROOT/etc/devlink.tab"; then
592 sed -e '/name=vboxdrv/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
593 echo "type=ddi_pseudo;name=vboxdrv \D" >> "$PKG_INSTALL_ROOT/etc/devlink.vbox"
594 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
595 else
596 errorprint "Missing $PKG_INSTALL_ROOT/etc/devlink.tab, aborting install"
597 return 1
598 fi
599
600 # Create the device link for non-remote installs
601 if test "$REMOTEINST" -eq 0; then
602 /usr/sbin/devfsadm -i "$MOD_VBOXDRV"
603 if test $? -ne 0 || test ! -h "/dev/vboxdrv"; then
604 errorprint "Failed to create device link for $MOD_VBOXDRV."
605 exit 1
606 fi
607 fi
608
609 # Load VBoxNetAdp
610 if test -f "$DIR_CONF/vboxnet.conf"; then
611 add_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
612 load_module "drv/$MOD_VBOXNET" "$DESC_VBOXNET" "$FATALOP"
613 fi
614
615 # If both vboxinst_vboxbow and vboxinst_vboxflt exist, bail.
616 if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt" && test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow"; then
617 errorprint "Force-install files '$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt' and '$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow' both exist."
618 errorprint "Cannot load $DESC_VBOXFLT and $DESC_VBOXBOW drivers at the same time."
619 return 1
620 fi
621
622 # If the force-install files exists, install blindly
623 if test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxflt"; then
624 load_vboxflt
625 elif test -f "$PKG_INSTALL_ROOT/etc/vboxinst_vboxbow"; then
626 infoprint "here"
627 load_vboxbow
628 else
629 # If host is S10 or S11 (< snv_159) or vboxbow isn't shipped, then load vboxflt
630 if test "$HOST_OS_MAJORVERSION" -eq 10 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -lt 159) || test ! -f "$DIR_CONF/vboxbow.conf"; then
631 load_vboxflt
632 else
633 # For S11 snv_159+ load vboxbow
634 load_vboxbow
635 fi
636 fi
637
638 # Load VBoxUSBMon, VBoxUSB
639 if test -f "$DIR_CONF/vboxusbmon.conf" && test "$HOST_OS_MAJORVERSION" != "10"; then
640 # For VirtualBox 3.1 the new USB code requires Nevada > 123 i.e. S12+ or S11 b124+
641 if test "$HOST_OS_MAJORVERSION" -gt 11 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -gt 123); then
642 # Add a group "vboxuser" (8-character limit) for USB access.
643 # All users which need host USB-passthrough support will have to be added to this group.
644 groupadd vboxuser >/dev/null 2>&1
645
646 add_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP" "not-$NULLOP" "'* 0666 root sys'"
647 load_module "drv/$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$FATALOP"
648
649 chown root:vboxuser "/devices/pseudo/vboxusbmon@0:vboxusbmon"
650
651 # Add vboxusbmon to devlink.tab
652 sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
653 echo "type=ddi_pseudo;name=vboxusbmon \D" >> "$PKG_INSTALL_ROOT/etc/devlink.vbox"
654 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
655
656 # Create the device link for non-remote installs
657 if test "$REMOTEINST" -eq 0; then
658 /usr/sbin/devfsadm -i "$MOD_VBOXUSBMON"
659 if test $? -ne 0; then
660 errorprint "Failed to create device link for $MOD_VBOXUSBMON."
661 exit 1
662 fi
663 fi
664
665 # Add vboxusb if present
666 # This driver is special, we need it in the boot-archive but since there is no
667 # USB device to attach to now (it's done at runtime) it will fail to attach so
668 # redirect attaching failure output to /dev/null
669 if test -f "$DIR_CONF/vboxusb.conf"; then
670 add_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP" "$NULLOP"
671 load_module "drv/$MOD_VBOXUSB" "$DESC_VBOXUSB" "$FATALOP"
672 fi
673 else
674 warnprint "Solaris 11 build 124 or higher required for USB support. Skipped installing USB support."
675 fi
676 fi
677
678 return $?
679}
680
681# remove_drivers([fatal])
682# failure: depends on [fatal]
683remove_drivers()
684{
685 fatal=$1
686
687 # Remove vboxdrv from devlink.tab
688 if test -f "$PKG_INSTALL_ROOT/etc/devlink.tab"; then
689 devlinkfound=`cat "$PKG_INSTALL_ROOT/etc/devlink.tab" | grep vboxdrv`
690 if test -n "$devlinkfound"; then
691 sed -e '/name=vboxdrv/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
692 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
693 fi
694
695 # Remove vboxusbmon from devlink.tab
696 devlinkfound=`cat "$PKG_INSTALL_ROOT/etc/devlink.tab" | grep vboxusbmon`
697 if test -n "$devlinkfound"; then
698 sed -e '/name=vboxusbmon/d' "$PKG_INSTALL_ROOT/etc/devlink.tab" > "$PKG_INSTALL_ROOT/etc/devlink.vbox"
699 mv -f "$PKG_INSTALL_ROOT/etc/devlink.vbox" "$PKG_INSTALL_ROOT/etc/devlink.tab"
700 fi
701 fi
702
703 unload_module "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$fatal"
704 rem_driver "$MOD_VBOXUSB" "$DESC_VBOXUSB" "$fatal"
705
706 unload_module "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$fatal"
707 rem_driver "$MOD_VBOXUSBMON" "$DESC_VBOXUSBMON" "$fatal"
708
709 unload_module "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$fatal"
710 rem_driver "$MOD_VBOXFLT" "$DESC_VBOXFLT" "$fatal"
711
712 unload_module "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$fatal"
713 rem_driver "$MOD_VBOXBOW" "$DESC_VBOXBOW" "$fatal"
714
715 unload_module "$MOD_VBOXNET" "$DESC_VBOXNET" "$fatal"
716 rem_driver "$MOD_VBOXNET" "$DESC_VBOXNET" "$fatal"
717
718 unload_module "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$fatal"
719 rem_driver "$MOD_VBOXDRV" "$DESC_VBOXDRV" "$fatal"
720
721 # remove devlinks
722 if test -h "$PKG_INSTALL_ROOT/dev/vboxdrv" || test -f "$PKG_INSTALL_ROOT/dev/vboxdrv"; then
723 rm -f "$PKG_INSTALL_ROOT/dev/vboxdrv"
724 fi
725 if test -h "$PKG_INSTALL_ROOT/dev/vboxusbmon" || test -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"; then
726 rm -f "$PKG_INSTALL_ROOT/dev/vboxusbmon"
727 fi
728
729 # unpatch nwam/dhcpagent fix
730 nwamfile="$PKG_INSTALL_ROOT/etc/nwam/llp"
731 nwambackupfile=$nwamfile.vbox
732 if test -f "$nwamfile"; then
733 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
734 mv -f $nwambackupfile $nwamfile
735 fi
736
737 # remove netmask configuration
738 if test -h "$PKG_INSTALL_ROOT/etc/netmasks"; then
739 nmaskfile="$PKG_INSTALL_ROOT/etc/inet/netmasks"
740 else
741 nmaskfile="$PKG_INSTALL_ROOT/etc/netmasks"
742 fi
743 nmaskbackupfile=$nmaskfile.vbox
744 if test -f "$nmaskfile"; then
745 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
746 mv -f $nmaskbackupfile $nmaskfile
747 fi
748
749 if test $UPDATEBOOTARCHIVE -eq 1; then
750 update_boot_archive
751 fi
752
753 return 0
754}
755
756# install_python_bindings(pythonbin)
757# remarks: changes pwd
758# failure: non fatal
759install_python_bindings()
760{
761 # The python binary might not be there, so just exit silently
762 if test -z "$1"; then
763 return 0
764 fi
765
766 if test -z "$2"; then
767 errorprint "missing argument to install_python_bindings"
768 exit 1
769 fi
770
771 pythonbin=$1
772 pythondesc=$2
773 if test -x "$pythonbin"; then
774 VBOX_INSTALL_PATH="$DIR_VBOXBASE"
775 export VBOX_INSTALL_PATH
776 cd $DIR_VBOXBASE/sdk/installer
777 $pythonbin ./vboxapisetup.py install > /dev/null
778 if test "$?" -eq 0; then
779 subprint "Installed: Bindings for $pythondesc"
780 fi
781 return 0
782 fi
783 return 1
784}
785
786# stop_process(processname)
787# failure: depends on [fatal]
788stop_process()
789{
790 if test -z "$1"; then
791 errorprint "missing argument to stop_process()"
792 exit 1
793 fi
794
795 procname=$1
796 procpid=`ps -eo pid,fname | grep $procname | grep -v grep | awk '{ print $1 }'`
797 if test ! -z "$procpid" && test "$procpid" -ge 0; then
798 $BIN_PKILL "$procname"
799 sleep 2
800 procpid=`ps -eo pid,fname | grep $procname | grep -v grep | awk '{ print $1 }'`
801 if test ! -z "$procpid" && test "$procpid" -ge 0; then
802 subprint "Terminating: $procname ...FAILED!"
803 if test "$fatal" = "$FATALOP"; then
804 exit 1
805 fi
806 else
807 subprint "Terminated: $procname"
808 fi
809 fi
810}
811
812# start_service(servicename, shortFMRI pretty printing, full FMRI, log-file path)
813# failure: non-fatal
814start_service()
815{
816 if test -z "$1" || test -z "$2" || test -z "$3" || test -z "$4"; then
817 errorprint "missing argument to enable_service()"
818 exit 1
819 fi
820
821 # Since S11 the way to import a manifest is via restarting manifest-import which is asynchronous and can
822 # take a while to complete, using disable/enable -s doesn't work either. So we restart it, and poll in
823 # 1 second intervals to see if our service has been successfully imported and timeout after 'cmax' seconds.
824 cmax=32
825 cslept=0
826 success=0
827
828 $BIN_SVCS "$3" >/dev/null 2>&1
829 while test $? -ne 0;
830 do
831 sleep 1
832 cslept=`expr $cslept + 1`
833 if test "$cslept" -eq "$cmax"; then
834 success=1
835 break
836 fi
837 $BIN_SVCS "$3" >/dev/null 2>&1
838 done
839 if test "$success" -eq 0; then
840 $BIN_SVCADM enable -s "$3"
841 if test "$?" -eq 0; then
842 subprint "Loaded: $1"
843 return 0
844 else
845 warnprint "Loading $1 ...FAILED."
846 warnprint "Refer $4 for details."
847 fi
848 else
849 warnprint "Importing $1 ...FAILED."
850 warnprint "Refer /var/svc/log/system-manifest-import:default.log for details."
851 fi
852 return 1
853}
854
855
856# stop_service(servicename, shortFMRI-suitable for grep, full FMRI)
857# failure: non fatal
858stop_service()
859{
860 if test -z "$1" || test -z "$2" || test -z "$3"; then
861 errorprint "missing argument to stop_service()"
862 exit 1
863 fi
864 servicefound=`$BIN_SVCS -a | grep "$2" 2>/dev/null`
865 if test ! -z "$servicefound"; then
866 $BIN_SVCADM disable -s "$3"
867 # Don't delete the manifest, this is handled by the manifest class action
868 # $BIN_SVCCFG delete "$3"
869 if test "$?" -eq 0; then
870 subprint "Unloaded: $1"
871 else
872 subprint "Unloading: $1 ...ERROR(S)."
873 fi
874 fi
875}
876
877
878# cleanup_install([fatal])
879# failure: depends on [fatal]
880cleanup_install()
881{
882 fatal=$1
883
884 # No-Op for remote installs
885 if test "$REMOTEINST" -eq 1; then
886 return 0
887 fi
888
889 # stop the services
890 stop_service "Web service" "virtualbox/webservice" "svc:/application/virtualbox/webservice:default"
891 stop_service "Balloon control service" "virtualbox/balloonctrl" "svc:/application/virtualbox/balloonctrl:default"
892 stop_service "Autostart service" "virtualbox/autostart" "svc:/application/virtualbox/autostart:default"
893 stop_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default"
894
895 # unplumb all vboxnet instances for non-remote installs
896 inst=0
897 while test $inst -ne $MOD_VBOXNET_INST; do
898 vboxnetup=`$BIN_IFCONFIG vboxnet$inst >/dev/null 2>&1`
899 if test "$?" -eq 0; then
900 $BIN_IFCONFIG vboxnet$inst unplumb
901 if test "$?" -ne 0; then
902 errorprint "VirtualBox NetAdapter 'vboxnet$inst' couldn't be unplumbed (probably in use)."
903 if test "$fatal" = "$FATALOP"; then
904 exit 1
905 fi
906 fi
907 fi
908
909 # unplumb vboxnet0 ipv6
910 vboxnetup=`$BIN_IFCONFIG vboxnet$inst inet6 >/dev/null 2>&1`
911 if test "$?" -eq 0; then
912 $BIN_IFCONFIG vboxnet$inst inet6 unplumb
913 if test "$?" -ne 0; then
914 errorprint "VirtualBox NetAdapter 'vboxnet$inst' IPv6 couldn't be unplumbed (probably in use)."
915 if test "$fatal" = "$FATALOP"; then
916 exit 1
917 fi
918 fi
919 fi
920
921 inst=`expr $inst + 1`
922 done
923
924 # Stop our other daemons, non-fatal
925 stop_process VBoxSVC
926 stop_process VBoxNetDHCP
927}
928
929
930# postinstall()
931# !! failure is always fatal
932postinstall()
933{
934 infoprint "Detected Solaris $HOST_OS_MAJORVERSION Version $HOST_OS_MINORVERSION"
935 infoprint "Loading VirtualBox kernel modules..."
936 install_drivers
937
938 if test "$?" -eq 0; then
939 if test -f "$DIR_CONF/vboxnet.conf"; then
940 # nwam/dhcpagent fix
941 nwamfile="$PKG_INSTALL_ROOT/etc/nwam/llp"
942 nwambackupfile=$nwamfile.vbox
943 if test -f "$nwamfile"; then
944 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
945
946 # add all vboxnet instances as static to nwam
947 inst=0
948 networkn=56
949 while test $inst -ne 1; do
950 echo "vboxnet$inst static 192.168.$networkn.1" >> $nwambackupfile
951 inst=`expr $inst + 1`
952 networkn=`expr $networkn + 1`
953 done
954 mv -f $nwambackupfile $nwamfile
955 fi
956
957 # plumb and configure vboxnet0 for non-remote installs
958 if test "$REMOTEINST" -eq 0; then
959 # S11 175a renames vboxnet0 as 'netX', undo this and rename it back (S12+ or S11 b175+)
960 if test "$HOST_OS_MAJORVERSION" -gt 11 || (test "$HOST_OS_MAJORVERSION" -eq 11 && test "$HOST_OS_MINORVERSION" -gt 174); then
961 vanityname=`dladm show-phys -po link,device | grep vboxnet0 | cut -f1 -d':'`
962 if test $? -eq 0 && test ! -z "$vanityname" && test "$vanityname" != "vboxnet0"; then
963 dladm rename-link "$vanityname" vboxnet0
964 if test $? -ne 0; then
965 errorprint "Failed to rename vanity interface ($vanityname) to vboxnet0"
966 fi
967 fi
968 fi
969
970 $BIN_IFCONFIG vboxnet0 plumb
971 $BIN_IFCONFIG vboxnet0 up
972 if test "$?" -eq 0; then
973 $BIN_IFCONFIG vboxnet0 192.168.56.1 netmask 255.255.255.0 up
974
975 # /etc/netmasks is a symlink, older installers replaced this with
976 # a copy of the actual file, repair that behaviour here.
977 recreatelink=0
978 if test -h "$PKG_INSTALL_ROOT/etc/netmasks"; then
979 nmaskfile="$PKG_INSTALL_ROOT/etc/inet/netmasks"
980 else
981 nmaskfile="$PKG_INSTALL_ROOT/etc/netmasks"
982 recreatelink=1
983 fi
984
985 # add the netmask to stay persistent across host reboots
986 nmaskbackupfile=$nmaskfile.vbox
987 if test -f $nmaskfile; then
988 sed -e '/#VirtualBox_SectionStart/,/#VirtualBox_SectionEnd/d' $nmaskfile > $nmaskbackupfile
989
990 if test $recreatelink -eq 1; then
991 # Check after removing our settings if /etc/netmasks is identifcal to /etc/inet/netmasks
992 anydiff=`diff $nmaskbackupfile "$PKG_INSTALL_ROOT/etc/inet/netmasks"`
993 if test ! -z "$anydiff"; then
994 # User may have some custom settings in /etc/netmasks, don't overwrite /etc/netmasks!
995 recreatelink=2
996 fi
997 fi
998
999 echo "#VirtualBox_SectionStart" >> $nmaskbackupfile
1000 inst=0
1001 networkn=56
1002 while test $inst -ne 1; do
1003 echo "192.168.$networkn.0 255.255.255.0" >> $nmaskbackupfile
1004 inst=`expr $inst + 1`
1005 networkn=`expr $networkn + 1`
1006 done
1007 echo "#VirtualBox_SectionEnd" >> $nmaskbackupfile
1008 mv -f $nmaskbackupfile $nmaskfile
1009
1010 # Recreate /etc/netmasks as a link if necessary
1011 if test $recreatelink -eq 1; then
1012 cp -f "$PKG_INSTALL_ROOT/etc/netmasks" "$PKG_INSTALL_ROOT/etc/inet/netmasks"
1013 ln -sf ./inet/netmasks "$PKG_INSTALL_ROOT/etc/netmasks"
1014 elif test $recreatelink -eq 2; then
1015 warnprint "/etc/netmasks is a symlink (to /etc/inet/netmasks) that older"
1016 warnprint "VirtualBox installers incorrectly overwrote. Now the contents"
1017 warnprint "of /etc/netmasks and /etc/inet/netmasks differ, therefore "
1018 warnprint "VirtualBox will not attempt to overwrite /etc/netmasks as a"
1019 warnprint "symlink to /etc/inet/netmasks. Please resolve this manually"
1020 warnprint "by updating /etc/inet/netmasks and creating /etc/netmasks as a"
1021 warnprint "symlink to /etc/inet/netmasks"
1022 fi
1023 fi
1024 else
1025 # Should this be fatal?
1026 warnprint "Failed to bring up vboxnet0!!"
1027 fi
1028 fi
1029 fi
1030
1031 if test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml" \
1032 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml" \
1033 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"\
1034 || test -f "$PKG_INSTALL_ROOT/var/svc/manifest/application/virtualbox/virtualbox-autostart.xml"; then
1035 infoprint "Configuring services..."
1036 if test "$REMOTEINST" -eq 1; then
1037 subprint "Skipped for targetted installs."
1038 else
1039 # Start ZoneAccess service, other services are disabled by default.
1040 $BIN_SVCADM restart svc:system/manifest-import:default
1041 start_service "Zone access service" "virtualbox/zoneaccess" "svc:/application/virtualbox/zoneaccess:default" \
1042 "/var/svc/log/application-virtualbox-zoneaccess:default.log"
1043 fi
1044 fi
1045
1046 # Update mime and desktop databases to get the right menu entries
1047 # and icons. There is still some delay until the GUI picks it up,
1048 # but that cannot be helped.
1049 if test -d "$PKG_INSTALL_ROOT/usr/share/icons"; then
1050 infoprint "Installing MIME types and icons..."
1051 if test "$REMOTEINST" -eq 0; then
1052 /usr/bin/update-mime-database /usr/share/mime >/dev/null 2>&1
1053 /usr/bin/update-desktop-database -q 2>/dev/null
1054 else
1055 subprint "Skipped for targetted installs."
1056 fi
1057 fi
1058
1059 # Install python bindings for non-remote installs
1060 if test "$REMOTEINST" -eq 0; then
1061 if test -f "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py" || test -h "$DIR_VBOXBASE/sdk/installer/vboxapisetup.py"; then
1062 PYTHONBIN=`which python 2> /dev/null`
1063 if test -f "$PYTHONBIN" || test -h "$PYTHONBIN"; then
1064 infoprint "Installing Python bindings..."
1065
1066 INSTALLEDIT=1
1067 PYTHONBIN=`which python2.4 2>/dev/null`
1068 install_python_bindings "$PYTHONBIN" "Python 2.4"
1069 if test "$?" -eq 0; then
1070 INSTALLEDIT=0
1071 fi
1072 PYTHONBIN=`which python2.5 2>/dev/null`
1073 install_python_bindings "$PYTHONBIN" "Python 2.5"
1074 if test "$?" -eq 0; then
1075 INSTALLEDIT=0
1076 fi
1077 PYTHONBIN=`which python2.6 2>/dev/null`
1078 install_python_bindings "$PYTHONBIN" "Python 2.6"
1079 if test "$?" -eq 0; then
1080 INSTALLEDIT=0
1081 fi
1082
1083 # remove files installed by Python build
1084 rm -rf $DIR_VBOXBASE/sdk/installer/build
1085
1086 if test "$INSTALLEDIT" -ne 0; then
1087 warnprint "No suitable Python version found. Required Python 2.4, 2.5 or 2.6."
1088 warnprint "Skipped installing the Python bindings."
1089 fi
1090 else
1091 warnprint "Python not found, skipped installed Python bindings."
1092 fi
1093 fi
1094 else
1095 warnprint "Skipped installing Python bindings. Run, as root, 'vboxapisetup.py install' manually from the booted system."
1096 fi
1097
1098 update_boot_archive
1099
1100 return 0
1101 else
1102 errorprint "Failed to install drivers"
1103 exit 666
1104 fi
1105 return 1
1106}
1107
1108# preremove([fatal])
1109# failure: depends on [fatal]
1110preremove()
1111{
1112 fatal=$1
1113
1114 cleanup_install "$fatal"
1115
1116 remove_drivers "$fatal"
1117 if test "$?" -eq 0; then
1118 return 0;
1119 fi
1120 return 1
1121}
1122
1123
1124# And it begins...
1125if test "x${PKG_INSTALL_ROOT:=/}" != "x/"; then
1126 BASEDIR_OPT="-b $PKG_INSTALL_ROOT"
1127 BASEDIR_PKGOPT="-R $PKG_INSTALL_ROOT"
1128 REMOTEINST=1
1129fi
1130find_bins
1131check_root
1132check_isa
1133check_zone
1134get_sysinfo
1135
1136
1137# Get command line options
1138while test $# -gt 0;
1139do
1140 case "$1" in
1141 --postinstall | --preremove | --installdrivers | --removedrivers | --setupdrivers)
1142 drvop="$1"
1143 ;;
1144 --fatal)
1145 fatal="$FATALOP"
1146 ;;
1147 --silent)
1148 ISSILENT="$SILENTOP"
1149 ;;
1150 --ips)
1151 ISIPS="$IPSOP"
1152 ;;
1153 --altkerndir)
1154 # Use alternate kernel driver config folder (dev only)
1155 DIR_CONF="/usr/kernel/drv"
1156 ;;
1157 --help)
1158 printusage
1159 exit 1
1160 ;;
1161 *)
1162 break
1163 ;;
1164 esac
1165 shift
1166done
1167
1168case "$drvop" in
1169--postinstall)
1170 check_module_arch
1171 postinstall
1172 ;;
1173--preremove)
1174 preremove "$fatal"
1175 ;;
1176--installdrivers)
1177 check_module_arch
1178 install_drivers
1179 ;;
1180--removedrivers)
1181 remove_drivers "$fatal"
1182 ;;
1183--setupdrivers)
1184 remove_drivers "$fatal"
1185 infoprint "Installing VirtualBox drivers:"
1186 install_drivers
1187 ;;
1188*)
1189 printusage
1190 exit 1
1191esac
1192
1193exit "$?"
1194
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