CF-72 Touch Screen Automated

I stretched my shell scripting abilities a bit today automating the driver patch for the touch screen on my notebook. I first tried to fix the lifebook.c file with sed. However, I found the multi-line editing functions a little to complex for me to just pick up. Next time. This time I took the easy way out and embedded the text of the entire source file in the script and simply  printed it out to a file before compilation. This will work as long as the rest of the driver source doesn’t get rewritten in the future.

here are the excerpts:

#!/bin/bash
i=1
sp="/-\|"
echo -n ' '
spin_it()
{
printf "\b${sp:i++%${#sp}:1}"
sleep 0.05
}
KernNum=`uname -r`
KernNum=${KernNum:0:6}
cd /root
echo -e \\r"** Installing necessary packages"
apt-get -y install xserver-xorg-input-evtouch linux-source linux-headers-`uname -r` 1>/root/psmlog.txt  2>/root/psmerr.txt &
while [ `pgrep apt-get` ]
do
spin_it
done
echo -e \\r"** Removing conflicting packages"
apt-get -y remove xorg-driver-fglrx 1>>/root/psmlog.txt 2>>/root/psmerr.txt &
while [ `pgrep apt-get` ]
do
spin_it
done
if [ -e "/usr/src/linux-source-$KernNum" ]; then
echo -e \\r"** Linux Source is up-to-date"
else
echo -e \\r"** Extracting Linux Source Files, This may take some time . . ."
cd /usr/src
tar -xjf "linux-source-"$KernNum".tar.bz2" &
while [ `pgrep tar` ]
do
spin_it
done
fi
echo -e \\r"** Preparing touch screen driver source"
cp -R /usr/src/linux-source-$KernNum/drivers/input/mouse /root/
cd /root/mouse
mv ./lifebook.c lifebook.old
echo '''/*
* Fujitsu B-series Lifebook PS/2 TouchScreen driver

~ ~ ~ ~ driver source code here ~ ~ ~ ~

”’ >lifebook.c
mv ./Makefile ./Makefile.old
echo ”’#
# Makefile for the psmouse driver.

~ ~ ~ ~ Makefile text  here ~ ~ ~ ~

”’ >Makefile
echo -e \\r”** Compiling device driver”
make 1>>/root/psmlog.txt 2>>/root/psmerr.txt
echo -e \\r”** Driver compiled successfully”
read -sn 1 -p “** Close any other open windows and press any key to continue…”
echo -e \\n\\r”** Installing touch screen driver”
mv /lib/modules/`uname -r`/kernel/drivers/input/mouse/psmouse.ko /lib/modules/`uname -r`/kernel/drivers/input/mouse/psmouse.bak
cp ./psmouse.ko /lib/modules/`uname -r`/kernel/drivers/input/mouse/psmouse.ko
make clean 1>>/root/psmlog.txt 2>>/root/psmerr.txt
mv /etc/X11/xorg.conf /etc/X11/xorg.old
echo ”’
# xorg.conf (X.Org X Window System server configuration file)

~ ~ ~ ~ Contents of /etc/X11/xorg.conf here ~ ~ ~ ~

”’ >/etc/X11/xorg.conf
rmmod psmouse
modprobe psmouse
killall -1 gdm
exit 0

I am sure that there are better ways to do this (using sed for instance), but this gets it done for now. Now maybe I will upgrade to Ubuntu 9.04 and see if this works there.

Ok I just tried this on ubuntu 9.04 and discovered that I had forgotten to include the ‘-y’ option to the ‘apt-get’ commands (fixed now). Also, the driver compile section fails unless you add ‘elantech.o hgpk.o’ to the Makefile section. And I added a 0.05 pause to the spinner so you can actually see it spin.

This post is outdated please use the new script here

Leave a comment