VirtualBox

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

Last change on this file since 38844 was 38016, checked in by vboxsync, 13 years ago

USB/Solaris: vboxuser group access constraint for USB devices.

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