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