1 | #!/bin/sh
|
---|
2 | # $Id: vboxguest.sh 101937 2023-11-07 12:15:59Z 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="${PKG_INSTALL_ROOT}/usr/kernel/drv"
|
---|
49 | MODDIR64="${PKG_INSTALL_ROOT}/usr/kernel/drv/amd64"
|
---|
50 | VFSDIR32="${PKG_INSTALL_ROOT}/usr/kernel/fs"
|
---|
51 | VFSDIR64="${PKG_INSTALL_ROOT}/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 | if test "$REMOTE_INST" -eq 1; then
|
---|
84 | return 1
|
---|
85 | fi
|
---|
86 |
|
---|
87 | modname=$1
|
---|
88 | # modinfo should now work properly since we prevent module autounloading.
|
---|
89 | loadentry=`/usr/sbin/modinfo | grep "$modname "`
|
---|
90 | if test -z "$loadentry"; then
|
---|
91 | return 1
|
---|
92 | fi
|
---|
93 | return 0
|
---|
94 | }
|
---|
95 |
|
---|
96 | vboxguest_loaded()
|
---|
97 | {
|
---|
98 | module_loaded $MODNAME
|
---|
99 | return $?
|
---|
100 | }
|
---|
101 |
|
---|
102 | vboxfs_loaded()
|
---|
103 | {
|
---|
104 | module_loaded $VFSMODNAME
|
---|
105 | return $?
|
---|
106 | }
|
---|
107 |
|
---|
108 | vboxms_loaded()
|
---|
109 | {
|
---|
110 | module_loaded $VMSMODNAME
|
---|
111 | return $?
|
---|
112 | }
|
---|
113 |
|
---|
114 | check_root()
|
---|
115 | {
|
---|
116 | # the reason we don't use "-u" is that some versions of id are old and do not
|
---|
117 | # support this option (eg. Solaris 10) and do not have a "--version" to check it either
|
---|
118 | # so go with the uglier but more generic approach
|
---|
119 | idbin=`which id`
|
---|
120 | isroot=`$idbin | grep "uid=0"`
|
---|
121 | if test -z "$isroot"; then
|
---|
122 | abort "This program must be run with administrator privileges. Aborting"
|
---|
123 | fi
|
---|
124 | }
|
---|
125 |
|
---|
126 | start_module()
|
---|
127 | {
|
---|
128 | if test "$REMOTE_INST" -eq 1; then
|
---|
129 | /usr/sbin/add_drv $BASEDIR_OPT -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME 2>/dev/null || \
|
---|
130 | abort "Failed to install VirtualBox guest kernel module into ${PKG_INSTALL_ROOT}."
|
---|
131 | info "VirtualBox guest kernel module installed."
|
---|
132 | return
|
---|
133 | fi
|
---|
134 |
|
---|
135 | /usr/sbin/add_drv -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME
|
---|
136 | if test ! vboxguest_loaded; then
|
---|
137 | abort "Failed to load VirtualBox guest kernel module."
|
---|
138 | elif test -c "/devices/pci@0,0/pci80ee,cafe@4:$MODNAME"; then
|
---|
139 | info "VirtualBox guest kernel module loaded."
|
---|
140 | else
|
---|
141 | info "VirtualBox guest kernel module failed to attach."
|
---|
142 | fi
|
---|
143 | }
|
---|
144 |
|
---|
145 | stop_module()
|
---|
146 | {
|
---|
147 | if test "$REMOTE_INST" -eq 1; then
|
---|
148 | /usr/sbin/rem_drv $BASEDIR_OPT $MODNAME || abort "Failed to uninstall VirtualBox guest kernel module."
|
---|
149 | info "VirtualBox guest kernel module uninstalled."
|
---|
150 | return
|
---|
151 | fi
|
---|
152 |
|
---|
153 | if vboxguest_loaded; then
|
---|
154 | /usr/sbin/rem_drv $MODNAME || abort "Failed to unload VirtualBox guest kernel module."
|
---|
155 | info "VirtualBox guest kernel module unloaded."
|
---|
156 | elif test -z "$SILENTUNLOAD"; then
|
---|
157 | info "VirtualBox guest kernel module not loaded."
|
---|
158 | fi
|
---|
159 | }
|
---|
160 |
|
---|
161 | start_vboxfs()
|
---|
162 | {
|
---|
163 | if test "$REMOTE_INST" -eq 1; then
|
---|
164 | return
|
---|
165 | fi
|
---|
166 |
|
---|
167 | if vboxfs_loaded; then
|
---|
168 | info "VirtualBox FileSystem kernel module already loaded."
|
---|
169 | else
|
---|
170 | /usr/sbin/modload -p fs/$VFSMODNAME || abort "Failed to load VirtualBox FileSystem kernel module."
|
---|
171 | if test ! vboxfs_loaded; then
|
---|
172 | info "Failed to load VirtualBox FileSystem kernel module."
|
---|
173 | else
|
---|
174 | info "VirtualBox FileSystem kernel module loaded."
|
---|
175 | fi
|
---|
176 | fi
|
---|
177 | }
|
---|
178 |
|
---|
179 | stop_vboxfs()
|
---|
180 | {
|
---|
181 | if test "$REMOTE_INST" -eq 1; then
|
---|
182 | return
|
---|
183 | fi
|
---|
184 |
|
---|
185 | if vboxfs_loaded; then
|
---|
186 | vboxfs_mod_id=`/usr/sbin/modinfo | grep $VFSMODNAME | cut -f 1 -d ' ' `
|
---|
187 | if test -n "$vboxfs_mod_id"; then
|
---|
188 | /usr/sbin/modunload -i $vboxfs_mod_id || abort "Failed to unload VirtualBox FileSystem module."
|
---|
189 | info "VirtualBox FileSystem kernel module unloaded."
|
---|
190 | fi
|
---|
191 | elif test -z "$SILENTUNLOAD"; then
|
---|
192 | info "VirtualBox FileSystem kernel module not loaded."
|
---|
193 | fi
|
---|
194 | }
|
---|
195 |
|
---|
196 | start_vboxms()
|
---|
197 | {
|
---|
198 | if test "$REMOTE_INST" -eq 1; then
|
---|
199 | /usr/sbin/add_drv $BASEDIR_OPT -m'* 0666 root sys' $VMSMODNAME 2>/dev/null ||
|
---|
200 | abort "Failed to install VirtualBox pointer integration module."
|
---|
201 | info "VirtualBox pointer integration module installed."
|
---|
202 | return
|
---|
203 | fi
|
---|
204 |
|
---|
205 | /usr/sbin/add_drv -m'* 0666 root sys' $VMSMODNAME
|
---|
206 | if test ! vboxms_loaded; then
|
---|
207 | abort "Failed to load VirtualBox pointer integration module."
|
---|
208 | elif test -c "/devices/pseudo/$VMSMODNAME@0:$VMSMODNAME"; then
|
---|
209 | info "VirtualBox pointer integration module loaded."
|
---|
210 | else
|
---|
211 | info "VirtualBox pointer integration module failed to attach."
|
---|
212 | fi
|
---|
213 | }
|
---|
214 |
|
---|
215 | stop_vboxms()
|
---|
216 | {
|
---|
217 | if test "$REMOTE_INST" -eq 1; then
|
---|
218 | /usr/sbin/rem_drv $BASEDIR_OPT $VMSMODNAME || abort "Failed to uninstall VirtualBox pointer integration module."
|
---|
219 | info "VirtualBox pointer integration module uninstalled."
|
---|
220 | return
|
---|
221 | fi
|
---|
222 |
|
---|
223 | if vboxms_loaded; then
|
---|
224 | /usr/sbin/rem_drv $VMSMODNAME || abort "Failed to unload VirtualBox pointer integration module."
|
---|
225 | info "VirtualBox pointer integration module unloaded."
|
---|
226 | elif test -z "$SILENTUNLOAD"; then
|
---|
227 | info "VirtualBox pointer integration module not loaded."
|
---|
228 | fi
|
---|
229 | }
|
---|
230 |
|
---|
231 | status_module()
|
---|
232 | {
|
---|
233 | if vboxguest_loaded; then
|
---|
234 | info "Running."
|
---|
235 | else
|
---|
236 | info "Stopped."
|
---|
237 | fi
|
---|
238 | }
|
---|
239 |
|
---|
240 | stop_all()
|
---|
241 | {
|
---|
242 | stop_vboxms
|
---|
243 | stop_vboxfs
|
---|
244 | stop_module
|
---|
245 | return 0
|
---|
246 | }
|
---|
247 |
|
---|
248 | restart_all()
|
---|
249 | {
|
---|
250 | stop_all
|
---|
251 | start_module
|
---|
252 | start_vboxfs
|
---|
253 | start_vboxms
|
---|
254 | return 0
|
---|
255 | }
|
---|
256 |
|
---|
257 | # "Remote" installs ('pkgadd -R') can skip many of the steps below.
|
---|
258 | REMOTE_INST=0
|
---|
259 | BASEDIR_OPT=""
|
---|
260 | if test "x${PKG_INSTALL_ROOT:-/}" != "x/"; then
|
---|
261 | BASEDIR_OPT="-b $PKG_INSTALL_ROOT"
|
---|
262 | REMOTE_INST=1
|
---|
263 | fi
|
---|
264 | export REMOTE_INST
|
---|
265 | export BASEDIR_OPT
|
---|
266 |
|
---|
267 | check_root
|
---|
268 | check_if_installed
|
---|
269 |
|
---|
270 | if test "$2" = "silentunload"; then
|
---|
271 | SILENTUNLOAD="$2"
|
---|
272 | fi
|
---|
273 |
|
---|
274 | case "$1" in
|
---|
275 | stopall)
|
---|
276 | stop_all
|
---|
277 | ;;
|
---|
278 | restartall)
|
---|
279 | restart_all
|
---|
280 | ;;
|
---|
281 | start)
|
---|
282 | start_module
|
---|
283 | start_vboxms
|
---|
284 | ;;
|
---|
285 | stop)
|
---|
286 | stop_vboxms
|
---|
287 | stop_module
|
---|
288 | ;;
|
---|
289 | status)
|
---|
290 | status_module
|
---|
291 | ;;
|
---|
292 | vfsstart)
|
---|
293 | start_vboxfs
|
---|
294 | ;;
|
---|
295 | vfsstop)
|
---|
296 | stop_vboxfs
|
---|
297 | ;;
|
---|
298 | vmsstart)
|
---|
299 | start_vboxms
|
---|
300 | ;;
|
---|
301 | vmsstop)
|
---|
302 | stop_vboxms
|
---|
303 | ;;
|
---|
304 | *)
|
---|
305 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
306 | exit 1
|
---|
307 | esac
|
---|
308 |
|
---|
309 | exit 0
|
---|
310 |
|
---|