Helper scripts for udev configuration in Chapter 7
Reece Dunn
msclrhd at googlemail.com
Sun Sep 30 11:07:57 MDT 2007
Hi,
These are some scripts I have written to auto-detect what network card
and cd drive udev rules to use:
cat > detect-cd << "EOF"
#!/bin/bash
# Written by Reece H. Dunn <msclrhd at gmail.com>
for block in `find /sys/block -maxdepth 1 -name [sh]d* | sed 's@/sys@@'`; do
udevtest ${block} > tmp/udev-info
if [[ `cat /tmp/udev-info | grep -F "ID_TYPE=cd"` ]]; then
MODEL=`cat /tmp/udev-info | grep -F "ID_MODEL" | sed
"s at .*ID_MODEL=\(.*\)'@\1@"`
REVISION=`cat /tmp/udev-info | grep -F "ID_REVISION" | sed
"s at .*ID_REVISION=\(.*\)'@\1@"`
echo "SUBSYSTEM==\"block\", ENV{ID_MODEL}==\"${MODEL}\",
ENV{ID_REVISION==\"${REVISION}\", SYMLINK+=\"cdrom dvd\"}"
fi
rm /tmp/udev-info
done
EOF
cat > detect-net << "EOF"
#!/bin/bash
# Written by Reece H. Dunn <msclrhd at gmail.com>
for net in `grep -H . /sys/class/net/*/address | sed -e
'/:00:00:00:00:00:00/d'`; do
address=`echo $net | sed -e 's at .*address:\(.*\)@\1@'`
name=`echo $net | sed -e 's at .*net/\(.*\)/address.*@\1@'`
echo "ACTION==\"add\", SUBSYSTEM==\"net\",
SYSFS{address}==\"${address}\", NAME=\"${name}\""
done
EOF
These can then be used like this:
./detect-cd > /etc/udev/rules.d/82-cdrom.rules
./detect-net > /etc/udev/rules.d/26-network.rules
The detect-cd script will only work properly with machines that only
have one CD, as it always uses the same symlink for the CD devices.
Are these useful to include in the LFS book?
- Reece
More information about the lfs-dev
mailing list