Aller au contenu

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

Un livre de Wikilivres.

add_appendix.sh

[modifier | modifier le wikicode]

addappendix.sh doit être converti en add_appendix.sh

  • français: add_appendix est le programme qui lance tout le programme de création de l'annexe des livres de wikibooks
    • Il fait appel au programme pre-annex pour créer les répertoire et condition d'exécution du script annex
  • anglais: add_appendix is ​​the program that launches the entire program for creating the appendix of wikibooks books
  • espagnol: add_appendix es el programa que lanza todo el programa para crear el apéndice de libros de wikilibros
#!/bin/bash
#H Header Documentation of the add_appendix.sh file
#H File add_appendix.sh
#H Syntax: add_appendix.sh <full url of wiki-book> [ ? ] [ -v ] [ -pb | -pc ]
#H the syntax is necessary for the call of the command 'annex [ <book-name> || ? ] [ -v ] [ -pb || -pc ]'
#H   ?  to print syntax
#H   -v verbose mode
#H   -pb for illustration uploaded from wikibooks
#H   -pc for illustration uploaded from commons
#H
#D Documentation of add_appendix.sh file
#D This script is the master program for creating the wiki-book appendix.
#D The firs parameter must be the full url to wikibooks book.
#D Syntax: add_appendix.sh <full url of wiki-book> [Options]
#D OPtions:
#D   ?  to print syntax
#D   -v verbose mode
#D   -pb for illustration uploaded from wikibooks
#D   -pc for illustration uploaded from commons
#D Subroutine scripts for 'add_appendix.sh' and 'add_appendix.sh' in order of execution:
#D Each of these scripts can be tested separately.
#D   pre-annex: create the directory structure of the book
#D   annex: is the master program which creates the appendix of the wiki-book
#D     header.inc: this file is included in all subroutine
#D     list: list files to download in project
#D     download: download listed files 
#D     add_sclt en_sclt.inc fr_sclt.inc: create chapter source, contributor, licence of articles
#D     add_sclic scli.inc en_sclic.inc: create standard illustration chapter src, contrib,lic
#D   add_sclipco en_sclipco.inc fr_sclipco.inc: create standard illustration chapter with src on commons
#D   add_sclipwb en_sclipwb.inc fr_sclipwb.inc: create standard illustration chapter with src on wikibooks
#D

VERSION=220216
TEXTDOMAIN=add_appendix
TEXTDOMAINDIR="~/Add_appendix/share/locale"
export TEXTDOMAINDIR

#P . gettext for translation
. gettext.sh

#O If not parameter 
    if test -z $1
    then 
      echo $"No parameter. < add_appendix | annexer > [ <full url of wiki-book> | ? ]"
      exit -1
    fi
	if [ "$1" = "?" ]
    then 
      echo $"Syntax: < add_appendix | annexer > [ <full url of wiki-book> | ? ] [ -v ] [ -pb | -pc ]"
      exit 0
    fi

#O If the command parameter is 'add_appendix' then working directory is 'Add_appendix'
    echo $0 | grep add_appendix > command.txt
	if test -s command.txt 
    then 
      Workdir=~/Add_appendix
      rm command.txt > /dev/null
      echo $0 | grep annexer > command.txt
#O Elif the command parameter is 'annexer' then working directory is 'Annexer'
    elif test -s command.txt
    then 
      Workdir=~/Annexer
      rm command.txt > /dev/null
#O Else print Working directory is not found. Exit from script.
    else 
      echo $"Working directory is not found. Exit from script."
      exit -1
#O End if
    fi
	
#O The books directory is '$Workdir/books' create it if not exist
    if test -d $Workdir/books
	then 
	  echo $"Working directory found: $Workdir"
	  echo $"script version: $VERSION"
	else
	  echo $"$Workdir/books is not found"
	  echo $"$Workdir/books creation" 
	  install -d $Workdir/books 
	fi

#O If the file installdir.var not exist, create it.
	if test -e $Workdir/vars/installdir.var
	then 
	  echo $"OK installdir.var exist"
	else
	  install -d $Workdir/books $Workdir/vars
	fi

