Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/list.sh

Un livre de Wikilivres.
Aller à la navigation Aller à la recherche
Remarquelink={{{link}}}

Les messages en anglais sont introduits pour l'internalisation avec gettext.
les commentaires #P pour les programmeurs sont en anglais, les autres commentaires ont été réduits au minimum.

#! /bin/bash
#P File list.sh
#P Syntax in console : "./bin/list.sh <bookname>"
#P Example : "./liste.sh LivreTest" à la console.
#P Creation date : 2020-03-26
#P Modified : 2020-04-26 by GC
#P Modified : 2020-05-30 by GC for automatic installation
#P Modified : 2020-06-30 by GC to include Summary pages at the list files
#P Modified : 2021-03-17 by GC for internationalization
#P modified : 2021-03-21 by GC for for layout
#D The list of files incuded in pages 
#D   /contenu, Contenus, Contents, compilé, compile, compiled, Sommaire and
#D   /Sommaire du livre, Summary are also valid.

#P if first param is empty print the syntax and exit
    if [ -z $1 ]
    then
      echo "$(gettext ' No Parameter ')"
      echo "$(gettext ' Syntax : ~/Add-appendix/bin/list.sh <book-name> ')"; 
      exit 0;
    fi 
    
Version=210321

#P . gettext for translation
    . gettext.sh

#P initialyze the directories variables
    if [ -d share ]; 
    then 
      echo "Sharedir is OK in list.sh";
      read Sharedir < sharedir.txt
      echo $Sharedir
      read Workdir < $Sharedir/workdir.txt
      read Bindir < $Sharedir/bindir.txt
      read Libdir < $Sharedir/libdir.txt
      read Project < $Sharedir/project.txt
    else
      echo -n "current directory in list.sh "
      pwd
      echo "Sharedir not found in list.sh"
      exit -1
    fi

#P include the file header.inc
    source $Bindir/header.inc

    echo "Environnemnt variables in list.sh : "
    echo -n "Current directory = "
    pwd
    echo "Working directory = $Workdir"
    echo "Binary directory  = $Bindir"
    echo "Library directory = $Libdir"
    echo "Project directory = $Project"

#P if the file is in test mode print Version, and if no parameter print syntax
    if [ $0="./list.sh" ] || [ $0="./bin/list.sh" ] ; then echo "$0 : Version "$Version; fi
    if [ -z $1 ]; then echo "Syntax for tests : $Bindir/list.sh/ <Bookname>"; exit 0; fi

#P initialize the return value
    retour=0

#P initialize the project list in project directory 
#P   the book must be included at the root of wikibooks
    echo "https://$Site/wiki/$1" > $Project/$1.list
    
#P included automatically in project directory
    if test -e $Project/$1.contenu; then Contenu=$Project/$1.contenu; fi
    if test -r $Project/$1.Contenus; then Contenu=$Project/$1.Contenus;fi
    if test -r $Project/$1.compilé; then Contenu=$Project/$1.compilé;fi
#P manually included in project directory
    if test -r $Project/$1.contents; then Contenu=$Project/$1.Contents; fi
    if test -r $Project/$1.compile; then Contenu=$Project/$1.compile;fi
    if test -r $Project/$1.compile; then Contenu=$Project/$1.compiled;fi
    if test -r $Project/$1.Sommaire; then Contenu=$Project/$1.Sommaire;fi
    if test -r $Project/$1.Summary; then Contenu=$Project/$1.Summary;fi
    if test -r $Project/$1.Sommaire_du_livre; then Contenu=$Project/$1.Sommaire_du_livre;fi
#T print the result found
    echo "Content of macro Contenu : " $Contenu
    
    if test -z $Contenu;
    then
      clear
      echo "$(gettext ' Contents pages were not found in directory : ')$Project"
      echo ""
      echo -e "$(gettext ' \033[31m  Copy the list of pages from the edited Summary page in the file ')$Project/$1.contenu \033[0m"
      echo ""
      echo -e "$(gettext ' \033[31m  or : Copy the list of pages from the edited Compiled book, in the file ')$Project/$1.compile \033[0m"
      echo ""
      let retour+=1;
#P   The return value '$retour' is valid only for a function call and not for a direct command.
      if [ "$O" == "./list.sh" ] || [ "$O" == "./bin/list.sh" ]
      then
#T        echo "$(gettext ' return code : ')$retour"
        return $retour
      else
       exit $retour
      fi
    fi 
    
#P code extraction as appropriate case  
#P case Contents page   
    if [ "$Contenu" = "$Project/$1.contenu" ] || [ "$Contenu" = "$Project/$1.Contenus" ] ||  [ "$Contenu" = "$Project/$1.Contents" ]
    then 
      {
        echo "$(gettext ' Found Content page : ')"$Contenu
        echo "$Project/$1.list with $Contenu :"
        cat $Contenu | sed "s/\[\[/$SitePrefix/g" | tr '|' '\n' | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' >> $Project/$1.list
        cat $Contenu | grep $1 | sed "s/\[\[//g" | tr '|' '\n' |grep $1 | sed "s/$1\]\]/\r/g" | sed "s/\]\]//g" | cut -sd '/' -f2-5 > $Project/$1.prj
      }
    fi
#P case compiled pages for PediaPress      
    if [ "Contenu" = "$Project/$1".compilé" ] || [ "Contenu" = "$Project/$1".compiled" ]
    then 
      {
        echo "$(gettext ' Found Compiled page : ')"$Contenu
        echo "$Project/$1.list avec $Project/$1.compilé :"
        cat $Project/$1.compilé | sed "s/:\[\[/$SitePrefix/g" | tr '|' '\n' | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' >> $Project/$1.list
        cat $1.compilé | grep $1 | sed "s/:\[\[//g" | tr '|' '\n' | grep $1 | sed "s/$1\]\]/\r/g" | sed "s/\]\]//g" | cut -sd '/' -f2-5 > $Project/$1.prj
      }
    fi
#P case Summary pages     
    if [ "$Contenu" = "$Project/$1.Sommaire" ] || [ "$Contenu" = "$Project/$1.Sommaire_du_livre" ] || [ "$Contenu" = "$Project/$1.Summary" ]
    then 
      {
        echo "$(gettext ' Found Summary page : ')"$Contenu
        echo "$Project/$1.list with $Contenu :"
        cat $Contenu | sed "s/\[\[/\n$SitePrefix/g" | grep -e "https:" | grep -v "Catégorie:" | grep -v "#" | sed "s/{{BASEPAGENAME}}/$1/g" | tr '|' '\n' | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' >> $Project/$1.list
        exit 0
        #cat $Contenu | sed "s/\[\[/$SitePrefix/g" | tr '|' '\n' | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' >> $Project/$1.list
        cat $Contenu | grep "[[" | sed "s/\[\[//g" | tr '|' '\n' | grep $1 | sed "s/$1\]\]/\r/g" | sed "s/\]\]//g" | cut -sd '/' -f2-5 > $Project/$1.prj
      }
    fi

#P print file Project.list and file Project.prj
    echo ""
    echo "$(gettext '  File Project.list')"
    cat $Project/$1.list
    echo ""
    echo "$(gettext '  File Project.prj')"
    cat $Project/$1.prj
    echo " "
    read -p "If all OK : return to continue, Ctrl-C to quit > "

#P The return value '$retour' is valid only for a function call and not for a direct command.
    if [ "$O" == "./list.sh" ] || [ "$O" == "./bin/list.sh" ]
    then
#T      echo "$(gettext ' return code : ')$retour"
      return $retour
    else
       exit $retour
    fi

#T exit 0
# End list.sh