#!/bin/bash # if given no arguments, or flag args, then start wincd. otherwise, we're # being _called_ by wincd, so don't start it again! WINCD_ARGS="-p 10 -z 2 -c -n 12 -s $0" case $1 in -*|"") echo "starting \"wincd $WINCD_ARGS $* & \"" wincd $WINCD_ARGS $* & echo "wincd is pid $!" exit 0 ;; *) #single non-flag argument, must be the imagename if [ $# = 1 ] then curimage=$1 fi ;; esac if [ ! "$curimage" ] then echo usage: $0 winc-args >&2 echo or >&2 echo usage: $0 image-filename >&2 exit 1 fi if [ ! -f "$curimage" ] then echo $0: no such image-file: $curimage >&2 exit 1 fi # how much smaller should the thumbnails be? # (set to null for no thumbnail images) THUMBSCALE=0.375 #how many images total will we save? KEEPFILES=10 #if we set NUMNAMES to null, no pretty names will be kept. #NUMNAMES=12 NUMNAMES= # the images will all be kept in IMAGEDIR IMAGEDIR=/home/atmos2/rdewitt/HTML/camera/tmp #if NUMNAMES is non-null, we'll keep symlinks to the N most # recent images, and the symlinks will be named like so: IMAGEPRETTYNAME=current # plus ".jpg" THUMBPRETTYNAME=thumb # plus ".jpg" #the real image and filenames will be like "img-DayHH:MM.jpg" imagepref=img- thumbpref=thmb- # picture is take at approximately ${now} now=$(date +%a%T) # construct the final filenames jpgimage=${IMAGEDIR}/${imagepref}${now}.jpg thumbimage=${IMAGEDIR}/${thumbpref}${now}.jpg cjpeg <$curimage >$jpgimage [ "$THUMBSCALE" ] && pnmscale $THUMBSCALE $curimage | cjpeg >$thumbimage rm $curimage # list all the images, and remove any that are too old, # i.e. any that are from $KEEPFILES+1 on up KEEPFILES=$((KEEPFILES + 1)) rm -f $(ls -t ${IMAGEDIR}/${imagepref}*.jpg | sed -n ${KEEPFILES}',$'p) 2>/dev/null [ "$THUMBSCALE" ] && rm -f $(ls -t ${IMAGEDIR}/${thumbpref}*.jpg | sed -n ${KEEPFILES}',$'p) 2>/dev/null if [ ! "$NUMNAMES" ] then exit 0 fi # relink all the "well-known" names # create a new suffix "", "1", "2", etc. sufx= count=0 for f in $(ls -t ${IMAGEDIR}/${imagepref}*.jpg | sed ${NUMNAMES}q ) do ln -s -f $f ${IMAGEDIR}/$IMAGEPRETTYNAME$sufx.jpg if [ "$sufx" ] then count=$((count + 1)) else count=1 fi sufx="-$count" done [ "$THUMBSCALE" ] || exit sufx= count=0 for f in $(ls -t ${IMAGEDIR}/${thumbpref}*.jpg | sed ${NUMNAMES}q ) do ln -s -f $f ${IMAGEDIR}/$THUMBPRETTYNAME$sufx.jpg if [ "$sufx" ] then count=$((count + 1)) else count=1 fi sufx="-$count" done