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