#!/bin/bash# "Constants"# Which interface is the HDHR on?IFACE=eth0# Path to config toolHDHR=/usr/local/bin/hdhomerun_config# ID of the Home RunHDID=FFFFFFFF# Which tuner [0|1] ?TUNER=0#### The string to throw the user when they need a boneusage="Usage: $(basename $0) [-i ID] [-t 0|1] -m mode -c channel -p program [-r] [-f filename] [-l length]"if [ $# == 0 ]then echo $usage exit 1fi# Parse all the command line argswhile getopts "i:t:m:c:p:f:l:rh" parmdo case $parm in m) MODE=$OPTARG;; c) CHAN=$OPTARG;; p) PROG=$OPTARG;; f) OUTFILE=$OPTARG;; l) LENGTH=$OPTARG;; r) RECORD=true;; i) HDID=$OPTARG;; t) TUNER=$OPTARG;; h) echo $usage;; \?) echo $usage exit 1 ;; *) echo $usage exit 1;; esacdone# Sanity checking should be here someday# Figure out what my IP isMYIP=$(ifconfig ${IFACE} | awk -F: '/inet addr:/{print $2}' | cut -d' ' -f1)PORT=1234${HDHR} ${HDID} set /tuner${TUNER}/channel $MODE:$CHAN${HDHR} ${HDID} set /tuner${TUNER}/program $PROGif [ "$RECORD" == "true" ]then if [ "$OUTFILE" == "" ] then echo "Please specify a filename to record to with the -f flag" exit 1 fi if [ "$LENGTH" != "" ] then ${HDHR} ${HDID} save ${TUNER} $OUTFILE & RECPID=$! echo "Recorder process is $RECPID. Recording for $LENGTH." sleep $LENGTH kill $RECPID else echo "Recording in foreground. Ctrl-C to stop." ${HDHR} ${HDID} save ${TUNER} $OUTFILE fielse vlc udp://@:${PORT} & sleep 3s ${HDHR} ${HDID} set /tuner${TUNER}/target ${MYIP}:${PORT}fi