#!/bin/bash
# Explanar.de bash script for calibrating Touchscreens in combination of several monitors
# Aug 2013 testet with ubuntu 12.04LTS64
OS=$(uname)
hostname=$(hostname)
whoami=$(whoami)
ip=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
echo "|--------------------------------|"
echo "|----Touchscreen Calibration----|"
echo "|-----with external Monitors-----|"
echo "|--------------------------------|"
echo "| www.explanar.de | August 2013 |"
echo "|--------------------------------|"
echo ""
# Must be root
if [ "$UID" -eq 0 ];
then
echo "Ip-Adress:${ip}."
echo "${OS}-Host:${hostname}."
echo "User:${whoami}."
echo ""
echo ""
echo ""
else
echo "Need to be root. Try to start script prefixed with \"sudo \"."
exit 1
fi
# Identification of devices to be used
inputdevall=$(xinput list --name-only | egrep -i "touch|Touch")
outputdevall=$(xrandr | grep "connected" | cut -f1 -d"(")
# Input device Selection
if [ -z "$inputdevall" ];
then
echo "Sorry, no Inputdevices found."
exit 0
else
if [ $(echo "$inputdevall" | wc -l) -gt 1 ];
then
echo "Please choose the Device to calibrate:"
echo "---------------------------------------"
echo "$inputdevall" | nl
echo "---------------------------------------"
read -p "Number of Device to use: " inputdevnr
echo ""
echo ""
inputdev=$(echo "$inputdevall" | awk "NR==$inputdevnr")
inputdevothers=$(echo -n "sed -i /$inputdev/d $inputdevall")
else
inputdev=$(echo "$inputdevall")
echo "Inputdevice: $inputdev"
echo ""
echo ""
fi
fi
# Output device Selection
if [ -z "$outputdevall" ];
then
echo "Sorry, no Outputdevices found."
exit 0
else
if [ $(echo "$outputdevall" | wc -l) -gt 1 ];
then
echo "Please choose the output-device to use:"
echo "---------------------------------------"
echo "$outputdevall" | nl
echo "---------------------------------------"
read -p "Number of Screen to use: " outputdevnr
echo ""
echo ""
outputdev=$(echo -e "$outputdevall" | cut -f1 -d" " | awk "NR==$outputdevnr")
outputdevothers=$(echo -e "$outputdevall" | cut -f1 -d" " | grep -v "$outputdev")
else
outputdev=$(echo "$outputdevall" | cut -f1 -d" ")
echo "Outputdevice: $outputdev"
echo ""
echo ""
fi
fi
# Switching off all unused Output-devices
echo "$outputdevothers" | while read a; do $(xrandr --output "$a" --off); done # > /dev/null 2>&1
# string-to-command workaround: xinput doesn't understand Devices from variables
cmd="xinput map-to-crtc '$inputdev' $outputdev"
eval "$cmd"
if [ -f /usr/share/X11/xorg.conf.d/99-calibration.conf ]
then
rm /usr/share/X11/xorg.conf.d/99-calibration.conf
fi
calibration=$(xinput_calibrator)
echo ""
sudo echo -e "$calibration" | awk 'NR > 9 { print }' >> /usr/share/X11/xorg.conf.d/99-calibration.conf
# neue Variable mit Auflösung und koordinaten
outputdevothersfull=$(echo -e "$outputdevall" | grep -v "$outputdev")
echo "$outputdevothers" | while read a;
do $(xrandr --output "$a" --off)
done # > /dev/null 2>&1
# Alte (einfache) Wiedereinschaltung der anderen monitore mit auto statt
# echo -e "$outputdevothers" | while read a; do $(xrandr --output "$a" --auto); done # > /dev/null 2>&1
eval "$cmd"
echo "Please readjust your \"(non-touch-)Monitors\" in the Systemsettings."
echo ""
echo ""
echo ""
echo ""
exit