#!/bin/sh
#
# configure MPlayer's DVB settings
#
# runlevels: geexbox, debug, configure

CHANNELS_CONF=/etc/mplayer/channels.conf

echo "### Configuring MPlayer's DVB support ###"

if [ -f /var/dvbcard ]; then

  # build DVB channels configuration file
  if [ ! -f $CHANNELS_CONF -a -f /etc/dvb.conf ]; then
    dvbscan -x 0 /etc/dvb.conf > $CHANNELS_CONF
    if [ -s $CHANNELS_CONF ]; then
      # remove non-coherent detected channels
      grep -v "^\[.*\]:" $CHANNELS_CONF > /tmp/channels.conf
      mv /tmp/channels.conf $CHANNELS_CONF
    fi
  fi
fi

# no DVB card or no configured channels
if [ ! -f /var/dvbcard -o ! -s $CHANNELS_CONF ]; then
  # remove DVB options from menu
  sed -i 's/.*ok="set_menu dvb_sel".*//' /etc/mplayer/menu.conf
fi

exit 0
