1 | #!/bin/bash
|
---|
2 | # $Id: vboxguest.sh 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Guest Additions kernel module control script for FreeBSD.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2008-2024 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | #
|
---|
28 |
|
---|
29 | VBOXGUESTFILE=""
|
---|
30 | SILENTUNLOAD=""
|
---|
31 |
|
---|
32 | abort()
|
---|
33 | {
|
---|
34 | echo 1>&2 "$1"
|
---|
35 | exit 1
|
---|
36 | }
|
---|
37 |
|
---|
38 | info()
|
---|
39 | {
|
---|
40 | echo 1>&2 "$1"
|
---|
41 | }
|
---|
42 |
|
---|
43 | get_module_path()
|
---|
44 | {
|
---|
45 | moduledir="/boot/kernel";
|
---|
46 | modulepath=$moduledir/vboxguest.ko
|
---|
47 | if test -f "$modulepath"; then
|
---|
48 | VBOXGUESTFILE="$modulepath"
|
---|
49 | else
|
---|
50 | VBOXGUESTFILE=""
|
---|
51 | fi
|
---|
52 | }
|
---|
53 |
|
---|
54 | check_if_installed()
|
---|
55 | {
|
---|
56 | if test "$VBOXGUESTFILE" -a -f "$VBOXGUESTFILE"; then
|
---|
57 | return 0
|
---|
58 | fi
|
---|
59 | abort "VirtualBox kernel module (vboxguest) not installed."
|
---|
60 | }
|
---|
61 |
|
---|
62 | module_loaded()
|
---|
63 | {
|
---|
64 | loadentry=`kldstat | grep vboxguest`
|
---|
65 | if test -z "$loadentry"; then
|
---|
66 | return 1
|
---|
67 | fi
|
---|
68 | return 0
|
---|
69 | }
|
---|
70 |
|
---|
71 | check_root()
|
---|
72 | {
|
---|
73 | if test `id -u` -ne 0; then
|
---|
74 | abort "This program must be run with administrator privileges. Aborting"
|
---|
75 | fi
|
---|
76 | }
|
---|
77 |
|
---|
78 | start()
|
---|
79 | {
|
---|
80 | if module_loaded; then
|
---|
81 | info "vboxguest already loaded..."
|
---|
82 | else
|
---|
83 | /sbin/kldload vboxguest.ko
|
---|
84 | if ! module_loaded; then
|
---|
85 | abort "Failed to load vboxguest."
|
---|
86 | elif test -c "/dev/vboxguest"; then
|
---|
87 | info "Loaded vboxguest."
|
---|
88 | else
|
---|
89 | stop
|
---|
90 | abort "Aborting due to attach failure."
|
---|
91 | fi
|
---|
92 | fi
|
---|
93 | }
|
---|
94 |
|
---|
95 | stop()
|
---|
96 | {
|
---|
97 | if module_loaded; then
|
---|
98 | /sbin/kldunload vboxguest.ko
|
---|
99 | info "Unloaded vboxguest."
|
---|
100 | elif test -z "$SILENTUNLOAD"; then
|
---|
101 | info "vboxguest not loaded."
|
---|
102 | fi
|
---|
103 | }
|
---|
104 |
|
---|
105 | restart()
|
---|
106 | {
|
---|
107 | stop
|
---|
108 | sync
|
---|
109 | start
|
---|
110 | return 0
|
---|
111 | }
|
---|
112 |
|
---|
113 | status()
|
---|
114 | {
|
---|
115 | if module_loaded; then
|
---|
116 | info "vboxguest running."
|
---|
117 | else
|
---|
118 | info "vboxguest stopped."
|
---|
119 | fi
|
---|
120 | }
|
---|
121 |
|
---|
122 | check_root
|
---|
123 | get_module_path
|
---|
124 | check_if_installed
|
---|
125 |
|
---|
126 | if test "$2" = "silentunload"; then
|
---|
127 | SILENTUNLOAD="$2"
|
---|
128 | fi
|
---|
129 |
|
---|
130 | case "$1" in
|
---|
131 | start)
|
---|
132 | start
|
---|
133 | ;;
|
---|
134 | stop)
|
---|
135 | stop
|
---|
136 | ;;
|
---|
137 | restart)
|
---|
138 | restart
|
---|
139 | ;;
|
---|
140 | status)
|
---|
141 | status
|
---|
142 | ;;
|
---|
143 | *)
|
---|
144 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
145 | exit 1
|
---|
146 | esac
|
---|
147 |
|
---|
148 | exit
|
---|
149 |
|
---|