VirtualBox

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

Last change on this file since 40344 was 40193, checked in by vboxsync, 13 years ago

Additions/Solaris: locale fix.

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