#!/bin/bash # set -xv # # Program: mkchannels # Purpose: Create channels on Tivo # Author: Indulis Bernsteins # Version: 0.1 # Date: 15 May 2003 # Usage: mkchannels source ChannelFile City ChannelType # # Source # The source object you'd like to add the channels to # # ChannelFile # name of file which has list of channels by city # # City # Which entries in the ChannelFile to add to the Tivo # # Run this program once for each source to populate # # --------------------------------------------------------------------- # Format of the ChannelFile... # # Comment line starts with a # # City ShortChannelName ChannelID ChannelNum LongChannelName # # City = just a name which must match the city name given to mkchannels # # ShortChannelName = Name which appears on Tivo where there is limited space # on the screen # # ChannelID = a number which matches the channel ID in the slice file # you downloaded # # ChannelNum = the buttons you push on the remote to change to this channel # (or the channel # in the Tivo tuner) # In other words, what channel is is programmed to on your # VCR or set-top box or cable box or... # ***NOTE*** ChannelNum is the most likely thing you'll need to change # if you don't have a "standard" setup # # LongChannelName = Name which appears in long listing on the Tivo # --------------------------------------------------------------------- # # Note that you DO NOT have to put the NoNag channel in, mkchannels will # do this for you # set bash options shopt -s extglob # use POSIX globbing # initialise variables typeset -ix my_numfound my_numfound=0 # counts the number of times a line matching given # city is found in the input file my_usage_text="Usage: $0 source/setup ChannelFile City" my_home="/var/hack/guide" # --------------------------------------------------------------------- # check inputs as much as we can # --------------------------------------------------------------------- if [[ ( $# -ne 3 ) ]] then # not enough options given echo $my_usage_text echo "You did not supply the correct number of parameters (hint: 3!)" exit 1 fi my_source=$1 my_chanfile=$2 my_city=$3 # make sure we can find channel file which maps channels to cities to... # if [[ ! (-f $my_chanfile) ]] then echo "Could not find the file $my_chanfile" exit 1 fi if [[ ! (-r $my_chanfile) ]] then echo "Could not read the file $my_chanfile- probably permissions problem" exit 1 fi # who knows if they got city right, we'll have to check that we can find at # least one line in the file by using my_numfound later # --------------------------------------------------------------------- # now start parsing the file for matching cities and add the channels # --------------------------------------------------------------------- cat $my_chanfile | { while read my_linecity my_shortchname my_chanid my_channum my_longchanname do my_linecity=${my_linecity##*([[:space:]])} # remove whitespace from start of line my_linecity=${my_linecity%%*([[:space:]])} # remove whitespace from end of line my_a=${my_linecity##\#} # see if we start with # if [[ ( $my_a = $my_linecity ) && ! ( x$my_linecity = x ) && ( $my_linecity = $my_city ) ]] then # it was not a comment line or a blank line # and it matched the city we wanted my_numfound=$my_numfound+1 # ---------------------- # add the channels # ---------------------- echo "tivosh $my_home/add-whole-channel.tcl $my_chanid $my_channum $my_shortchname \"$my_longchanname\" $my_source" my_longchanname=\"$my_longchanname\" echo "exec $my_home/add-whole-channel.tcl $my_chanid $my_channum $my_shortchname $my_longchanname $my_source" | tivosh fi done # --------------------------------------------------------------------- # check to see if we found ANY matching channels # --------------------------------------------------------------------- if [[ ( $my_numfound -eq 0 ) ]] then echo "ERROR! Could not find any channels in file $my_chanfile to match city $my_city" echo "Please check for misspelling and uppercase/lowercase mismatches" exit 1 fi } exit 0