#!/bin/bash

echo "Fetching LIRC-CVS kernel-source into /usr/src/lirc/."
echo
echo "If you do not like this Ctrl-C now and edit this script, thanks!"
echo "10 seconds to break out ..."

sleep 10

rm -rf /usr/src/lirc/
cd /usr/src/

echo
echo "Press <Enter>"
cvs -q -f -d ':pserver:anonymous@cvs.sourceforge.net:/cvsroot/lirc' login
cvs -q -f -z8 -d ':pserver:anonymous@cvs.sourceforge.net:/cvsroot/lirc' co lirc || exit 1
cvs -q -f -d ':pserver:anonymous@cvs.sourceforge.net:/cvsroot/lirc' logout

echo
echo "Now I merge LIRC-CVS into the kernel-source."
echo " * /usr/src/linux/drivers/char/lirc/"
echo " * /usr/src/linux/include/linux/{kcompat.h,lirc.h}"
echo
echo "You have 10 seconds to Ctrl-C to correct directory links ..."

sleep 10

echo
echo " * Updating LIRC-CVS files"
find lirc/drivers/ -name "*.[ch]" -exec perl -pi -e "s/drivers\/lirc\.h/linux\/lirc\.h/g" {} \;
find lirc/drivers/ -name "*.[ch]" -exec perl -pi -e "s/drivers\/kcompat\.h/linux\/kcompat\.h/g" {} \;

echo " * Copying include files"
cp lirc/drivers/{kcompat.h,lirc.h} linux/include/linux/
echo " * Copying LIRC-CVS files"
mkdir -p linux/drivers/char/lirc/
find lirc/drivers/*/ -name "*.[ch]" -exec cp {} linux/drivers/char/lirc/ \;

rm -rf /usr/src/lirc/

echo
echo "Merge done!"
echo "---------------------------------------"
echo "Don't forget to apply the patch and ..."
echo "if necessary edit it for new drivers and/or to suite your kernel-sources."
echo
echo "http://geki.ath.cx/kernel-patches/include-lirc-into-kernel.patch"
