updated on Tue Jan 17 12:00:36 UTC 2012
[aur-mirror.git] / virtualbox_bin_beta / vboxdrv.rc
blob0ef676a2e6c77766612357856024c4d12ccd60e2
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/vbox/vbox.cfg
6 . /etc/conf.d/vboxdrv
8 if [[ -n "$INSTALL_DIR" ]]; then
9 VBOXMANAGE="$INSTALL_DIR/VBoxManage"
10 BUILDVBOXDRV="$INSTALL_DIR/src/vboxhost/vboxdrv/build_in_tmp"
11 BUILDVBOXNETFLT="$INSTALL_DIR/src/vboxhost/vboxnetflt/build_in_tmp"
12 BUILDVBOXNETADP="$INSTALL_DIR/src/vboxhost/vboxnetadp/build_in_tmp"
13 else
14 echo "Missing /etc/vbox/vbox.cfg"
15 exit 0
18 # detection of dkms (if not disabled)
19 if [[ "$DISABLE_DKMS" =~ [yY][eE][sS] ]]; then
20 USE_DKMS=0
21 else
22 which dkms &>/dev/null
23 USE_DKMS=$((! $?))
26 # STARTBUILD cannot be used with dkms
27 (( USE_DKMS == 1 )) && START_BUILD=no
30 load() {
31 if [[ "$START_BUILD" =~ [yY][eE][sS] ]]; then
32 # check if module exists
33 c=$('find' "/lib/modules/$(uname -r)" -type f -regex '.*/vbox\(drv\|netadp\|netflt\).ko' | wc -l)
34 ((c == 0 )) && setup
36 stat_busy "Loading VirtualBox kernel modules"
37 # trivial loading
38 for module in vbox{drv,netadp,netflt}; do
39 modprobe $module &>/dev/null
40 done
41 # check
42 for module in vbox{drv,netadp,netflt}; do
43 if ! grep -q "^${module}" /proc/modules; then
44 stat_fail
45 return 1
47 done
48 add_daemon vboxdrv
49 stat_done
52 unload() {
53 stat_busy "Unloading VirtualBox kernel modules"
54 # trivial unload
55 for module in vbox{netflt,netadp,drv}; do
56 if grep -q "^${module}" /proc/modules; then
57 modprobe -r $module &>/dev/null
59 done
60 # check
61 for module in vbox{drv,netadp,netflt}; do
62 if grep -q "^${module}" /proc/modules; then
63 stat_fail
64 return 1
66 done
67 rm_daemon vboxdrv
68 stat_done
71 remove() {
72 if (( USE_DKMS == 1 )); then
73 status "Removing VirtualBox kernel modules with DKMS" dkms remove -m vboxhost -v "$INSTALL_VER" --all
74 else
75 stat_busy "Removing VirtualBox kernel modules"
76 find "/lib/modules/$(uname -r)" -type f -regex '.*/vbox\(drv\|netadp\|netflt\).ko' -delete
77 stat_done
81 setup() {
82 if (( USE_DKMS == 1 )); then
83 status "Adding VirtualBox kernel modules in DKMS" dkms add -m vboxhost -v "$INSTALL_VER"
84 status "Bulding VirtualBox kernel modules with DKMS" dkms build -m vboxhost -v "$INSTALL_VER"
85 status "Installing VirtualBox kernel modules with DKMS" dkms install -m vboxhost -v "$INSTALL_VER"
86 else
87 remove
88 stat_busy "Compiling VirtualBox kernel modules"
89 LOG="/tmp/vbox-install.log"
90 if ! $BUILDVBOXDRV \
91 --save-module-symvers /tmp/vboxdrv-Module.symvers \
92 --no-print-directory install > $LOG 2>&1; then
93 echo "Look at $LOG to find out what went wrong"
95 if ! $BUILDVBOXNETFLT \
96 --use-module-symvers /tmp/vboxdrv-Module.symvers \
97 --no-print-directory install >> $LOG 2>&1; then
98 echo "Look at $LOG to find out what went wrong"
100 if ! $BUILDVBOXNETADP \
101 --use-module-symvers /tmp/vboxdrv-Module.symvers \
102 --no-print-directory install >> $LOG 2>&1; then
103 echo "Look at $LOG to find out what went wrong"
105 depmod -A
106 stat_done
110 fixusb() {
111 # Build our device tree
112 for i in /sys/bus/usb/devices/*; do
113 if test -r "$i/dev"; then
114 dev="`cat "$i/dev" 2> /dev/null`"
115 major="`expr "$dev" : '\(.*\):' 2> /dev/null`"
116 minor="`expr "$dev" : '.*:\(.*\)' 2> /dev/null`"
117 class="`cat $i/bDeviceClass 2> /dev/null`"
118 sh "$INSTALL_DIR/VBoxCreateUSBNode.sh" "$major" "$minor" "$class" 2>/dev/null
120 done
123 case "$1" in
124 start)
125 load
127 stop)
128 unload
130 restart)
131 unload
132 load
134 setup)
135 setup
137 remove)
138 remove
140 fixusb)
141 fixusb
144 echo "usage: $0 {start|stop|restart|setup|remove|fixusb}"
145 esac
147 # vim:set ts=2 sw=2 ft=sh et: