VBoxCreateUSBNode.sh revision 0c3967e9709e62d96e8e9e078dd5a0df9c5125cd
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync#! /bin/sh
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync# $Id$ */
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync## @file
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync# VirtualBox USB Proxy Service, Linux Specialization.
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync# udev helper for creating and removing device nodes for VirtualBox USB devices
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync#
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync#
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync# Copyright (C) 2010 Oracle Corporation
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync#
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# available from http://www.virtualbox.org. This file is free software;
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# you can redistribute it and/or modify it under the terms of the GNU
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# General Public License (GPL) as published by the Free Software
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0c3967e9709e62d96e8e9e078dd5a0df9c5125cdvboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync#
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncdo_remove=0
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsynccase "$1" in "--remove")
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync do_remove=1; shift;;
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncesac
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncbus=`expr "$2" '/' 128 + 1`
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncdevice=`expr "$2" '%' 128 + 1`
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncclass="$3"
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsyncgroup="$4"
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncif test "$class" -eq 9; then
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync exit 0
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncfi
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncdevdir="`printf "/dev/vboxusb/%.3d" $bus`"
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncdevpath="`printf "/dev/vboxusb/%.3d/%.3d" $bus $device`"
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncif test "$do_remove" -eq 0; then
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync if test -z "$group"; then
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync group="vboxusers"
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync fi
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync mkdir /dev/vboxusb -m 0750 2>/dev/null
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync chown root:$group /dev/vboxusb 2>/dev/null
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync mkdir "$devdir" -m 0750 2>/dev/null
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync chown root:$group "$devdir" 2>/dev/null
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync mknod "$devpath" c $1 $2 -m 0660 2>/dev/null
c6adb272ec43d5eaadb1493cb2bf45f2f8adf588vboxsync chown root:$group "$devpath" 2>/dev/null
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncelse
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync rm -f "$devpath"
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsyncfi
5f709c846bb234a0319a5c1f17e5a994d88d7352vboxsync