#!/bin/bash

## thanks and credit to mrplow - http://ubuntuforums.org/showpost.php?p=11422009&postcount=19
## run this script from the directory containing the lirc source directory

## lets update the lirc sourc files
rm -rfv lirc
git clone git://lirc.git.sourceforge.net/gitroot/lirc/lirc
[ -d lirc ] || { echo "git clone failed."; exit 1; }

## uncomment if you don't already have the patch
wget http://old.nabble.com/attachment/31787507/0/lirc_0.9.1_lirc_xbox_driver.patch

## apply the patch and configure the driver
cd lirc/
patch -p1 <../lirc_0.9.1_lirc_xbox_driver.patch
sed -i '/smp_lock/ d' drivers/lirc_xbox/lirc_xbox.c
./autogen.sh
./configure -with-driver=userspace

## make and install the driver then restart lirc
cd drivers/lirc_xbox/
make

{
    trap "sudo -k" EXIT INT QUIT TERM
    sudo make install
    sudo service lirc restart
}
