1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # VirtualBox Guest Additions kernel module control script for Solaris.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2008-2010 Oracle Corporation
|
---|
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 | # The contents of this file may alternatively be used under the terms
|
---|
16 | # of the Common Development and Distribution License Version 1.0
|
---|
17 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
18 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
19 | # CDDL are applicable instead of those of the GPL.
|
---|
20 | #
|
---|
21 | # You may elect to license modified versions of this file under the
|
---|
22 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
23 | #
|
---|
24 |
|
---|
25 | SILENTUNLOAD=""
|
---|
26 | MODNAME="vboxguest"
|
---|
27 | VFSMODNAME="vboxfs"
|
---|
28 | MODDIR32="/usr/kernel/drv"
|
---|
29 | MODDIR64="/usr/kernel/drv/amd64"
|
---|
30 | VFSDIR32="/usr/kernel/fs"
|
---|
31 | VFSDIR64="/usr/kernel/fs/amd64"
|
---|
32 |
|
---|
33 | abort()
|
---|
34 | {
|
---|
35 | echo 1>&2 "## $1"
|
---|
36 | exit 1
|
---|
37 | }
|
---|
38 |
|
---|
39 | info()
|
---|
40 | {
|
---|
41 | echo 1>&2 "$1"
|
---|
42 | }
|
---|
43 |
|
---|
44 | check_if_installed()
|
---|
45 | {
|
---|
46 | cputype=`isainfo -k`
|
---|
47 | modulepath="$MODDIR32/$MODNAME"
|
---|
48 | if test "$cputype" = "amd64"; then
|
---|
49 | modulepath="$MODDIR64/$MODNAME"
|
---|
50 | fi
|
---|
51 | if test -f "$modulepath"; then
|
---|
52 | return 0
|
---|
53 | fi
|
---|
54 | abort "VirtualBox kernel module ($MODNAME) NOT installed."
|
---|
55 | }
|
---|
56 |
|
---|
57 | module_loaded()
|
---|
58 | {
|
---|
59 | if test -z "$1"; then
|
---|
60 | abort "missing argument to module_loaded()"
|
---|
61 | fi
|
---|
62 |
|
---|
63 | modname=$1
|
---|
64 | # modinfo should now work properly since we prevent module autounloading.
|
---|
65 | loadentry=`/usr/sbin/modinfo | grep "$modname "`
|
---|
66 | if test -z "$loadentry"; then
|
---|
67 | return 1
|
---|
68 | fi
|
---|
69 | return 0
|
---|
70 | }
|
---|
71 |
|
---|
72 | vboxguest_loaded()
|
---|
73 | {
|
---|
74 | module_loaded $MODNAME
|
---|
75 | return $?
|
---|
76 | }
|
---|
77 |
|
---|
78 | vboxfs_loaded()
|
---|
79 | {
|
---|
80 | module_loaded $VFSMODNAME
|
---|
81 | return $?
|
---|
82 | }
|
---|
83 |
|
---|
84 | check_root()
|
---|
85 | {
|
---|
86 | # the reason we don't use "-u" is that some versions of id are old and do not
|
---|
87 | # support this option (eg. Solaris 10) and do not have a "--version" to check it either
|
---|
88 | # so go with the uglier but more generic approach
|
---|
89 | idbin=`which id`
|
---|
90 | isroot=`$idbin | grep "uid=0"`
|
---|
91 | if test -z "$isroot"; then
|
---|
92 | abort "This program must be run with administrator privileges. Aborting"
|
---|
93 | fi
|
---|
94 | }
|
---|
95 |
|
---|
96 | start_module()
|
---|
97 | {
|
---|
98 | if vboxguest_loaded; then
|
---|
99 | info "VirtualBox guest kernel module already loaded."
|
---|
100 | else
|
---|
101 | /usr/sbin/add_drv -i'pci80ee,cafe' -m'* 0666 root sys' $MODNAME
|
---|
102 | sync
|
---|
103 | if test ! vboxguest_loaded; then
|
---|
104 | abort "Failed to load VirtualBox guest kernel module."
|
---|
105 | elif test -c "/devices/pci@0,0/pci80ee,cafe@4:$MODNAME"; then
|
---|
106 | info "VirtualBox guest kernel module loaded."
|
---|
107 | else
|
---|
108 | abort "Aborting due to attach failure."
|
---|
109 | fi
|
---|
110 | fi
|
---|
111 | }
|
---|
112 |
|
---|
113 | stop_module()
|
---|
114 | {
|
---|
115 | if vboxguest_loaded; then
|
---|
116 | /usr/sbin/rem_drv $MODNAME || abort "Failed to unload VirtualBox guest kernel module."
|
---|
117 | info "VirtualBox guest kernel module unloaded."
|
---|
118 | elif test -z "$SILENTUNLOAD"; then
|
---|
119 | info "VirtualBox guest kernel module not loaded."
|
---|
120 | fi
|
---|
121 | }
|
---|
122 |
|
---|
123 | start_vboxfs()
|
---|
124 | {
|
---|
125 | if vboxfs_loaded; then
|
---|
126 | info "VirtualBox FileSystem kernel module already loaded."
|
---|
127 | else
|
---|
128 | /usr/sbin/modload -p fs/$VFSMODNAME || abort "Failed to load VirtualBox FileSystem kernel module."
|
---|
129 | if test ! vboxfs_loaded; then
|
---|
130 | abort "Failed to load VirtualBox FileSystem kernel module."
|
---|
131 | else
|
---|
132 | info "VirtualBox FileSystem kernel module loaded."
|
---|
133 | fi
|
---|
134 | fi
|
---|
135 | }
|
---|
136 |
|
---|
137 | stop_vboxfs()
|
---|
138 | {
|
---|
139 | if vboxfs_loaded; then
|
---|
140 | vboxfs_mod_id=`/usr/sbin/modinfo | grep $VFSMODNAME | cut -f 1 -d ' ' `
|
---|
141 | if test -n "$vboxfs_mod_id"; then
|
---|
142 | /usr/sbin/modunload -i $vboxfs_mod_id || abort "Failed to unload VirtualBox FileSystem module."
|
---|
143 | info "VirtualBox FileSystem kernel module unloaded."
|
---|
144 | fi
|
---|
145 | elif test -z "$SILENTUNLOAD"; then
|
---|
146 | info "VirtualBox FileSystem kernel module not loaded."
|
---|
147 | fi
|
---|
148 | }
|
---|
149 |
|
---|
150 | status_module()
|
---|
151 | {
|
---|
152 | if vboxguest_loaded; then
|
---|
153 | info "Running."
|
---|
154 | else
|
---|
155 | info "Stopped."
|
---|
156 | fi
|
---|
157 | }
|
---|
158 |
|
---|
159 | stop_all()
|
---|
160 | {
|
---|
161 | stop_vboxfs
|
---|
162 | stop_module
|
---|
163 | return 0
|
---|
164 | }
|
---|
165 |
|
---|
166 | restart_all()
|
---|
167 | {
|
---|
168 | stop_all
|
---|
169 | start_module
|
---|
170 | start_vboxfs
|
---|
171 | return 0
|
---|
172 | }
|
---|
173 |
|
---|
174 | check_root
|
---|
175 | check_if_installed
|
---|
176 |
|
---|
177 | if test "$2" = "silentunload"; then
|
---|
178 | SILENTUNLOAD="$2"
|
---|
179 | fi
|
---|
180 |
|
---|
181 | case "$1" in
|
---|
182 | stopall)
|
---|
183 | stop_all
|
---|
184 | ;;
|
---|
185 | restartall)
|
---|
186 | restart_all
|
---|
187 | ;;
|
---|
188 | start)
|
---|
189 | start_module
|
---|
190 | ;;
|
---|
191 | stop)
|
---|
192 | stop_module
|
---|
193 | ;;
|
---|
194 | status)
|
---|
195 | status_module
|
---|
196 | ;;
|
---|
197 | vfsstart)
|
---|
198 | start_vboxfs
|
---|
199 | ;;
|
---|
200 | vfsstop)
|
---|
201 | stop_vboxfs
|
---|
202 | ;;
|
---|
203 | *)
|
---|
204 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
205 | exit 1
|
---|
206 | esac
|
---|
207 |
|
---|
208 | exit 0
|
---|
209 |
|
---|