This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
lsts_glued/rules/filesystem/fs/sbin/mdev-ttyusb

44 lines
1.2 KiB
Bash
Executable File

#! /bin/sh
[ "$SUBSYSTEM" -ne "tty" ] && exit 0
if [ -z "$MAJOR" ] || [ -z "$MINOR" ]; then
exit 0
fi
MAJOR_HEX=$(echo $(printf %2x "$MAJOR"))
MINOR_HEX=$(echo $(printf %2x "$MINOR"))
# env | while read line; do
# logger -t "$0" "$line"
# done
case "$ACTION" in
add)
dev_root="/sys/$DEVPATH/../../../../"
itf_root="/sys/$DEVPATH/../../../"
vid="$(cat $dev_root/idVendor 2> /dev/null)"
pid="$(cat $dev_root/idProduct 2> /dev/null)"
serial="$(cat $dev_root/serial 2> /dev/null)"
[ -z "$serial" ] && serial='0'
itf="$(cat $itf_root/bInterfaceNumber 2> /dev/null)"
dev_name="${vid}_${pid}_${serial}_${itf}"
dev_file="/dev/uart/$dev_name"
logger -t "$0" "creating device: $dev_file"
mknod "$dev_file" c "$MAJOR" "$MINOR"
;;
remove)
removed_major_minor="$MAJOR_HEX:$MINOR_HEX"
for f in /dev/uart/*; do
file_major_minor="$(stat -c %t:%T "$f")"
#logger -t "$0" "$f | $removed_major_minor | $file_major_minor"
if [ "$file_major_minor" = "$removed_major_minor" ]; then
logger -t "$0" "removing device: $f"
rm -f "$f"
fi
done
;;
esac