1 | #! /bin/sh
|
---|
2 | # $Id: VBoxCreateUSBNode.sh 34726 2010-12-05 19:39:07Z vboxsync $ */
|
---|
3 | ## @file
|
---|
4 | # VirtualBox USB Proxy Service, Linux Specialization.
|
---|
5 | # udev helper for creating and removing device nodes for VirtualBox USB devices
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2010 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 | do_remove=0
|
---|
21 | case "$1" in "--remove")
|
---|
22 | do_remove=1; shift;;
|
---|
23 | esac
|
---|
24 | bus=`expr "$2" '/' 128 + 1`
|
---|
25 | device=`expr "$2" '%' 128 + 1`
|
---|
26 | class="$3"
|
---|
27 | group="$4"
|
---|
28 | if test "$class" -eq 9; then
|
---|
29 | exit 0
|
---|
30 | fi
|
---|
31 | devdir="`printf "/dev/vboxusb/%.3d" $bus`"
|
---|
32 | devpath="`printf "/dev/vboxusb/%.3d/%.3d" $bus $device`"
|
---|
33 | if test "$do_remove" -eq 0; then
|
---|
34 | if test -z "$group"; then
|
---|
35 | group="vboxusers"
|
---|
36 | fi
|
---|
37 | mkdir /dev/vboxusb -m 0750 2>/dev/null
|
---|
38 | chown root:$group /dev/vboxusb 2>/dev/null
|
---|
39 | mkdir "$devdir" -m 0750 2>/dev/null
|
---|
40 | chown root:$group "$devdir" 2>/dev/null
|
---|
41 | mknod "$devpath" c $1 $2 -m 0660 2>/dev/null
|
---|
42 | chown root:$group "$devpath" 2>/dev/null
|
---|
43 | else
|
---|
44 | rm -f "$devpath"
|
---|
45 | fi
|
---|
46 |
|
---|