#O Initialize installdir.var
    echo "Workdir=$Workdir" > $Workdir/vars/installdir.var
	if test -d $Workdir/bin 
	then
      echo "$Workdir/bin exist then Installdir=$Workdir"
	  Installdir=$Workdir
      echo "Installdir=$Workdir" >> $Workdir/vars/installdir.var
	  Bindir=$Workdir/bin
      echo "Bindir=$Bindir" >> $Workdir/vars/installdir.var
	  Booksdir=$Workdir/books
      echo "Booksdir=$Workdir/books" >> $Workdir/vars/installdir.var
	  Datasdir=$Workdir/datas
      echo "Datasdir=$Workdir/datas" >> $Workdir/vars/installdir.var
	  Libdir=$Workdir/lib
      echo "Libdir=$Workdir/lib" >> $Workdir/vars/installdir.var
	  Sharedir=$Workdir/share
      echo "Sharedir=$Workdir/share" >> $Workdir/vars/installdir.var
	  Srcdir=$Workdir/src
      echo "Srcdir=$Workdir/src" >> $Workdir/vars/installdir.var
	  Testdir=$Workdir/tests
      echo "Testsdir=$Workdir/tests" >> $Workdir/vars/installdir.var
	  Varsdir=$Workdir/vars
      echo "Varsdir=$Workdir/vars" >> $Workdir/vars/installdir.var
	else
      echo "$Workdir/bin does not exist then Installdir=/usr/local"
	  Installdir=/usr/local
      echo "Installdir=/usr/local" >> $Workdir/vars/installdir.var
	  Bindir=/usr/local/bin
      echo "Bindir=$Bindir" >> $Workdir/vars/installdir.var
	  Booksdir=$Workdir/books
      echo "Booksdir=$Workdir/books" >> $Workdir/vars/installdir.var
	  Datasdir=/usr/local/datas
      echo "Datasdir=/usr/local/datas" >> $Workdir/vars/installdir.var
	  Libdir=/usr/local/lib
      echo "Libdir=/usr/local/lib" >> $Workdir/vars/installdir.var
	  Sharedir=/usr/local/share
      echo "$Sharedir=/usr/local/share" >> $Workdir/vars/installdir.var
	  Srcdir=/usr/local/src/Add_appendix
      echo "Srcdir=/usr/local/src/Add_appendix" >> $Workdir/vars/installdir.var
	  Varsdir=$Workdir/vars
      echo "Varsdir=$Workdir/vars" >> $Workdir/vars/installdir.var
	fi
#T test break cat $Workdir/vars/installdir.var; exit 0

#O Update variables from installdir.var if necessary
    # source $HOME/Add_appendix/vars/installdir.var

#O Test if first parameter is https and wikibooks site
    rm -f *.txt > /dev/null
	echo $1 | grep -e "wikibooks.org" > wikibooks-site.txt
	echo -n "wikibooks-site.txt: "
    cat wikibooks-site.txt
    echo
	if test -s wikibooks-site.txt
	then 
      echo $"OK to continue with book site validation"
      rm -f wikibooks-site.txt
	else 
      echo $"First parameter entry is not a wikibooks site"
      exit -1
	fi	
#T test break exit 0
#O Test if the url content a book file
    rm -f valid-book-site.txt > /dev/null
    echo $1 | grep "Collection\|Compilation\|Content\|Contenu\|Sommaire\|Summary" > valid-book-site.txt
	if test -s valid-book-site.txt
	then 
      echo $"OK to continue with pre-annex"
      rm -f valid-book-site.txt
	else 
      echo $"First parameter entry is not a valid book site"
      exit -1
	fi
	
#O Valider les variables de mode bavard et Bindir Report-silent
    if [ "$2" = "-v" ] || [ "$3" = "-v" ]
    then Verbose="true"
    else 
      Verbose=$"false"
      echo $"Verbose mode = $Verbose"
    fi

#P If not exist $Workdir/temp/Report-silent-mode create it
	if test -d $Workdir/temp/Report-silent-mode 
	then echo "$Workdir/temp/Report-silent-mode exist" > /dev/null
	else install -d $Workdir/temp/Report-silent-mode; fi
	
#P Running pre-annex
    echo
    echo
    echo $"*** Continue with pre-annex ***"
    if [ $Verbose = "true" ]
    then 
	   echo $"Verbose mode = true ? :$Verbose"
       $Bindir/pre-annex $1 $2 $3
    else
	  echo $"Verbose mode = false ? $Verbose"
      $Bindir/pre-annex $1 > $Workdir/temp/Report-silent-mode/pre-annex-cmd.txt
    fi  
