#!/bin/sh # Copyright © 2000, 2002 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation. No representations are made about the suitability of this # software for any purpose. It is provided "as is" without express or # implied warranty. # # Created: 16-Aug-2000. progname=slideshow-pull delay=10 url="http://medulla.dnalounge.com/cam/live.jpg" file="html/live.jpg" colorbars=colorbars.jpg tmp="${file}~" #verbose=true too_old() { if [ -n `find $1 -prune -mmin +60 -print 2>&-` ]; then return 1 else return 0 fi } pull_one() { # wget doesn't save the proper file date if -O is specified... # wget -q -O $tmp $url # so instead, write ./live.jpg and rename to html/live.jpg to get the date. tmp="live.jpg" # Arrgh! Note that wget takes 15 minutes to time out on host that # won't connect() even if you specify -T! if [ "$verbose" = true ]; then echo "downloading..." >&2 fi rm -f $tmp wget -t1 -T5 -q $url if [ -s $tmp ]; then # we downloaded a non-zero-length file if too_old $tmp; then # it's stale if [ "$verbose" = true ]; then echo "downloaded image is more than 1 hour old:" >&2 ls -lG --full-time $tmp fi cp -p $colorbars $file else # it's recent mv $tmp $file if [ "$verbose" = true ]; then echo "done." >&2 fi fi else # file was not downloaded, or was 0-length if [ "$verbose" = true ]; then echo "no image downloaded" >&2 fi cp -p $colorbars $file fi if [ "$verbose" = true ]; then ls -lG --full-time $file fi sleep $delay } pull_loop() { while true ; do pull_one done } # log all stdout/stderr text to syslog log_lines() { while read line ; do logger -st "$progname" -- "$line" done } echo "started at `date`" | log_lines pull_loop 2>&1 | log_lines exit 0