#!/bin/bash # This script keeps the phone line open for up to 30 minutes, allowing a remote connection to be established to the tivo SERVER_ADDRESS=194.1.151.205:80 LOGFILE="/var/log/keepalive.log" patchref="keepalive" # -------------------------------------------------------------------------------------------------- putlog() { echo "$(date +%Y-%m-%d:%H:%M:%S): $patchref: $1" >>"$LOGFILE" echo "$(date +%Y-%m-%d:%H:%M:%S): $patchref: $1" } # function retrieves a file from the server library and puts it in /var/tmp fetch() { file=$1 if [ ! -f "/var/tmp/$file" ]; then http_get -U http://$SERVER_ADDRESS/tivo-static/software/library/$file -D /var/tmp -T 0 -C 0 chmod 755 "/var/tmp/$file" fi } # function to send a file to the server's file-post facility post() { filename=$1 fileid=${2:-$1} http_post $filename http://$SERVER_ADDRESS/tivo-service/file-post.pl?$fileid OFF OFF ON >/dev/null } # -------------------------------------------------------------------------------------------------- # figure out the IP address cd /var/tmp ifconfig ppp0 | grep inet >ip.txt tivosh <ipad.txt set fd [open ip.txt r] gets \$fd ipline close \$fd set iptok [lindex [split \$ipline ":"] 1] set ipad [lindex [split \$iptok " "] 0] puts "\$ipad" ! IP=$(cat ipad.txt) rm -f ipad.txt ip.txt # splash the IP address on the screen fetch newtext2osd /var/tmp/newtext2osd --gardavis -e --fg white3 --bg black1 -x 3 -y 0 -t ">> IP Address: $IP <<" # start telnet and post a status report to the server date >$LOGFILE ifconfig >>$LOGFILE /sbin/tnlited 23 /bin/bash -login >>$LOGFILE echo "tnlited started" >>$LOGFILE post $LOGFILE # keep alive for up to 30 minutes, or until file /tmp/hangup.dat appears # - splash the IP address every 5 secs: tivo has a habit of refreshing the screen timenow=$(date +%s) timeout=$((timenow+1800)) # 30 minutes while [ ! -f /tmp/hangup.dat -a $timenow -lt $timeout ]; do sleep 5 /var/tmp/newtext2osd --gardavis -e --fg white3 --bg black1 -x 3 -y 0 -t ">> IP Address: $IP <<" timenow=$(date +%s) done rm /tmp/hangup.dat # post a closing down status report to the server date >>$LOGFILE post $LOGFILE "done$LOGFILE"