#!/bin/sh
#
# setup lirc
#
# runlevels: geexbox, debug, configure

echo "### Starting LIRC daemon ###"

# check for remote: if not found or invalid, use default remote
#REMOTE=`sed -n "s/.*remote=\([^ ]*\).*/\1/p" /proc/cmdline`
#if test -z "$REMOTE" \
#        -o ! -f "/etc/lirc/lircrc_$REMOTE" \
#        -o ! -f "/etc/lirc/lircd_$REMOTE.conf"; then
#  REMOTE="atiusb"
#fi

# check for receiver: if not found or invalid, use default receiver
#RECEIVER=`sed -n "s/.*receiver=\([^ ]*\).*/\1/p" /proc/cmdline`
#if test -z "$RECEIVER" \
#        -o ! -f "/etc/lirc/lircd_$RECEIVER"; then
#  RECEIVER="atiusb"
#fi

#cp -f "/etc/lirc/lircrc_$REMOTE" /etc/lircrc
#cp -f "/etc/lirc/lircd_$RECEIVER" /etc/lircd
#cp -f "/etc/lirc/lircd_$REMOTE.conf" /etc/lircd.conf
. /etc/lircd
. /settings
[ "$LIRC_DRIVER" = wiimote -a -n "$WIIMOTE" ] && LIRC_DEVICE="$WIIMOTE"

# insert needed modules
IFS='|'
for module in $LIRC_MODULES; do
  eval "modprobe $module" >/dev/null 2>&1
done

# start lircd
lircd --driver=$LIRC_DRIVER --device=$LIRC_DEVICE -L /dev/null
[ "$LIRC_DRIVER" = bte -o "$LIRC_DRIVER" = bluemobile -o "$LIRC_DRIVER" = wiimote ] && irw > /dev/null 2>&1&

exit 0
