#!/bin/sh
# by yellow 

if [ "$1" == "--help" ] ; then 
	echo " "
	echo " launch the script with argument sudo for having sudo"
	echo " launch the script with no argument, and you do not have sudo. This is not adviced and not secured. "
	exit 0
fi

if [ "$1" == "-help" ] ; then 
	echo " "
	echo " launch the script with argument sudo for having sudo"
	echo " launch the script with no argument, and you do not have sudo. This is not adviced and not secured. "
	exit 0
fi


clear
echo "***********************************************************"
echo "Auto installer MCE USB RC2400, remote control with lirc use"
echo "***********************************************************"
echo " "
echo " "
mkdir -p /tmp/rc2400autoinstaller_au
mkdir -p /etc/lirc/
cd /tmp/rc2400autoinstaller_au
wget -N "http://yellowprotoss.ye.funpic.org/website/lirc-rc2400/beta01-autoinstaller/rc2400-1.3rc2.tar.gz"
rm -rf /tmp/rc2400autoinstaller_au/rc2400-1.3rc2
tar xvpfz rc2400-1.3rc2.tar.gz
cd rc2400-1.3rc2
rm rc2400
make

if [ "$1" == "sudo" ] ; then 
	echo " "
	echo "Sudo:"
	sudo cp rc2400 /usr/bin/ 
	echo " "
	echo "Installing the config file in /etc/lirc/ "
	sudo cp rc2400.conf "/etc/lirc/rc2400.conf" 
else
	echo " "
	echo "No sudo:"
	cp rc2400 /usr/bin/
	echo " "
	echo "Installing the config file in /etc/lirc/ "
	cp rc2400.conf "/etc/lirc/rc2400.conf" 
fi
chmod +rx /usr/bin/rc2400
echo "rc2400 Installed."
whereis rc2400



echo " "
echo "Preparing the files, to avoid locking up, at boot"
echo "File: /etc/rc2.d/S18rc2400" 
echo "" > "/etc/rc2.d/S18rc2400" 

echo "killall -e irzol01 ;" >> "/etc/rc2.d/S18rc2400" 
echo "killall -e rc2400" >> "/etc/rc2.d/S18rc2400" 
echo "killall -e lircd ;" >> "/etc/rc2.d/S18rc2400" 
echo "/usr/bin/rc2400 -udp -d 0x147a:0xe017  &  sleep 1s ; lircd -n -H udp /etc/lirc/rc2400.conf  & " >> "/etc/rc2.d/S18rc2400" 
chmod +rx "/etc/rc2.d/S18rc2400"

echo "File: /etc/rc2.d/S18rc2400   installed" 
echo " Enjoy lirc "
echo " Many thanks to Jason and Ian "
echo " "
echo " Autoinstaller script, finished. rc2400 installed. Please reboot to see the effect"
echo " "
echo " Yellow."
echo " "