#P Test if $TEXTDOMAIN=add_appendix and restore if not
    if [ $TEXTDOMAIN != "add_appendix" ]
    then TEXTDOMAIN=add_appendix
    fi
#P Return value from pre-annex        
    Return=$?
    if [ $Return -gt '0' ]
    then
      echo "$(gettext ' Error in shell module pre-annex in silent mode. See $Workdir/temp/Report-silent-mode/pre-annex-cmd.txt ')"
      exit 1
    fi

#P Running annex
    echo; echo; echo "*** Continue with annex and sub-annex scripts ***"
#T    echo "$Varsdir +++ $Libdir"
	source $Libdir/annex.lib
	findbook $1
	echo "Bookname : $Bookname"
#T	exit 0
    if [ "$Verbose" = "true" ]
    then   
      $Bindir/annex $Bookname $2 $3
    else
      $Bindir/annex $Bookname $2 $3 > $Workdir/temp/Report-silent-mode/annex-cmd.txt
    fi 
    if [ $TEXTDOMAIN != "add_appendix" ]
    then TEXTDOMAIN=add_appendix
    fi
#P Return value from annex        
    Return=$?
    if [ $Return -gt '0' ]
    then
      echo "$(gettext ' Error in shell module annex in silent mode. See $Workdir/temp/Report-silent-mode/annex-cmd.txt ')"
      exit 1
    fi
exit 0
#O End of add_appendix.sh
  • annexer est le programme qui lance tout le programme de création de l'annexe des livres de wikibooks
    • annexer permet de créer la documentation en français, vérifie la validité de la ligne de commandes et fait appel à add_appendix.
    • les traductions de add_appendix en français font de annexer un programme en langue française
#!/bin/bash
#H Documentation de l'enête du fichier annexer.sh
#H File annexer.sh
#H syntaxe annexer <adresse url complète du livre> [ ? ] [ -v ] [ -pb | -pc ]
#H la syntaxe est nessessitée pour l'appel de:
#H   < add_appendix | annexer > [ <full url of wiki-book> | ? ] [ -v ] [ -pb | -pc ]
#H   annex [ <book-name> || ? ] [ -v ] [ -pb || -pc ]
#H OPtions:
#H   ? pour demander la syntaxe
#H   -v est le mode bavard
#H   -pb pour illustration téléchargées sur wikilivres
#H   -pc pour illustration téléchargées sur commons
#H
#D Documentation du fichier annexer.sh
#D Ce scipt est le programme maître pour créer l'annexe des wiki-livres.
#D Le premier paramètre doit être l'adresse, (l'url) complète du livre.
#D Syntaxe: annexer <adresse url complète du livre> [Options]
#D OPtions:
#D   ? pour demander la syntaxe
#D   -v est le mode bavard de l'exécution des scripts enfants
#D   -pb pour illustration téléchargées sur wikilivres
#D   -pc pour illustration téléchargées sur commons
#D Scripts sous-programmes pour 'annexer' et 'add_appendix' dans l'ordre d'exécution: 
#D Chacun de ces scripts est éprouvable séparément
#D   pre-annex: crée la structure des répertoires du livre
#D   annex: est le programme maître qui crée l'annexe du wiki-livre
#D     header.inc: 
#D     list 
#D     download 
#D     add_sclt en_sclt.inc fr_sclt.inc 
#D     add_sclic scli.inc en_sclic.inc
#D   add_sclipco en_sclipco.inc fr_sclipco.inc
#D   add_sclipwb en_sclipwb.inc fr_sclipwb.inc 
#D

VERSION=220304
TEXTDOMAIN=annexer
TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAINDIR

#O Utiliser le script de add_appendix commun aux deux versions avec la même traduction
#D L'installation commune dans /usr/local ne crée pas de répertoire bin dans le répertoire de travail
#D Ceci est mis à profit pour trouver les répertoire de travail et les binaires appropriés.
#D Lorsque l'installation est commune le répertoire de travail est toujours $HOME/Add_appendix 
if test -e $HOME/Annexer/bin/add_appendix; then $HOME/Annexer/bin/add_appendix $1 $2 $3
elif test -e /usr/local/bin/add_appendix; then /usr/local/bin/add_appendix $1 $2 $3
else echo $"the script add_appendix is not found: in Annexer/bin nor in /usr/local/bin, exit"; exit -1
fi
#O End of annexer.sh