#!/bin/bash

data=$(dmesg | grep ttyACM | cut -f 7 -d " " | cut -f 1 -d : )
code=$(echo $data | cut -f 1 -d " ")
#echo $code
port=$(pwd | cut -c 17)
let port--
#echo $port
dev="/dev/ttyACM"
name="$dev$port"
commande=$(udevadm info --name=$name --attribute-walk | egrep "idVendor|idProduct|serial")
idProduct=$(echo $commande | cut -f 1 -d " ")
idVendor=$(echo $commande | cut -f 2 -d " ")
serial=$(echo $commande | cut -f 3 -d " ")
#echo $commande
#echo $idProduct
#echo $idVendor
#echo $serial
newdev="ttyPR"
newname="$newdev$port"
#echo $newname
rule="SUBSYSTEM==\"tty\", $serial, $idVendor, $idProduct, SYMLINK+=\"$newname\""
#echo $rule
echo $rule >> /etc/udev/rules.d/usb-serial.rules
udevadm trigger
