#!/bin/sh

# from 1600x1200 jpegs, 1024x768 ones, 30% ones and 15% ones are created,
# with symlinked .xvpics directories

# JUST THE named FILES ON THE COMMAND LINE ARE ADDED by this script, 
# or just the indexes updated, with no parameters.

# Jenik Hollan, N. Copernicus Observatory and Planetarium in Brno, April 2002

# to make the index files, sed is to be installed in unix (a must anyway)

#  date_hp315_jpgs
 
if [ -d fit ]
 then 
#  # mkdir fit
  for F in $@
   do convert -geometry 64% -quality 95 $F fit/$F
   touch -r $F fit/$F 
  done
  if [ -d rot ]
  then
   cd rot
   date_hp315_jpgs
   for F in $@ 
    do convert -rotate -90 -geometry 48% -quality 95 $F ../fit/$F
    touch -r $F ../fit/$F 
   done
   cd ..
  fi 
  cd fit
#  # mkdir .xvpics
  index_thumb
#  the images are still large, so index with thumbnails is created  
 else
  cd fit 
fi

if [  -d third ]
 then
#  # mkdir third
  cd ..
  for F in $@ 
  do convert -geometry 30% -quality 90 $F fit/third/$F
  touch -r $F fit/third/$F 
#  this gives the smaller file the original timestamp
  done
  if [ -d rot ]
  then
   cd rot
   for F in $@ 
    do convert -rotate -90 -geometry 30% -quality 90 $F ../fit/third/$F
    touch -r $F ../fit/third/$F 
   done
   cd ..
  fi
  cd fit/third
#  ln -s ../.xvpics ./
  index_tab
#  index is created with dates and filenames at the right, as a table 
fi

if [  -d sixth ]
 then
  # mkdir sixth
  for F in $@ 
  do convert -geometry 50% -quality 80 $F sixth/$F
   touch -r $F sixth/$F 
#  this gives the smaller file the original timestamp
  done
  cd sixth
#  ln -s ../.xvpics ./
  index_plain
#  index with just all images themselves is created, simply filling the page   
 else
  cd sixth 
fi

if [  -d thumb ]
 then
  # mkdir thumb
  for F in $@ 
  do convert -geometry 60% $F thumb/$F
   touch -r $F thumb/$F 
#  this gives the smaller file the original timestamp
  done
  cd thumb
 # ln -s ../.xvpics ./
  index_plain
#  index with just all images themselves is created, simply filling the page   
 else
  cd thumb
fi

cd ../..  
cd ..     
cd .. 

if [-d .xvpics ]
 then
#  ln -s fit/.xvpics .xvpics
  if [ -d rot ]
  then
   cd rot
   for F in $@ 
    do convert -rotate -90 -quality 95 $F ../$F
    touch -r $F ../$F 
   done
   cd ..
  fi 
  index_thumb
#  the images are very large, so index with just thumbnails is created  
  if [  -a list.htm ]
   then 
# renaming the output of index_thumb back to list.htm
   mv index.htm list.htm
  fi
  if [ -d fullsize ]
   then
#    # mkdir fullsize
    cd fullsize
#    ln -s ../$@ ./
    cd ..
  fi
fi

#if [ (du -sS | sed "s/[[:blank:]]\(.*\)//")  \
#    < (df ./ | sed  -n "2 s/ \+/ /gp" | cut -d ' ' -f 4) ] 
# then
#  ls 
#fi

cd fit/third

zgv 
# here the user is assumed to press u to create thumbnails 
# and then exit sometimes later
