VirtualBox

source: vbox/trunk/src/VBox/Additions/solaris/Installer/vboxguest.sh@ 85416

Last change on this file since 85416 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1#!/bin/sh
2# $Id: vboxguest.sh 82968 2020-02-04 10:35:17Z vboxsync $
3## @file
4# VirtualBox Guest Additions kernel module control script for Solaris.
5#
6
7#
8# Copyright (C) 2008-2020 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
28LC_ALL=C
29export LC_ALL
30
31LANG=C
32export LANG
33
34SILENTUNLOAD=""
35MODNAME="vboxguest"
36VFSMODNAME="vboxfs"
37VMSMODNAME="vboxms"
38MODDIR32="/usr/kernel/drv"
39MODDIR64="/usr/kernel/drv/amd64"
40VFSDIR32="/usr/kernel/fs"
41VFSDIR64="/usr/kernel/fs/amd64"
42
43abort()
44{
45 echo 1>&2 "## $1"
46 exit 1
47}
48
49info()
50{
51 echo 1>&2 "$1"
52}
53
54check_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
67module_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
82vboxguest_loaded()
83{
84 module_loaded $MODNAME
85 return $?
86}
87
88vboxfs_loaded()
89{
90 module_loaded $VFSMODNAME
91 return $?
92}
93
94vboxms_loaded()
95{
96 module_loaded $VMSMODNAME
97 return $?
98}
99
100check_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
112start_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
124stop_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
134start_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
148stop_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
161start_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
173stop_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
183status_module()
184{
185 if vboxguest_loaded; then
186 info "Running."
187 else
188 info "Stopped."
189 fi
190}
191
192stop_all()
193{
194 stop_vboxms
195 stop_vboxfs
196 stop_module
197 return 0
198}
199
200restart_all()
201{
202 stop_all
203 start_module
204 start_vboxfs
205 start_vboxms
206 return 0
207}
208
209check_root
210check_if_installed
211
212if test "$2" = "silentunload"; then
213 SILENTUNLOAD="$2"
214fi
215
216case "$1" in
217stopall)
218 stop_all
219 ;;
220restartall)
221 restart_all
222 ;;
223start)
224 start_module
225 start_vboxms
226 ;;
227stop)
228 stop_vboxms
229 stop_module
230 ;;
231status)
232 status_module
233 ;;
234vfsstart)
235 start_vboxfs
236 ;;
237vfsstop)
238 stop_vboxfs
239 ;;
240vmsstart)
241 start_vboxms
242 ;;
243vmsstop)
244 stop_vboxms
245 ;;
246*)
247 echo "Usage: $0 {start|stop|restart|status}"
248 exit 1
249esac
250
251exit 0
252
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette