VirtualBox

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

Last change on this file since 42433 was 41641, checked in by vboxsync, 13 years ago

Solaris/Installer: comment.

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