#! /bin/sh

# photoindex.sh - Version 1.0
# Builds up a HTML page with links to all the pictures on the directory,
# with the possibility to add comments
#
# Copyright (c) 2000 Raphaël HALIMI <raph@captainblood.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

VERSION="1.0"

echo -n "Ajouter un commentaire pour chaque photo ? [o/n, ENTER pour sortir] "
read WANTCOMMENT

if [ ! $WANTCOMMENT ]  ; then
   exit
elif [ $WANTCOMMENT = o -o $WANTCOMMENT = O ] ; then
   echo -n "Nom du visualiseur à utiliser : [qiv] " ; read VIEWER
   if [ ! $VIEWER ] ; then
      VIEWER=qiv
   fi
   WANTCOMMENT=YES
elif [ $WANTCOMMENT = n -o $WANTCOMMENT = N ] ; then
   echo "Ok, sans commentaire :-)"
   WANTCOMMENT=NO
else
   echo "Réponse non comprise. Abandon..."
   exit
fi

echo -n "Nom du fichier ? [index.html] " ; read FILENAME

if [ ! $FILENAME ] ; then
   FILENAME=index.html
fi

if [ -e $FILENAME ] ; then
   echo "$FILENAME existe déjà. Sauvegardé en $FILENAME.bak"
   mv "$FILENAME" "$FILENAME.bak"
fi

echo -e "<html>\n" >> $FILENAME

echo -n "Titre de la page : " ; read TITLE

echo -e "<head>\n<title>$TITLE</title>\n<head>\n" >> $FILENAME

echo -e "<body bgcolor="black" text="white">\n\n<h1>$TITLE</h1>\n" >> $FILENAME

echo -n "Introduction : " ; read INTRO

echo -e "<h3>$INTRO</h3>\n" >> $FILENAME

COUNT=1

if [ $WANTCOMMENT = "YES" ] ; then
   for I in *.jpg ; do
       $VIEWER "$I" &
       echo -n "Commentaire : " ; read COMMENT
       echo "<a href=\"$I\">Photo $COUNT</a> - $COMMENT<p>" >> $FILENAME
       COUNT=$[ $COUNT + 1 ]
   done
else
   for I in *.jpg ; do
       echo "<a href=\"$I\">Photo $COUNT</a><p>" >> $FILENAME
       COUNT=$[ $COUNT + 1 ]
   done
fi

echo -e "\n<hr>\n<div align=\"right\"><i>Page générée par photoindex.sh</i></div>" >> $FILENAME

echo -e "</body>\n\n</html>" >> $FILENAME
