1 | #!/bin/sh
|
---|
2 | # $Id: vboxguest.sh 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Guest Additions kernel module control script for Solaris.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # The contents of this file may alternatively be used under the terms
|
---|
27 | # of the Common Development and Distribution License Version 1.0
|
---|
28 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
29 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
30 | # CDDL are applicable instead of those of the GPL.
|
---|
31 | #
|
---|
32 | # You may elect to license modified versions of this file under the
|
---|
33 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
34 | #
|
---|
35 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
36 | #
|
---|
37 |
|
---|
38 | LC_ALL=C
|
---|
39 | export LC_ALL
|
---|
40 |
|
---|
41 | LANG=C
|
---|
42 | export LANG
|
---|
43 |
|
---|
44 | SILENTUNLOAD=""
|
---|
45 | MODNAME="vboxguest"
|
---|
46 | VFSMODNAME="vboxfs"
|
---|
47 | VMSMODNAME="vboxms"
|
---|
48 | MODDIR32="/usr/kernel/drv"
|
---|
49 | MODDIR64="/usr/kernel/drv/amd64"
|
---|
50 | VFSDIR32="/usr/kernel/fs"
|
---|
51 | VFSDIR64="/usr/kernel/fs/amd64"
|
---|
52 |
|
---|
53 | abort()
|
---|
54 | {
|
---|
55 | echo 1>&2 "## $1"
|
---|
56 | exit 1
|
---|
57 | }
|
---|
58 |
|
---|
59 | info()
|
---|
60 | {
|
---|
61 | echo 1>&2 "$1"
|
---|
62 | }
|
---|
63 |
|
---|
64 | check_if_installed()
|
---|
65 | {
|
---|
66 | cputype=`isainfo -k`
|
---|
67 | modulepath="$MODDIR32/$MODNAME"
|
---|
68 | if test "$cputype" = "amd64"; then
|
---|
69 | modulepath="$MODDIR64/$MODNAME"
|
---|
70 | fi
|
---|
71 | if test -f "$modulepath"; then
|
---|
72 | return 0
|
---|
73 | fi
|
---|
74 | abort "VirtualBox kernel module ($MODNAME) NOT installed."
|
---|
75 | }
|
---|
76 |
|
---|
77 | module_loaded()
|
---|
78 | {
|
---|
79 | if test -z "$1"; then
|
---|
80 | abort "missing argument to module_loaded()"
|
---|
81 | fi
|
---|
82 |
|
---|
83 | modname=$1
|
---|
84 | # modinfo should now work properly since we prevent module autounloading.
|
---|
85 | loadentry=`/usr/sbin/modinfo | grep "$modname "`
|
---|
86 | if test -z "$loadentry"; then
|
---|
87 | return 1
|
---|
88 | fi
|
---|
89 | return 0
|
---|
90 | }
|
---|
91 |
|
---|
92 | vboxguest_loaded()
|
---|
93 | {
|
---|
94 | module_loaded $MODNAME
|
---|
95 | return $?
|
---|
96 | }
|
---|
97 |
|
---|
98 | vboxfs_loaded()
|
---|
99 | {
|
---|
100 | module_loaded $VFSMODNAME
|
---|
101 | return $?
|
---|
102 | }
|
---|
103 |
|
---|
104 | vboxms_loaded()
|
---|
105 | {
|
---|
106 | module_loaded $VMSMODNAME
|
---|
107 | return $?
|
---|
108 | }
|
---|
109 |
|
---|
110 | check_root()
|
---|
111 | {
|
---|
112 | # the reason we don't use "-u" is that some versions of id are old and do not
|
---|
113 | # support this option (eg. Solaris 10) and do not have a "--version" to check it either
|
---|
114 | # so go with the uglier but more generic approach
|
---|
115 | idbin=`which id`
|
---|
116 | isroot=`$idbin | grep "uid=0"`
|
---|
117 | if test -z "$isroot"; then
|
---|
118 | abort "This program must be run with administrator privileges. Aborting"
|
---|
119 | fi
|
---|
120 | }
|
---|
121 |
|
---|
122 | start_module()
|
---|
123 | {
|
---|
124 | /usr/sbin/add_drv -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME
|
---|
125 | if test ! vboxguest_loaded; then
|
---|
126 | abort "Failed to load VirtualBox guest kernel module."
|
---|
127 | elif test -c "/devices/pci@0,0/pci80ee,cafe@4:$MODNAME"; then
|
---|
128 | info "VirtualBox guest kernel module loaded."
|
---|
129 | else
|
---|
130 | info "VirtualBox guest kernel module failed to attach."
|
---|
131 | fi
|
---|
132 | }
|
---|
133 |
|
---|
134 | stop_module()
|
---|
135 | {
|
---|
136 | if vboxguest_loaded; then
|
---|
137 | /usr/sbin/rem_drv $MODNAME || abort "Failed to unload VirtualBox guest kernel module."
|
---|
138 | info "VirtualBox guest kernel module unloaded."
|
---|
139 | elif test -z "$SILENTUNLOAD"; then
|
---|
140 | info "VirtualBox guest kernel module not loaded."
|
---|
141 | fi
|
---|
142 | }
|
---|
143 |
|
---|
144 | start_vboxfs()
|
---|
145 | {
|
---|
146 | if vboxfs_loaded; then
|
---|
147 | info "VirtualBox FileSystem kernel module already loaded."
|
---|
148 | else
|
---|
149 | /usr/sbin/modload -p fs/$VFSMODNAME || abort "Failed to load VirtualBox FileSystem kernel module."
|
---|
150 | if test ! vboxfs_loaded; then
|
---|
151 | info "Failed to load VirtualBox FileSystem kernel module."
|
---|
152 | else
|
---|
153 | info "VirtualBox FileSystem kernel module loaded."
|
---|
154 | fi
|
---|
155 | fi
|
---|
156 | }
|
---|
157 |
|
---|
158 | stop_vboxfs()
|
---|
159 | {
|
---|
160 | if vboxfs_loaded; then
|
---|
161 | vboxfs_mod_id=`/usr/sbin/modinfo | grep $VFSMODNAME | cut -f 1 -d ' ' `
|
---|
162 | if test -n "$vboxfs_mod_id"; then
|
---|
163 | /usr/sbin/modunload -i $vboxfs_mod_id || abort "Failed to unload VirtualBox FileSystem module."
|
---|
164 | info "VirtualBox FileSystem kernel module unloaded."
|
---|
165 | fi
|
---|
166 | elif test -z "$SILENTUNLOAD"; then
|
---|
167 | info "VirtualBox FileSystem kernel module not loaded."
|
---|
168 | fi
|
---|
169 | }
|
---|
170 |
|
---|
171 | start_vboxms()
|
---|
172 | {
|
---|
173 | /usr/sbin/add_drv -m'* 0666 root sys' $VMSMODNAME
|
---|
174 | if test ! vboxms_loaded; then
|
---|
175 | abort "Failed to load VirtualBox pointer integration module."
|
---|
176 | elif test -c "/devices/pseudo/$VMSMODNAME@0:$VMSMODNAME"; then
|
---|
177 | info "VirtualBox pointer integration module loaded."
|
---|
178 | else
|
---|
179 | info "VirtualBox pointer integration module failed to attach."
|
---|
180 | fi
|
---|
181 | }
|
---|
182 |
|
---|
183 | stop_vboxms()
|
---|
184 | {
|
---|
185 | if vboxms_loaded; then
|
---|
186 | /usr/sbin/rem_drv $VMSMODNAME || abort "Failed to unload VirtualBox pointer integration module."
|
---|
187 | info "VirtualBox pointer integration module unloaded."
|
---|
188 | elif test -z "$SILENTUNLOAD"; then
|
---|
189 | info "VirtualBox pointer integration module not loaded."
|
---|
190 | fi
|
---|
191 | }
|
---|
192 |
|
---|
193 | status_module()
|
---|
194 | {
|
---|
195 | if vboxguest_loaded; then
|
---|
196 | info "Running."
|
---|
197 | else
|
---|
198 | info "Stopped."
|
---|
199 | fi
|
---|
200 | }
|
---|
201 |
|
---|
202 | stop_all()
|
---|
203 | {
|
---|
204 | stop_vboxms
|
---|
205 | stop_vboxfs
|
---|
206 | stop_module
|
---|
207 | return 0
|
---|
208 | }
|
---|
209 |
|
---|
210 | restart_all()
|
---|
211 | {
|
---|
212 | stop_all
|
---|
213 | start_module
|
---|
214 | start_vboxfs
|
---|
215 | start_vboxms
|
---|
216 | return 0
|
---|
217 | }
|
---|
218 |
|
---|
219 | check_root
|
---|
220 | check_if_installed
|
---|
221 |
|
---|
222 | if test "$2" = "silentunload"; then
|
---|
223 | SILENTUNLOAD="$2"
|
---|
224 | fi
|
---|
225 |
|
---|
226 | case "$1" in
|
---|
227 | stopall)
|
---|
228 | stop_all
|
---|
229 | ;;
|
---|
230 | restartall)
|
---|
231 | restart_all
|
---|
232 | ;;
|
---|
233 | start)
|
---|
234 | start_module
|
---|
235 | start_vboxms
|
---|
236 | ;;
|
---|
237 | stop)
|
---|
238 | stop_vboxms
|
---|
239 | stop_module
|
---|
240 | ;;
|
---|
241 | status)
|
---|
242 | status_module
|
---|
243 | ;;
|
---|
244 | vfsstart)
|
---|
245 | start_vboxfs
|
---|
246 | ;;
|
---|
247 | vfsstop)
|
---|
248 | stop_vboxfs
|
---|
249 | ;;
|
---|
250 | vmsstart)
|
---|
251 | start_vboxms
|
---|
252 | ;;
|
---|
253 | vmsstop)
|
---|
254 | stop_vboxms
|
---|
255 | ;;
|
---|
256 | *)
|
---|
257 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
258 | exit 1
|
---|
259 | esac
|
---|
260 |
|
---|
261 | exit 0
|
---|
262 |
|
---|