#!/bin/bash
is_cal_active=`grep -c '#Option "Calibration"' /usr/share/X11/xorg.conf.d/10-evdev.conf`
echo $is_cal_active
if [ "$is_cal_active" = "1" ]
then
    xinput_calibrator > /tmp/cal_output
    good_cal=`grep -c "Making the calibration permanent" /tmp/cal_output`
    if [ $good_cal = "1" ] 
    then 
    echo "Good CAL"
    new_cal=`grep Calibration /tmp/cal_output`
    else
    echo "BAD CAL"
    fi
    cat /usr/share/X11/xorg.conf.d/10-evdev.conf | sed 's/.*"Calibration.*/'"$new_cal"'/' /usr/share/X11/xorg.conf.d/10-evdev.conf > /tmp/temp-10-evdev.conf
    sudo cp /tmp/temp-10-evdev.conf /usr/share/X11/xorg.conf.d/10-evdev.conf
    exit 1
else
    cat /home/acradyne/g4dev/project/system/10-evdev.conf > /tmp/temp-10-evdev.conf
    sudo cp /home/acradyne/g4dev/project/system/10-evdev.conf /usr/share/X11/xorg.conf.d/10-evdev.conf
    echo "CAL CLEAR"
    exit 0
fi

