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