VirtualBox

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

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

Additions/solaris: Fix for Solaris 12 kernel package FMRI.

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