1 | #!/bin/sh
|
---|
2 | # Sun xVM VirtualBox
|
---|
3 | # VirtualBox Guest Additions kernel module control script for Solaris.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.org. This file is free software;
|
---|
9 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | # General Public License (GPL) as published by the Free Software
|
---|
11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
16 | # Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
17 | # additional information or have any questions.
|
---|
18 | #
|
---|
19 |
|
---|
20 | SILENTUNLOAD=""
|
---|
21 | MODNAME="vboxguest"
|
---|
22 | MODDIR32="/platform/i86pc/kernel/drv"
|
---|
23 | MODDIR64=$MODDIR32/amd64
|
---|
24 |
|
---|
25 | abort()
|
---|
26 | {
|
---|
27 | echo 1>&2 "$1"
|
---|
28 | exit 1
|
---|
29 | }
|
---|
30 |
|
---|
31 | info()
|
---|
32 | {
|
---|
33 | echo 1>&2 "$1"
|
---|
34 | }
|
---|
35 |
|
---|
36 | check_if_installed()
|
---|
37 | {
|
---|
38 | cputype=`isainfo -k`
|
---|
39 | modulepath="$MODDIR32/$MODNAME"
|
---|
40 | if test "$cputype" = "amd64"; then
|
---|
41 | modulepath="$MODDIR64/$MODNAME"
|
---|
42 | fi
|
---|
43 | if test -f "$modulepath"; then
|
---|
44 | return 0
|
---|
45 | fi
|
---|
46 | abort "VirtualBox kernel module ($MODNAME) NOT installed."
|
---|
47 | }
|
---|
48 |
|
---|
49 | module_loaded()
|
---|
50 | {
|
---|
51 | if test -f "/etc/name_to_major"; then
|
---|
52 | loadentry=`cat /etc/name_to_major | grep $MODNAME`
|
---|
53 | else
|
---|
54 | loadentry=`/usr/sbin/modinfo | grep $MODNAME`
|
---|
55 | fi
|
---|
56 | if test -z "$loadentry"; then
|
---|
57 | return 1
|
---|
58 | fi
|
---|
59 | return 0
|
---|
60 | }
|
---|
61 |
|
---|
62 | check_root()
|
---|
63 | {
|
---|
64 | if test `/usr/xpg4/bin/id -u` -ne 0; then
|
---|
65 | abort "This program must be run with administrator privileges. Aborting"
|
---|
66 | fi
|
---|
67 | }
|
---|
68 |
|
---|
69 | start_module()
|
---|
70 | {
|
---|
71 | if module_loaded; then
|
---|
72 | info "VirtualBox guest kernel module already loaded."
|
---|
73 | else
|
---|
74 | /usr/sbin/add_drv -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME
|
---|
75 | if test ! module_loaded; then
|
---|
76 | abort "## Failed to load VirtualBox guest kernel module."
|
---|
77 | elif test -c "/devices/pci@0,0/pci80ee,cafe@4:$MODNAME"; then
|
---|
78 | info "VirtualBox guest kernel module loaded."
|
---|
79 | else
|
---|
80 | stop
|
---|
81 | abort "Aborting due to attach failure."
|
---|
82 | fi
|
---|
83 | fi
|
---|
84 | }
|
---|
85 |
|
---|
86 | stop_module()
|
---|
87 | {
|
---|
88 | if module_loaded; then
|
---|
89 | /usr/sbin/rem_drv $MODNAME || abort "## Failed to unload VirtualBox guest kernel module."
|
---|
90 | info "VirtualBox guest kernel module unloaded."
|
---|
91 | elif test -z "$SILENTUNLOAD"; then
|
---|
92 | info "VirtualBox guest kernel module not loaded."
|
---|
93 | fi
|
---|
94 | }
|
---|
95 |
|
---|
96 | restart_module()
|
---|
97 | {
|
---|
98 | stop_module
|
---|
99 | sync
|
---|
100 | start_module
|
---|
101 | return 0
|
---|
102 | }
|
---|
103 |
|
---|
104 | status_module()
|
---|
105 | {
|
---|
106 | if module_loaded; then
|
---|
107 | info "Running."
|
---|
108 | else
|
---|
109 | info "Stopped."
|
---|
110 | fi
|
---|
111 | }
|
---|
112 |
|
---|
113 | check_root
|
---|
114 | check_if_installed
|
---|
115 |
|
---|
116 | if test "$2" = "silentunload"; then
|
---|
117 | SILENTUNLOAD="$2"
|
---|
118 | fi
|
---|
119 |
|
---|
120 | case "$1" in
|
---|
121 | start)
|
---|
122 | start_module
|
---|
123 | ;;
|
---|
124 | stop)
|
---|
125 | stop_module
|
---|
126 | ;;
|
---|
127 | restart)
|
---|
128 | restart_module
|
---|
129 | ;;
|
---|
130 | status)
|
---|
131 | status_module
|
---|
132 | ;;
|
---|
133 | *)
|
---|
134 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
135 | exit 1
|
---|
136 | esac
|
---|
137 |
|
---|
138 | exit 0
|
---|
139 |
|
---|