#!/bin/bash # set -xv # shell script to automatically list or delete Tivo program sources, to make it # ready to install new ones # # Version 0.2 # 15 May 2003 # Author: Indulis Bernsteins # Usage: At your own risk entirely! # # This program will delete all sources on the Tivo! # # You'd better have made a backup!!!! # # The program works by looping through the available sources, # then calling tivosh # using a modified removesource.tcl file called # my_removesource.tcl which accepts parameters setup & source # as positional parameters i.e. # my_removesource.tcl 1878 1625 # will remove source 1625 from setup 1878 shopt -s extglob # for extended POSIX pattern matching typeset -ax my_words #my_words is an array (not a BBC radio program) typeset -ix i #i is an integer typeset -x my_mode # my_mode tells us whether to delete or list typeset -ix my_loop_count my_usage_text="Usage: $0 ... that's it! If called as delallsources will delete, if called as lssources will list all sources." my_name=${0##*/} #remove leading directories my_dir=${0%/*} # get called directory name del_tcl_prog="$my_dir/delsource.tcl" if [[ $my_name = "delallsources" ]] then my_mode="delete" else my_mode="list" fi # note that the "builtins" in the tivosh like mls have to be fed to # tivosh via an echo (i.e. pretending it is coming from a terminal) echo "mls /" | tivosh | grep Setup | { read my_a my_b my_c the_rest if [ "x"$my_a = "x" ] then #there were no setups! exit 1 fi # now have the Setup object # in $my_c echo "dumpobj $my_c" | tivosh | grep [[:space:]]Source[[:space:]] | { read my_line if [[ ! ( -n $my_line ) ]] then #there were no sources! echo "No sources found. Nothing to do. Exiting. Bye!" exit 1 fi my_line=${my_line#*([[:space:]])@(Source)*([[:space:]])@(=)*([[:space:]])} #remove Source= from start echo $my_line | { read -a my_words i=0 while [[ $i -lt ${#my_words[*]} ]] do my_c=${my_words[i]} # get sources into array my_d=${my_c#+([[:digit:]]@(/)+([[:digit:]])} if [[ ! ( -n $my_d ) ]] then echo "Weird stuff in source, not digits/digits!" exit 1 fi # change the source to be separated by a space not a slash # remove trailing /nums to get setup number into my_setup my_setup=${my_c%%/*} my_source=${my_c##*/} # now ready to execute the deletes if [[ ( $my_mode = "delete" ) ]] then echo "Deleting source using $del_tcl_prog $my_setup $my_source" $del_tcl_prog $my_setup $my_source my_rc=$? my_loop_count=1 while [[ $my_rc -ne 0 ]] do echo " Retry $my_loop_count (probably due to temporary errTmBackgroundHoldoff)" sleep 2 tivosh $del_tcl_prog $my_setup $my_source my_rc=$? my_loop_count=my_loop_count+1 if [[ my_loop_count -gt 10 ]] then echo "Too many retries!" exit 1 fi done else # mode is to list echo "Listing source $my_setup/$my_source" echo "dumpobj $my_setup/$my_source" | tivosh fi i=i+1 # next source to delete please done } } } exit 0