[pvrusb2] udev rule and script for multiple WinTV-PVR-USB2 devices
rja at firkraag.rogera.net
rja at firkraag.rogera.net
Wed May 28 18:27:14 CDT 2008
After spending months checking dmesg to see which of my two
WinTV-PVR-USB2 devices would win the race for /dev/video0, I finally got
around to learning enough about udev rules to straighten out my mess. I
have Comcast Chicago cable with a single settopbox which is feeding the
composite of one of the boxes, while the other one is connected directly
to the coax and tuning the few (31 and decreasing) available unecrypted
analog cable channels. This is working under Fedora 8 with mythtv rpms
from atrpms. I tried to keep it simple so it only uses the shell and
grep. Fedora doesn't have a "video" group, so this is using "mythtv"
instead. I modified the mythbackend to run as "mythtv" instead of
"root". Other dists will probably want to change the GROUP and/or OWNER
or not use OWNER at all in the udev rule. The rule creates symlinks
for /dev/comcasta and /dev/comcastd for Analog and Digital. There are
comments in udev-pvrusb2 describing how to use it with mythtv-setup.
I'm sure the shell script could be better written, but it works for me.
This mythtv backend also has a Kworld ATSC-110 using /dev/video2, which
the script successfully leaves alone, so it should play nice with
other video devices.
The single line udev rule goes into /etc/udev/rules.d/94-local.rules
or whatever file your Linux distribution likes:
# local rules by rja for moria
# pvrusb2
# Create a symlink /dev/comcasta pointing to WinTV-PVR-USB2
# with serial sn-7653922 tuning comcast analog
# Create a symlink /dev/comcastd pointing to WinTV-PVR-USB2
# with serial sn-8257134 using composite comcast digital
KERNEL=="video[0-9]*", PROGRAM="/usr/local/bin/udev-pvrusb2 %m", \
SYMLINK+="%c", OWNER="mythtv", GROUP="mythtv"
The /usr/local/bin/udev-pvrusb2 script (don't forget to make it
executable) is:
#!/bin/sh
#
# program: udev-pvrusb2
#
# author: Roger J. Allen - rja at rogera.net
# Wed May 28 12:54:18 CDT 2008
#
# help udev assign consistent device name
# for WinTV-PVR-USB2 by its serial number
#
# argument 1 is a device minor number from udev
# test which sysfs entry matches this minor number
# output consistent device name for udev to create a symlink
#
# in mythtv-setup "Capture Card Setup"
# set "Video device:" to the symlink instead of /dev/video*
# for capturecard videodevice
#
# sn-7653922 returns "comcasta" for comcast analog tuner input
# udev will create /dev/comcasta symlink
# sn-8257134 returns "comcastd" for comcast digital composite input
# udev will create /dev/comcastd symlink
#
# udev rule for Fedora 8 with my custom owner and group settings
#
# KERNEL=="video[0-9]*", PROGRAM="/usr/local/bin/udev-pvrusb2 %m", \
# SYMLINK+="%c", OWNER="mythtv", GROUP="mythtv"
#
SerialNo1="sn-7653922"
Symlink1="comcasta"
SerialNo2="sn-8257134"
Symlink2="comcastd"
if [ 1 = $(grep -c $1 /sys/class/pvrusb2/$SerialNo1/v4l_minor_number) ]
then
echo $Symlink1
exit 0
elif [ 1 = $(grep -c $1 /sys/class/pvrusb2/$SerialNo2/v4l_minor_number) ]
then
echo $Symlink2
exit 0
fi
exit 1
Unless you break into my home and steal my WinTV-PVR-USB2s, change the
serial numbers and symlink names to taste. If you have more than two
devices, just modify the udev-pvrusb2 script.
You can mangle the bits any way you want. If you find that it needs
tweaking for other Linux distributions, then please post your fixes.
--
Roger J. Allen rja {at] rogera.net
-------------- next part --------------
# local rules by rja for moria
# pvrusb2
# Create a symlink /dev/comcasta pointing to WinTV-PVR-USB2 with serial sn-7653922 tuning comcast analog
# Create a symlink /dev/comcastd pointing to WinTV-PVR-USB2 with serial sn-8257134 using composite comcast digital
KERNEL=="video[0-9]*", PROGRAM="/usr/local/bin/udev-pvrusb2 %m", SYMLINK+="%c", OWNER="mythtv", GROUP="mythtv"
-------------- next part --------------
#!/bin/sh
#
# program: udev-pvrusb2
#
# author: Roger J. Allen - rja at rogera.net
# Wed May 28 12:54:18 CDT 2008
#
# help udev assign consistent device name
# for WinTV-PVR-USB2 by its serial number
#
# argument 1 is a device minor number from udev
# test which sysfs entry matches this minor number
# output consistent device name for udev to create a symlink
#
# in mythtv-setup "Capture Card Setup"
# set "Video device:" to the symlink instead of /dev/video*
# for capturecard videodevice
#
# sn-7653922 returns "comcasta" for comcast analog tuner input
# udev will create /dev/comcasta symlink
# sn-8257134 returns "comcastd" for comcast digital composite input
# udev will create /dev/comcastd symlink
#
# udev rule for Fedora 8 with my custom owner and group settings
#
# KERNEL=="video[0-9]*", PROGRAM="/usr/local/bin/udev-pvrusb2 %m", \
# SYMLINK+="%c", OWNER="mythtv", GROUP="mythtv"
#
SerialNo1="sn-7653922"
Symlink1="comcasta"
SerialNo2="sn-8257134"
Symlink2="comcastd"
if [ 1 = $(grep -c $1 /sys/class/pvrusb2/$SerialNo1/v4l_minor_number) ]
then
echo $Symlink1
exit 0
elif [ 1 = $(grep -c $1 /sys/class/pvrusb2/$SerialNo2/v4l_minor_number) ]
then
echo $Symlink2
exit 0
fi
exit 1
More information about the pvrusb2
mailing list