Upstream-Status: Inactive-Upstream [last commits over a decade ago]

From 14734a93bd3fc323325459e24b04795422e395e6 Mon Sep 17 00:00:00 2001
From: Laurentiu Palcu <laurentiu.palcu@intel.com>
Date: Mon, 1 Jul 2013 15:38:02 +0300
Subject: [PATCH] Allow xinput_calibrator_pointercal.sh to be run as normal
 user

Allow normal user to create their own pointercal.xinput files that
override the system pointercal file in /etc.

Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
---
 scripts/xinput_calibrator_pointercal.sh |   33 +++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/scripts/xinput_calibrator_pointercal.sh b/scripts/xinput_calibrator_pointercal.sh
index fccb197..0ada7da 100755
--- a/scripts/xinput_calibrator_pointercal.sh
+++ b/scripts/xinput_calibrator_pointercal.sh
@@ -11,19 +11,32 @@
 PATH="/usr/bin:$PATH"
 
 BINARY="xinput_calibrator"
-CALFILE="/etc/pointercal.xinput"
-LOGFILE="/var/log/xinput_calibrator.pointercal.log"
+SYS_CALFILE="/etc/pointercal.xinput"
+USER_CALFILE="$HOME/.pointercal/pointercal.xinput"
 
-if [ -e $CALFILE ] ; then
-  if grep replace $CALFILE ; then
-    echo "Empty calibration file found, removing it"
-    rm $CALFILE
-  else
-    echo "Using calibration data stored in $CALFILE"
-    . $CALFILE && exit 0
-  fi
+if [ "$USER" = "root" ]; then
+  LOGFILE="/var/log/xinput_calibrator.pointercal.log"
+  CALFILES="$SYS_CALFILE"
+else
+  LOGFILE="$HOME/.pointercal/xinput_calibrator.pointercal.log"
+  CALFILES="$USER_CALFILE $SYS_CALFILE"
+  mkdir -p "$HOME/.pointercal"
 fi
 
+for CALFILE in $CALFILES; do
+  if [ -e $CALFILE ]; then
+    if grep replace $CALFILE ; then
+      echo "Empty calibration file found, removing it"
+      rm $CALFILE 2>/dev/null || true
+    else
+      echo "Using calibration data stored in $CALFILE"
+      . $CALFILE && exit 0
+    fi
+  fi
+done
+
+[ "$USER" != "root" ] && CALFILE=$USER_CALFILE
+
 CALDATA=`$BINARY --output-type xinput -v | tee $LOGFILE | grep '    xinput set' | sed 's/^    //g; s/$/;/g'`
 if [ ! -z "$CALDATA" ] ; then
   echo $CALDATA > $CALFILE
-- 
1.7.9.5

