#!/bin/sh -e # keep dirs grouped by the device/origin # thanks to the Freenode #bash peeps PXREPO=frodo:pictures BACKUP=melkinpaasi.cs.helsinki.fi:pictures WEBDIR=/srv/www/pictures FORCEEDIT=0 SKIPPEDFILES=0 UPLOADEDFILES=0 #. ~/.pik usage() { cat < /dev/stderr exit 1 else if [ $VERBOSE ] ; then du -h $i; fi fi } ### Make sure we have a JPEG notJPEG() { type=$(file "$1") case $type in *JPEG*) return 1 ;; *) echo "PIK002: $type is not a JPEG, skipping" > /dev/stderr return 0 ;; esac } import() { GOOD="good-"`basename $1`".pik" BAD="bad-"`basename $1`".pik" checkdirdepth $1 for i in `find $1 -type f` do if [ $VERBOSE ] ; then ls -alh $i; fi # Skip if not JPEG if notJPEG $i ; then continue fi ### Get the time from the exifinfo. Else get it from the mtime. # EXIFs don't have timezone information. Assuming UTC exifdatetime=`jhead $i | grep "Date/Time"` if [ "$exifdatetime" ] ; then #TODO: Optimize this line dt=$(echo $exifdatetime | sed 's,Date/Time : ,,' | sed 's,:,/,1' | sed 's,:,/,1') echo $dt TIME=$(date -d"$dt" +%Y%m%d%H%M.%S...%Z) else echo PIK003: $i has an error in the EXIF > /dev/stderr EPOCH=`stat -c%Y $i` TIME="*"$(date -d"01 jan 1970 + $EPOCH seconds" +%Y%m%d%H%M.%S) fi # The unique time of the picture BUG: USES PERL ;) #echo -n "[[CC]YY]MMDDhhmm[.ss]" # convert EPOCH to UTC #echo -n `perl -MPOSIX -le 'print strftime("%Y%m%d%H%M.%S", gmtime shift)' $P_EPOCH` echo $TIME $PWD/$i done } while getopts "i:h-" opt ; do case "$opt" in i) import $OPTARG;; u) upload ;; h) usage ; exit 0 ;; -) break ;; *) usage 1>&2 ; exit 1 ;; esac done shift $(($OPTIND - 1))