#!/bin/bash
# HP20100831 only handling IMG_????.???, converting PNG to JPG
# HP20111127 added MOV
# HP20121203 iPhone5
# HP20130807 rewrite, touch to set timestamp of symlink
# HP20130921 only handle newer files

cd /data/pictures/iPhone5/pictures-symlink/
s="../pictures"

for i in ` ( cd $s && ls IMG_????.JPG ) `
do
j=${i,,}
if [[ $s/$i -nt $j ]]
then
ln -f -s $s/$i $j
touch -h -r $s/$i $j
fi
done

for i in ` ( cd $s && ls IMG_????.MOV ) `
do
j=${i,,}
if [[ $s/$i -nt $j ]]
then
ln -f -s $s/$i $j
touch -h -r $s/$i $j
fi
done

for i in ` ( cd $s && ls IMG_????.PNG ) `
do
j=${i,,}
k=${j/.png/_png.jpg}
if [[ $s/$i -nt $j ]]
then
ln -f -s $s/$i $j
touch -h -r $s/$i $j
convert -quality 93 -sampling-factor 1x1 $j $k
touch -h -r $s/$i $k
fi
done

cd ..

#--
