#!/bin/sh -e
# Rotate image according to exif header but keep timestamp of file as is

unset LANG
unset LANGUAGE
unset LC_ALL

if [ ! -x /usr/bin/jhead ] ; then
    echo "Please install package jhead"
    exit 1
fi

TMPFILE=`mktemp`
for img in `ls [0-9A-z]*.jpg [0-9A-z]*.JPG 2>/dev/null` ; do
    touch -r "$img" $TMPFILE
    jhead -autorot "$img"
    touch -r $TMPFILE "$img"
done
