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