#!/bin/sh -ex

if [ -z "$1" ]; then
	echo "You must specify the angle: 0 90 180 or 270";
	exit 1;
fi;
angle="$1";
if [ "$angle" -ne 0 ]; then
	angle="-rotate $angle";
else
	angle="";
fi;
shift;
mkdir -p proc;
for i in "$@"; do
	jpegtran -copy all $angle -optimize -progressive -perfect "$i" >"proc/$i";
	touch -r "$i" "proc/$i";
done;
