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

Un livre de Wikilivres.
Sauter à la navigation Sauter à la recherche
  1. #!/bin/bash
    #H File    : src/header.inc.sh 
    #H Syntax  : annex.inc [ <book-name> || ? ] [ -v ] [ -pb || -pc ] ')"
    #H Example : ./header.inc LivreTest (on the terminal, in bin directory, for unit tests)
    #H Creation: 2020-03-24 
    #H           see //fr.wikibooks.org/w/index.php?title=Auto-éditer_un_wikilivre/Auto-référencer#Annexer_(main)
    #H Updated : 2020-05-15 by GC
    #H Updated : 2020-05-24 By GC to translate
    #H Updated : 2020-06-15 by GC to update for translations and tests
    #H Update on fr:Wikibooks : 2020-06-15
    #H
    
    . gettext.sh
    Version="200615"
    clear
    if [ "$0" = "./header.inc" ]; then pwd > tmp.txt
    else
      echo $0 | awk -F"/" '{ for (i=1;i<NF;i++) print $i}' | tr '\n' '/' | sed "s/bin\//bin/g" > tmp.txt
    fi
    read Tmpdir < tmp.txt
    rm tmp.txt
    cd $Tmpdir; pwd > tmp.txt
    read Bindir < tmp.txt
    rm tmp.txt
    Tmpdir=""
    
    if test -d $Bindir
       then 
          echo "$(gettext ' The commands directory :  ')"$Bindir"$(gettext '  is correct ! ')"
       else
          echo "$(gettext ' The commands directory  ')"$Bindir"$(gettext '  is not found ! ')"
    fi
    
    echo $Bindir | awk -F"/" '{ for (i=1;i<=NF;i++) print $i}' | tr '\n' '/' | sed s/"\/bin\/"//g > tmp.txt
    read Installdir < tmp.txt
    rm tmp.txt
    echo "$(gettext ' The Installdir :  ')"$Installdir"$(gettext '  is found ! ')"
    
    Libdir="$Installdir/lib"
    if test -d "$Libdir" 
       then 
          echo "$(gettext ' The lib directory :  ')"$Bindir"$(gettext '  is correct ! ')"
       else
          echo "$(gettext ' The lib directory  ')"$Bindir"$(gettext '  is not found ! ')"
    fi
    
    Workdir=~/Add_appendix
    
    if test -d $Workdir
       then 
          echo "$(gettext ' The work directory :  ')"$Workdir"$(gettext '  is correct ! ')"
       else
          mkdir $Workdir
          echo "$(gettext ' The work directory  ')"$Workdir"$(gettext '  is created ! ')";
    fi
    
    Conversions=$Workdir/conversions.dat
    
    if [ $0 = "./header.inc" ] 
      then 
        echo "$(gettext ' When the command is ./header.inc, then conversion file is recreated to ')"$Workdir/conversions.dat
        rm $Workdir/conversions.dat
        fi
    
    if test -a "$Conversions"
        then echo "$(gettext ' The conversion file is present ')"
        else {
    echo "s/%24/\$/g;s/%21/\!/g;s/%25/%/g;s/%2B/+/g;s/%3C/\\\&lt\;/g;s/%3E/\&gt\;/g;" >> $Conversions
    echo "s/%5C/\\\/g;s/%B0/°/g" >> $Conversions
    echo "s/%E0/à/g;s/%E2/â/g" >> $Conversions
    echo "s/%E8/è/g;s/%E9/é/g;s/%EA/ê/g;s/%EB/ë/g" >> $Conversions
    echo "s/%EE/î/g;s/%EF/ï/g" >> $Conversions
    echo "s/%F4/ô/g" >> $Conversions
    echo "s/%F9/ù/g;s/%FB/û/g" >> $Conversions
    echo "s/%25/%/g;" >> $Conversions
    echo "s/%28/(/g;s/%29/)/g;" >> $Conversions
    echo "s/%2B/+/g;" >> $Conversions
    echo "s/%3A/:/g;" >> $Conversions
    echo "s/%3D/=/g;" >> $Conversions
    echo "s/%5B/[/g;" >> $Conversions
    echo "s/%5D/]/g" >> $Conversions
    echo "s/%3B/;/g;s/%2F/\//g;s/%27/''/g" >> $Conversions
    echo 's/%22/"/g' >> $Conversions
    echo "s/%C3%A7/ç/g;s/%E7/ç/g" >> $Conversions
    echo "s/%C3%A0/à/g;s/%C3%A2/â/g" >> $Conversions
    echo "s/%C3%A9/é/g;s/%C3%A8/è/g;s/%C3%AA/ê/g" >> $Conversions
    echo "s/%C3%AE/î/g;s/%C3%AF/ï/g" >> $Conversions
    echo "s/%C3%B4/ô/g" >> $Conversions
    echo "s/%C3%B9/ù/g;s/%C3%BB/û/g" >> $Conversions
    echo "s/%C2%B7/-/g;s/%C2%AB/«/g;s/%C2%BB/»/g" >> $Conversions
    }
    echo "$(gettext ' The file conversions.dat is created or updated. ')"
    fi
    
    function header_syntax
    {
    	   echo "$(gettext ' Syntax of the header.inc command in test mode: header.inc <book> ')"
           echo "$(gettext ' Example : "header.inc LivreTest" or "header.inc ?" ')"
    	   echo ""
           exit 0
    }
    
    if test -z "$1"
        then 
           echo "-----"
           echo "$(gettext ' Error: no input parameter, see  the command : annex ? ')"
             if [ $0 = "./header.inc" ]; 
    		   then header_syntax; 
    		   else echo "$(gettext ' Syntax  : $0  [ <book-name> || ? ] [ -v ] [ -pb || -pc ] ')"; fi
    	   exit 1;
    	else if [ "$1" != "?" ]; then echo "$(gettext ' Project : Creation of the annex page of the book :  ')"$1; fi;
    fi
    
    if test $1; then
       if [ "$1" = "?" ]
       then
          clear
          header_syntax
       fi
    fi
    
    Project=$Workdir/$1
    echo "$(gettext ' Project directory :  ')"$Project
    echo "----------"
    
    if test -d $Project
       then 
          echo "$(gettext ' The project directory :  ')"$Project"$(gettext '  is correct ! ')"
       else
          mkdir $Project
          echo "$(gettext ' The working directory  ')"$Project"$(gettext '  is created ! ')"
    fi
    
    echo "Default Site name is fr.wikibooks.org, when your book is in another site please modify Site.txt" > $Workdir/README
    if test -a $Workdir/Site.txt
      then 
        read Site < $Workdir/Site.txt
        SitePrefix="https:\/\/$Site\/wiki\/"
      else
        Site="fr.wikibooks.org"
    	SitePrefix="https:\/\/fr.wikibooks.org\/wiki\/"
      fi
    
    echo "----------"
    echo "$(gettext ' Project name:  ')"$1
    echo "$(gettext ' $Site:  ')"$Site
    echo "$(gettext ' $SitePrefix for the shell command sed. ')"$SitePrefix
    echo "----------"
    echo "$(gettext ' List of links to articles to be analyzed: ')"
    echo "$(gettext ' Test if the file : $Project/$1.list, exists: ')$Project/$1.list"
    if test -a $Project/$1.list
       then 
        echo "$(gettext ' Yes, the file : $Project/$1.list exists. ')" 
       else 
        echo -e "$(gettext ' \033[31mNo, ')"$Project/$1.list"$(gettext ' is not yet created.\033[0m ')"
    fi
    echo "----------"
    echo "$(gettext ' Test if the file : $Project/$1.prj, exists: ')$Project/$1.prj"
    # ? echo "$(gettext ' List of articles in the project: ')"
    if test -a $Project/$1.prj;
       then 
          echo "$(gettext ' Yes the file : "$Project/$1.prj exists ')"; 
       else 
       echo -e "$(gettext ' \033[31mNo, ')"$Project/$1.prj"$(gettext ' is not yet created.\033[0m ')"
    fi
    echo "----------"
    echo "$(gettext ' Contents of the project directory: ')"$Project
    ls -al $Project 
    echo "----------"
    
    cd $Project
    # End header.inc.sh