#!/bin/bash
rm -rf temp
rm -f picture_date.txt
rm -f zeegat_date/*.jpg
ls 1*.jpg | cut -b 1-10 > jpgs
#ls 1290522437.jpg | cut -b 1-10 > jpgs
let ipict=0
for i in `more jpgs`
do
let ipict=ipict+1;
#s=$i
#shift
#date -d @$s "$@"  > temp
 date -u --date="1970-01-01 ${i} sec GMT" > temp
#date --date="1970-01-01 ${i} sec GMT" > temp
#date --date="@${i}" > temp
more temp
cut -b 25-28  temp > year  
echo "year  `more year`" 
cut -b 5-7  temp > month 
echo "month `more month`" 
cut -b 9-10 temp > day   
echo "day   `more day`" 
cut -b 12-13 temp > hour  
echo "hour  `more hour`" 
cut -b 15-16 temp > minut 
echo "minut `more minut`" 
cut -b 18-19 temp > scnds 
echo "scnds `more scnds`" 
#exit
mydate="`more year` `more month` `more day` `more hour` `more minut` `more scnds` "
echo "mydate ${mydate}"
monthnumber() {
    month=$1
    months="JanFebMarAprMayJunJulAugSepOctNovDec"
    tmp=${months%%$month*}
    month=${#tmp}
    monthnumber=$((month/3+1))
    printf "%02d\n" $monthnumber
}

arr=(`echo ${mydate}`);
year=$(echo ${arr[0]})
month=$(monthnumber ${arr[1]})
day=$(echo ${arr[2]})
printf "%02d" $day > day2
dayt=`more day2`
hour=$(echo ${arr[3]})
minut=$(echo ${arr[4]})
scnds=$(echo ${arr[5]})
#pictname="$year.$month.$dayt.$hour.$minut.$scnds" 
printf "%03d" $ipict > picti
pict=`more picti`
#pictname="zeegat${pict}"
#pictname="P$pict.$year.$month.$dayt.$hour.$minut.$scnds" 
pictname="P$pict.$year.$month.$dayt.$hour" 
echo "$i $pictname" >> picture_date.txt
#cp -p ${i}.jpg zeegat_date/$pictname.jpg
cp ${i}.jpg zeegat_date/$pictname.jpg
done
rm -f jpgs year temp month minut hour day scnds out day2 picture_date.txt picti
exit
