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