VirtualBox

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

Last change on this file since 21774 was 21680, checked in by vboxsync, 15 years ago

Solaris/Installer: vboxconfig.sh (unused)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1#!/bin/sh
2# $Id: vboxconfig.sh 21680 2009-07-17 13:01:57Z vboxsync $
3
4# Sun VirtualBox
5# VirtualBox Configuration Script, Solaris host.
6#
7# Copyright (C) 2009 Sun Microsystems, Inc.
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# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18# Clara, CA 95054 USA or visit http://www.sun.com if you need
19# additional information or have any questions.
20#
21
22
23HOST_OS_VERSION=`uname -r`
24BIN_ADDDRV=/usr/sbin/add_drv
25BIN_REMDRV=/usr/sbin/rem_drv
26BIN_MODLOAD=/usr/sbin/modload
27BIN_MODUNLOAD=/usr/sbin/modunload
28BIN_MODINFO=/usr/sbin/modinfo
29BIN_DEVFSADM=/usr/sbin/devfsadm
30BIN_BOOTADM=/sbin/bootadm
31
32# "vboxdrv" is also used in sed lines here (change those as well if it ever changes)
33MOD_VBOXDRV=vboxdrv
34MOD_VBOXNET=vboxnet
35MOD_VBOXFLT=vboxflt
36MOD_VBI=vbi
37MOD_VBOXUSBMON=vboxusbmon
38FATALOP=fatal
39
40MODDIR32="/platform/i86pc/kernel/drv"
41MODDIR64=$MODDIR32/amd64
42
43
44infoprint()
45{
46 echo 1>&2 "$1"
47}
48
49success()
50{
51 echo 1>&2 "$1"
52}
53
54error()
55{
56 echo 1>&2 "## $1"
57}
58
59# check_bin_path()
60# !! failure is always fatal
61check_bin_paths()
62{
63 if test -z "$1"; then
64 error "missing argument to check_bin_path()"
65 exit 50
66 fi
67
68 if test ! -x "$1"; then
69 error "$1 missing or is not an executable"
70 exit 51
71 fi
72 return 0
73}
74
75# check_root()
76# !! failure is always fatal
77check_root()
78{
79 idbin=/usr/xpg4/bin/id
80 if test ! -f "$idbin"; then
81 found=`which id`
82 if test ! -f "$found" || test ! -h "$found"; then
83 error "Failed to find a suitable user id binary."
84 exit 1
85 else
86 idbin=$found
87 fi
88 fi
89
90 if test `$idbin -u` -ne 0; then
91 error "This script must be run with administrator privileges."
92 exit 2
93 fi
94}
95
96# check_zone()
97# !! failure is always fatal
98check_zone()
99{
100 currentzone=`zonename`
101 if test "$currentzone" != "global"; then
102 error "This script must be run from the global zone."
103 exit 3
104 fi
105}
106
107# check_isa()
108# !! failure is always fatal
109check_isa()
110{
111 currentisa=`uname -i`
112 if test "$currentisa" = "i86xpv"; then
113 error "VirtualBox cannot run under xVM Dom0! Fatal Error, Aborting installation!"
114 exit 4
115 fi
116}
117
118# check_module_arch()
119# !! failure is always fatal
120check_module_arch()
121{
122 cputype=`isainfo -k`
123 modulepath="$MODDIR32/$MOD_VBOXDRV"
124 if test "$cputype" = "amd64"; then
125 modulepath="$MODDIR64/$MOD_VBOXDRV"
126 elif test "$cputype" != "i386"; then
127 error "VirtualBox works only on i386/amd64 architectures, not $cputype"
128 exit 98
129 fi
130
131 # If things are where they should be, return success
132 if test -f "$modulepath" || test -h "$modulepath"; then
133 return 0
134 fi
135
136 # Something's screwed, let us go a step further and check if user has mixed up x86/amd64
137 # amd64 ISA, x86 kernel module??
138 if test "$cputype" = "amd64"; then
139 modulepath="$MODDIR32/$MOD_VBOXDRV"
140 if test -f "$modulepath"; then
141 error "Found 32-bit module instead of 64-bit. Please install the amd64 package!"
142 exit 97
143 fi
144 else
145 # x86 ISA, amd64 kernel module??
146 modulepath="$MODDIR64/$MOD_VBOXDRV"
147 if test -f "$modulepath"; then
148 error "Found 64-bit module instead of 32-bit. Please install the x86 package!"
149 exit 96
150 fi
151 fi
152
153 # Shouldn't really happen...
154 error "VirtualBox Host kernel module NOT installed."
155 exit 99
156}
157
158# module_added(modname)
159# returns 0 if added, 1 otherwise
160module_added()
161{
162 if test -z "$1"; then
163 error "missing argument to module_added()"
164 exit 5
165 fi
166
167 loadentry=`cat /etc/name_to_major | grep $1`
168 if test -z "$loadentry"; then
169 return 0
170 fi
171 return 1
172}
173
174# module_loaded(modname)
175# returns 1 if loaded, 0 otherwise
176module_loaded()
177{
178 if test -z "$1"; then
179 error "missing argument to module_loaded()"
180 exit 6
181 fi
182
183 modname=$1
184 # modinfo should now work properly since we prevent module autounloading
185 loadentry=`$BIN_MODINFO | grep $modname`
186 if test -z "$loadentry"; then
187 return 0
188 fi
189 return 1
190}
191
192# add_driver(modname, [driverperm], [fatal])
193# failure: depends on [fatal]
194add_driver()
195{
196 if test -z "$1"; then
197 error "missing argument to add_driver()"
198 exit 7
199 fi
200
201 modname=$1
202 modperm=$2
203 fatal=$3
204 if test -n "$modperm"; then
205 $BIN_ADDDRV -m'$modperm' $modname
206 else
207 $BIN_ADDDRV $modname
208 fi
209
210 if test $? -ne 0; then
211 error "Failed to load: $modname"
212 if test "$fatal" = "$FATALOP"; then
213 exit 8
214 fi
215 return 1
216 fi
217 return 0
218}
219
220# rem_driver(modname, [fatal])
221# failure: depends on [fatal]
222rem_driver()
223{
224 if test -z "$1"; then
225 error "missing argument to rem_driver()"
226 exit 9
227 fi
228
229 modname=$1
230 fatal=$2
231 module_added $modname
232 if test "$?" -eq 0; then
233 $BIN_REMDRV $modname
234 if test $? -eq 0; then
235 success "Removed: $modname successfully"
236 return 0
237 else
238 error "Failed to remove: $modname"
239 if test "$fatal" = "$FATALOP"; then
240 exit 10
241 fi
242 return 1
243 fi
244 fi
245}
246
247# unload_module(modname, [fatal])
248# failure: fatal
249unload_module()
250{
251 if test -z "$1"; then
252 error "missing argument to unload_module()"
253 exit 11
254 fi
255
256 modname=$1
257 fatal=$2
258 modid=`$BIN_MODINFO | grep $modname | cut -f 1 -d ' ' `
259 if test -n "$modid"; then
260 $BIN_MODUNLOAD -i $modid
261 if test $? -eq 0; then
262 success "Unloaded: $modname successfully"
263 else
264 error "Failed to unload: $modname"
265 if test "$fatal" = "$FATALOP"; then
266 exit 12
267 fi
268 return 1
269 fi
270 fi
271 return 0
272}
273
274# load_module(modname)
275# pass "drv/modname" or "misc/vbi" etc.
276# failure: fatal
277load_module()
278{
279 if test -z "$1"; then
280 error "missing argument to load_module()"
281 exit 14
282 fi
283
284 modname=$1
285 fatal=$2
286 $BIN_MODLOAD -p $modname
287 if test $? -eq 0; then
288 success "Loaded: $modname successfully"
289 return 0
290 else
291 error "Failed to load: $modname"
292 if test "$fatal" = "$FATALOP"; then
293 exit 15
294 fi
295 return 1
296 fi
297}
298
299# install_drivers()
300# !! failure is always fatal
301install_drivers()
302{
303 infoprint "Loading Host Driver..."
304 add_driver $MOD_VBOXDRV "* 0600 root sys" fatal
305 load_module $MOD_VBOXDRV fatal
306
307 # Add vboxdrv to devlink.tab
308 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
309 echo "type=ddi_pseudo;name=vboxdrv \D" >> /etc/devlink.vbox
310 mv -f /etc/devlink.vbox /etc/devlink.tab
311
312 # Create the device link
313 /usr/sbin/devfsadm -i $MOD_VBOXDRV
314
315 if test $? -eq 0; then
316
317 if test -f /platform/i86pc/kernel/drv/vboxnet.conf; then
318 infoprint "Loading NetAdapter..."
319 add_drv $MOD_VBOXNET fatal
320 load_module $MOD_VBOXNET fatal
321 fi
322
323 if test -f /platform/i86pc/kernel/drv/vboxflt.conf; then
324 infoprint "Loading NetFilter..."
325 add_driver $MOD_VBOXFLT fatal
326 load_module $MOD_VBOXFLT fatal
327 fi
328
329 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
330 infoprint "Loading USBMonitor..."
331 add_driver $MOD_VBOXUSBMON fatal
332 load_module $MOD_VBOXUSBMON fatal
333
334 # Add vboxusbmon to devlink.tab
335 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
336 echo "type=ddi_pseudo;name=vboxusbmon \D" >> /etc/devlink.vbox
337
338 # Create the device link
339 /usr/sbin/devfsadm -i $MOD_VBOXUSBMON
340 if test $? -ne 0; then
341 error "Failed to create device link for $MOD_VBOXUSBMON."
342 exit 16
343 fi
344 fi
345 else
346 error "Failed to create device link for $MOD_VBOXDRV."
347 exit 17
348 fi
349
350 return $?
351}
352
353# remove_all([fatal])
354# failure: depends on [fatal]
355remove_drivers()
356{
357 $fatal=$1
358 # Remove vboxdrv from devlink.tab
359 sed -e '/name=vboxdrv/d' /etc/devlink.tab > /etc/devlink.vbox
360 mv -f /etc/devlink.vbox /etc/devlink.tab
361
362 # Remove vboxusbmon from devlink.tab
363 sed -e '/name=vboxusbmon/d' /etc/devlink.tab > /etc/devlink.vbox
364 mv -f /etc/devlink.vbox /etc/devlink.tab
365
366 # USBMonitor might not even be installed, but anyway...
367 if test -f /platform/i86pc/kernel/drv/vboxusbmon.conf && test "$HOST_OS_VERSION" != "5.10"; then
368 infoprint "Unloading USBMonitor..."
369 unload_module $MOD_VBOXUSBMON "$fatal"
370 rem_driver $MOD_VBOXUSBMON "$fatal"
371 fi
372
373 infoprint "Unloading NetFilter..."
374 unload_module $MOD_VBOXFLT "$fatal"
375 rem_driver $MOD_VBOXFLT "$fatal"
376
377 infoprint "Unloading NetAdapter..."
378 unload_module $MOD_VBOXNET "$fatal"
379 rem_driver $MOD_VBOXNET "$fatal"
380
381 infoprint "Unloading Host Driver..."
382 unload_module $MOD_VBOXDRV "$fatal"
383 rem_driver $MOD_VBOXDRV "$fatal"
384
385 infoprint "Unloading VBI..."
386 unload_module $MOD_VBI "$fatal"
387
388 return 0
389}
390
391
392# post_install()
393# !! failure is always fatal
394post_install()
395{
396 # @todo install_drivers, update boot-archive start services, patch_files, update boot archive
397 infoprint "Loading VirtualBox kernel modules..."
398 install_drivers
399
400 infoprint "Updating the boot archive..."
401 $BIN_BOOTADM update-archive > /dev/null
402
403 if test "$?" -eq 0; then
404 # nwam/dhcpagent fix
405 nwamfile=/etc/nwam/llp
406 nwambackupfile=$nwamfile.vbox
407 if test -f "$nwamfile"; then
408 sed -e '/vboxnet/d' $nwamfile > $nwambackupfile
409 echo "vboxnet0 static 192.168.56.1" >> $nwambackupfile
410 mv -f $nwambackupfile $nwamfile
411 fi
412
413 return 0
414 else
415 error "Failed to update boot-archive"
416 exit 666
417 fi
418 return 1
419}
420
421# pre_remove([fatal])
422# failure: depends on [fatal]
423pre_remove()
424{
425 fatal=$1
426
427 # @todo halt services, remove_drivers, unpatch_files
428}
429
430
431# And it begins...
432check_root
433check_isa
434check_zone
435
436check_bin_path $BIN_ADDDRV
437check_bin_path $BIN_REMDRV
438check_bin_path $BIN_MODLOAD
439check_bin_path $BIN_MODUNLOAD
440check_bin_path $BIN_MODINFO
441check_bin_path $BIN_DEVFSADM
442check_bin_path $BIN_BOOTADM
443
444drvop=$1
445fatal=$2
446case "$drvop" in
447post_install)
448 check_module_arch
449 post_install
450 ;;
451pre_remove)
452 pre_remove "$fatal"
453 ;;
454install_drivers)
455 check_module_arch
456 install_drivers
457 ;;
458remove_drivers)
459 remove_drivers "$fatal"
460 ;;
461*)
462 echo "Usage: $0 post_install|pre_remove|install_drivers|remove_drivers [fatal]"
463 exit 13
464esac
465
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