#!/bin/bash
VARLOG=/var/log/minerva

date +"%F %H:%M CMD $0 $*" >>$VARLOG/bearskin/`basename $0` 2>/dev/null

if [ $# -le 1 ]; then
  echo "Usage: $0 <device> <command> [params]"
  echo "  command ::= channels getchannel getname getstation getxawtv onnow"
fi

MINROOT=/usr/local/minerva

DEVICE=$1
CMD=$2
PARAM=$3

. $MINROOT/conf/tvconf.conf

case "$CMD" in
  init)
     exit 0;
     ;;

  channels)
     echo ${#channel[@]}
     exit 0;
     ;;

  getchannel)
     echo ${channel[$PARAM]}
     exit 0;
     ;;

  getname)
     echo ${names[$PARAM]}
     exit 0;
     ;;

  getstation)
     echo ${stations[$PARAM]}
     exit 0;
     ;;

  onnow)
     $MINROOT/bin/tvonnow $DEVICE all $PARAM $4
     exit 0;
     ;;

  getxawtv)
     for NUM in $(seq 0 $((${#channel[@]} - 1)))
     do
        echo "["${names[$NUM]}"]"
        echo "channel="${channel[$NUM]}
        echo "key="$(($NUM+1))
        echo
     done
     exit 0;
     ;;
esac
 


