#!/bin/sh
#
# Script pour générer des pages HTML en fonction des fiches de bandes dessinées
# PARAMÊTRES
#
DEBUG=0
if [ "$1" = "-d" -o "$1" = "-debug" ]; then
DEBUG=1
shift
fi
PRETS=0
if [ "$1" = "prets" ]; then
PRETS=1
shift
fi
PUBLIC=0
if [ "$1" = "all" ]; then
PUBLIC=1
shift
fi
if [ "$1" != "" ]; then
echo "update [-debug] [prets] [all]"
exit
fi
# DÉFINITIONS
#
TODAY=`date '+%A %d %B %Y'`
FREP=fiches
NREP=prochains
PREP=emprunts
DREP=html
TMP=/tmp/parties-bds
serie=""
genre=""
auteurs=""
editeur=""
numeros=""
destfiche=""
index=""
fichegenre=""
nbalbums=0
totalalbums=0
totalseries=0
coultitre="CFCFCF"
coulligne1="EBEBEB"
coulligne2="E5E5E5"
# CRÉATION DE LA FICHE HTML POUR LA SÉRIE
#
do_file () {
if [ $DEBUG = 1 ]; then
echo "===> Traitement de $fiche :"
echo " Série : $serie"
echo " Genre : $genre"
echo " Auteurs : $auteurs"
echo " Éditeur : $editeur"
echo " Numéros : $numeros"
fi
cat << EOF > $destfiche
BD - $serie
$serie
Auteur(s) |
: |
$auteurs |
Éditeur |
: |
$editeur |
Numéros |
: |
$numeros |
Genre |
: |
$genre |
Fiche |
: |
$fiche |
TITRES DISPONIBLES :
NUMÉRO |
TITRE |
EOF
nbalbums=0
fond="$coulligne2"
for num in $numeros; do
nbalbums=`expr $nbalbums + 1`
album=`grep "^$num : " $fiche | awk -F " : " '{print $2}'`
if [ "$fond" = "$coulligne2" ]; then
fond="$coulligne1"
else
fond="$coulligne2"
fi
echo " " >> $destfiche
echo " " >> $destfiche
echo " $num " >> $destfiche
echo " | " >> $destfiche
echo " " >> $destfiche
echo " $album" >> $destfiche
echo " | " >> $destfiche
echo "
" >> $destfiche
done
echo "
" >> $destfiche
echo "
" >> $destfiche
echo "
" >> $destfiche
if [ "$fichealt" != "" ]; then
echo " " >> $destfiche
if [ "$rep" = "$NREP" ]; then
echo " Albums déjà achetés." >> $destfiche
else
echo " Albums prévus à l'achat." >> $destfiche
fi
echo "
" >> $destfiche
fi
echo "
" >> $destfiche
echo " " >> $destfiche
echo " " >> $destfiche
echo " " >> $destfiche
echo " " >> $destfiche
echo " Fiche mise à jour le $TODAY." >> $destfiche
echo " " >> $destfiche
echo " | " >> $destfiche
echo " " >> $destfiche
echo " " >> $destfiche
echo " Index" >> $destfiche
echo " " >> $destfiche
echo " | " >> $destfiche
echo "
" >> $destfiche
echo "
" >> $destfiche
echo " " >> $destfiche
echo " " >> $destfiche
echo "" >> $destfiche
}
# TRAITEMENT DE LA LISTE DES FICHES ET DES ÉLÉMENTS DE L'INDEX
#
do_list () {
nomfiche=`basename $fiche`
if [ -f $ALT/$nomfiche ]; then
fichealt=$ALT/$nomfiche.html
else
fichealt=""
fi
serie=`grep SÉRIE $fiche | awk -F" : " '{print $2}'`
genre=`grep GENRE $fiche | awk -F" : " '{print $2}'`
auteurs=`grep AUTEURS $fiche | awk -F" : " '{print $2}'`
editeur=`grep ÉDITEUR $fiche | awk -F" : " '{print $2}'`
numeros=`grep NUMÉROS $fiche | awk -F" : " '{print $2}'`
destfiche=$DREP/$fiche.html
nomdest=$nomfiche.html
fichegenre=$TMP/$genre.html
touch $fichegenre
x=`wc -l $fichegenre | awk '{print $1}' | sed -e 's/.*\(.\)$/\1/'`
do_file
totalalbums=`echo "$totalalbums + $nbalbums" | bc`
if [ "$x" = "0" -o "$x" = "2" -o "$x" = "4" -o "$x" = "6" -o "$x" = "8" ]; then
fond="$coulligne1"
else
fond="$coulligne2"
fi
echo " $serie ($nbalbums) | $auteurs | $editeur |
" >> $fichegenre
}
# TRAITEMENT DES INDEX
#
do_idx () {
totalseries=0
totalalbums=0
n=0
mkdir $DREP/$rep
index=$DREP/$rep/index.html
if [ "$rep" = "$FREP" ]; then
ALT=$NREP
else
ALT=$FREP
fi
cat << EOF > $index
Liste des bandes dessinées
EOF
if [ "$rep" = "$FREP" ]; then
echo "
LISTE DES BANDES DESSINÉES
" >> $index
else
echo " LISTE DES BANDES DESSINÉES PRÉVUES À L'ACHAT
" >> $index
fi
cat << EOF >> $index
EOF
# Création des fiches et des éléments de l'index
for fiche in $rep/*; do
n=`expr $n + 1`
echo -n "." >> /dev/stderr
if [ $n = 10 -o $n = 20 -o $n = 30 -o $n = 40 ]; then
echo -n " " >> /dev/stderr
fi
if [ $n = 50 ]; then
totalseries=`echo "$totalseries + $n" | bc`
n=0
echo " $totalseries" >> /dev/stderr
fi
do_list
done
# Insertion des genres.
for genre in $TMP/*.html; do
nomgenre=`basename $genre .html`
totalgenre=`wc -l $genre | awk '{print $1}'`
if [ $PUBLIC = 1 -a "$genre" != "$TMP/Érotique.html" -o $PUBLIC = 0 ]; then
cat << EOF >> $index
|
|
$nomgenre ($totalgenre)
|
|
SÉRIE (nb albums) |
AUTEUR(S) |
ÉDITEUR |
EOF
cat $genre >> $index
fi
done
echo "" >> /dev/stderr
if [ $n != 0 ]; then
totalseries=`echo "$totalseries + $n" | bc`
fi
echo "Nombre de séries ($rep) : $totalseries" >> /dev/stderr
echo "Nombre de d'albums ($rep) : $totalalbums" >> /dev/stderr
ts=`echo "$ts + $totalseries" | bc`
ta=`echo "$ta + $totalalbums" | bc`
cat << EOF >> $index
NOMBRE TOTAL DE SÉRIES : $totalseries
NOMBRE TOTAL DE BDS : $totalalbums
Fiche mise à jour le $TODAY.
|
|
EOF
rm -rf $TMP/*
}
# TRAITEMENTS DES LISTES DE BANDES DESSINÉES & SÉRIES
#
do_all () {
ts=0
ta=0
rm -rf html/*
for rep in $FREP $NREP; do
do_idx
done
}
# TRAITEMENT DES PRÊTS
#
do_prets () {
mkdir $DREP/$PREP 2> /dev/null
nbemprunts=`ls $PREP | wc -l | awk '{print $1}'`
index=$DREP/$PREP/index.html
cat << EOF > $index
Liste des bandes dessinées empruntées
LISTE DES BANDES DESSINÉES EMPRUNTÉES
EOF
if [ $nbemprunts -gt 0 ]; then
for pret in $PREP/*; do
nompret=`basename $pret`
destpret=$DREP/$pret.html
cat << EOF > $destpret
$nompret
$nompret
SÉRIE |
NUMÉROS |
EOF
fond="$coullinge2"
cat $pret | while read ligne; do
if [ "$fond" = "$coulligne2" ]; then
fond="$coulligne1"
else
fond="$coulligne2"
fi
serie=`echo "$ligne" | sed -e 's/^\(.*\)§.*/\1/'`
numeros=`echo "$ligne" | sed -e 's/^.*§\(.*\)/\1/'`
echo " " >> $destpret
echo " $serie | " >> $destpret
echo " $numeros | " >> $destpret
echo "
" >> $destpret
done
cat << EOF >> $destpret
Fiche mise à jour le $TODAY.
|
|
EOF
echo " $nompret
" >> $index
done
else
echo " AUCUN EMPRUNT EN COURS...
" >> $index
fi
cat << EOF >> $index
Fiche mise à jour le $TODAY.
|
|
EOF
}
# TRAITEMENT DES LISTES
#
mkdir $TMP
if [ $PRETS = 0 ]; then
do_all
fi
do_prets
index=html/index.html
cat << EOF > $index
Liste des bandes dessinées
LISTE DES BANDES DESSINÉES
- Albums déjà achetés.
- Achats prévus.
- Albums empruntés.
Fiche mise à jour le $TODAY.
|
|
EOF
rm -rf $TMP