VirtualBox

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

Last change on this file since 40040 was 39782, checked in by vboxsync, 13 years ago

Solaris/Installer: better warning text.

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