#!/bin/sh # Copyright © 2000-2013 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=60 url="http://static-cdn.justin.tv/previews/live_user_dnalounge-630x473.jpg" file="html/live.jpg" colorbars=colorbars.jpg tmp="${file}~" tmp2="${file}2~" verbose=false too_old() { if [ -z `find $1 -prune -mmin +240 -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_user_dnalounge-630x473.jpg" # we get this is there's a failure crud="screencap_404_630x473.png 404_preview.png" # 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 `date`: "downloading $url" >&2 fi rm -f $tmp $tmp2 $crud wget -t1 -T5 -q $url if ! [ -s $tmp ]; then # zero-length file if [ "$verbose" = true ]; then echo `date`: "zero-length file: $tmp" >&2 ls -lG --full-time $tmp fi rm -f $tmp fi if [ -f $tmp ] && ! too_old $tmp; then convert -crop 480x360+75+56 $tmp $tmp2 >/dev/null 2>&1 touch -r $tmp $tmp2 mv $tmp2 $tmp if cmp -s $tmp $file ; then if [ "$verbose" = true ]; then echo `date`: "image hasn't changed" >&2 fi rm -f $tmp fi fi if [ ! -f $tmp ]; then # not downloaded, or unchanged cp -p $file $tmp fi if too_old $tmp; then if [ "$verbose" = true ]; then echo `date`: "too old: $tmp" >&2 ls -lG --full-time $tmp fi cp -p $colorbars $file rm -f $tmp else mv $tmp $file fi if [ "$verbose" = true ]; then echo `date`: "done." >&2 ls -lG --full-time $file echo "" 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 `date`: "started" | log_lines pull_loop 2>&1 | log_lines exit 0