#!/bin/sh

dev_id=`cat /var/log/Xorg.0.log | grep IDEACO | grep "id " |  grep TABLET | cut -d, -f2 | cut -f3 -d" " | sed 's/)//'`
xinput_calibrator --device $dev_id --output-type xinput > /tmp/cal.txt
perl -pi -e "s/xinput set-int-prop \".*?\"/xinput set-int-prop $dev_id/g" /tmp/cal.txt
echo "sleep 3" > /opt/bin/calibrate.sh
echo "dev_id=\`cat /var/log/Xorg.0.log | grep IDEACO | grep \"id \" |  grep TABLET | cut -d, -f2 | cut -f3 -d\" \" | sed 's/)//'\`" >> /opt/bin/calibrate.sh
cat /tmp/cal.txt | grep "xinput set-int-prop" >> /opt/bin/calibrate.sh
perl -pi -e 's/set-int-prop \d+ /set-int-prop \$dev_id /g' /opt/bin/calibrate.sh
chmod 755 /opt/bin/calibrate.sh
rm -rf /tmp/cal.txt

