1 | #!/bin/bash
|
---|
2 | # innotek VirtualBox
|
---|
3 | # VirtualBox kernel module control script for Solaris.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2007-2008 innotek GmbH
|
---|
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 | VBOXDRVFILE=""
|
---|
17 | SILENTUNLOAD=""
|
---|
18 |
|
---|
19 | abort()
|
---|
20 | {
|
---|
21 | echo 1>&2 "$1"
|
---|
22 | exit 1
|
---|
23 | }
|
---|
24 |
|
---|
25 | info()
|
---|
26 | {
|
---|
27 | echo 1>&2 "$1"
|
---|
28 | }
|
---|
29 |
|
---|
30 | get_module_path()
|
---|
31 | {
|
---|
32 | cputype=`isainfo -k`
|
---|
33 | moduledir="/platform/i86pc/kernel/drv";
|
---|
34 | if test "$cputype" = "amd64"; then
|
---|
35 | moduledir=$moduledir/amd64
|
---|
36 | fi
|
---|
37 | modulepath=$moduledir/vboxdrv
|
---|
38 | if test -f "$modulepath"; then
|
---|
39 | VBOXDRVFILE="$modulepath"
|
---|
40 | else
|
---|
41 | VBOXDRVFILE=""
|
---|
42 | fi
|
---|
43 | }
|
---|
44 |
|
---|
45 | check_if_installed()
|
---|
46 | {
|
---|
47 | if test "$VBOXDRVFILE" -a -f "$VBOXDRVFILE"; then
|
---|
48 | return 0
|
---|
49 | fi
|
---|
50 | abort "VirtualBox kernel module (vboxdrv) not installed."
|
---|
51 | }
|
---|
52 |
|
---|
53 | module_loaded()
|
---|
54 | {
|
---|
55 | if test -f "/etc/name_to_major"; then
|
---|
56 | loadentry=`cat /etc/name_to_major | grep vboxdrv`
|
---|
57 | else
|
---|
58 | loadentry=`/usr/sbin/modinfo | grep vboxdrv`
|
---|
59 | fi
|
---|
60 | if test -z "$loadentry"; then
|
---|
61 | return 1
|
---|
62 | fi
|
---|
63 | return 0
|
---|
64 | }
|
---|
65 |
|
---|
66 | check_root()
|
---|
67 | {
|
---|
68 | if test `id -u` -ne 0; then
|
---|
69 | abort "This program must be run with administrator privileges. Aborting"
|
---|
70 | fi
|
---|
71 | }
|
---|
72 |
|
---|
73 | start()
|
---|
74 | {
|
---|
75 | if module_loaded; then
|
---|
76 | info "vboxdrv already loaded..."
|
---|
77 | else
|
---|
78 | /usr/sbin/add_drv -m'* 0666 root sys' vboxdrv
|
---|
79 | if ! module_loaded; then
|
---|
80 | abort "Failed to load vboxdrv."
|
---|
81 | elif test -c "/devices/pseudo/vboxdrv@0:vboxdrv"; then
|
---|
82 | info "Loaded vboxdrv."
|
---|
83 | else
|
---|
84 | stop
|
---|
85 | abort "Aborting due to attach failure."
|
---|
86 | fi
|
---|
87 | fi
|
---|
88 | }
|
---|
89 |
|
---|
90 | stop()
|
---|
91 | {
|
---|
92 | if module_loaded; then
|
---|
93 | /usr/sbin/rem_drv vboxdrv
|
---|
94 | info "Unloaded vboxdrv."
|
---|
95 | elif test -z "$SILENTUNLOAD"; then
|
---|
96 | info "vboxdrv not loaded."
|
---|
97 | fi
|
---|
98 | }
|
---|
99 |
|
---|
100 | restart()
|
---|
101 | {
|
---|
102 | stop
|
---|
103 | sync
|
---|
104 | start
|
---|
105 | return 0
|
---|
106 | }
|
---|
107 |
|
---|
108 | status()
|
---|
109 | {
|
---|
110 | if module_loaded; then
|
---|
111 | info "vboxdrv running."
|
---|
112 | else
|
---|
113 | info "vboxdrv stopped."
|
---|
114 | fi
|
---|
115 | }
|
---|
116 |
|
---|
117 | check_root
|
---|
118 | get_module_path
|
---|
119 | check_if_installed
|
---|
120 |
|
---|
121 | if test "$2" = "silentunload"; then
|
---|
122 | SILENTUNLOAD="$2"
|
---|
123 | fi
|
---|
124 |
|
---|
125 | case "$1" in
|
---|
126 | start)
|
---|
127 | start
|
---|
128 | ;;
|
---|
129 | stop)
|
---|
130 | stop
|
---|
131 | ;;
|
---|
132 | restart)
|
---|
133 | restart
|
---|
134 | ;;
|
---|
135 | status)
|
---|
136 | status
|
---|
137 | ;;
|
---|
138 | *)
|
---|
139 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
140 | exit 1
|
---|
141 | esac
|
---|
142 |
|
---|
143 | exit
|
---|
144 |
|
---|