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

Un livre de Wikilivres.
Sauter à la navigation Sauter à la recherche
  1. #!/bin/bash
    #H File    : annex (executable file). Source file is named annex.sh
    #H Version : 2020-05-24
    #H Syntax  : annex [ <book-name> || ? ] [ -v ] [ -pb || -pc ] ')"
    #H Example : ./annex TestBook (on the terminal for unit tests)
    #H Creation: 2020-03-24 
    #H   see https://fr.wikibooks.org/Auto-éditer_un_wikilivre/Auto-référencer
    #H Updated : 2020-05-15 by GC
    #H Updated : 2020-05-24 By GC to translate
    #H Update on fr:Wikibooks : 2020-05-24
    #H
    
    . gettext.sh
          if [ "$1" = "?" ]
          then {
            clear
            echo "$(gettext ' Syntax : ')"
            echo "$(gettext '   annex [ <book-name> || ? ] [ -v ] [ -pb || -pc ] ')"
            echo "$(gettext '   Options : ')"
            echo "$(gettext '     annex ?, to display the command syntax. ')"
            echo "$(gettext '     -pb for personal version with illustrations on wikibooks. ')"
            echo "$(gettext '     -pc for personal version with illustrations on 'Commons'. ')"
            echo "$(gettext '     -v  verbose mode. ')"
            exit 0
          }
          fi
    
    source $ComDir/header.inc
    
    
    Verbose="false"
    Personal="false"
    Personalwb="false"
    Personalco="false"
    
        if (("$#" > "1"))    
        then
          if [ "$2" = "-v" ]
          then
            Verbose="true";
          fi
          if [ "$2" = "-pb" ]
          then
            Personalwb="true"; Personal="true";
          fi
          if [ "$2" = "-pc" ]
          then
            Personalco="true"; Personal="true";
          fi
        fi
        if (("$#" == "3"))
        then
          if [ "$3" = "-v" ]
          then
            Verbose="true";
          fi
          if [ "$3" = "-pb" ]
          then 
            if test "$Personalco" = "false" 
            then 
              Personalwb="true"; Personal="true" 
            else 
              echo "$(gettext ' Error at command line, parameter three :$3 incompatible with parameter two :$2 ')" 
              exit 1 
            fi;
          fi
        
          if [ "$3" = "-pc" ]
          then if test "$Personalwb" = "false"; then Personalco="true"; Personal="true"; else echo "$(gettext ' Error at command line, parameter three :$3 incompatible with parameter two :$2 ')"; exit 1; fi;
          fi
        fi
        if (("$#" > "3"))    
        then  
          echo "Error : too many parameters !"
          echo "'./annex ?' to display the syntax."
          exit 1
        fi
        
    echo "$(gettext ' The variable Verbose is  initialised at : ')"$Verbose
    echo "$(gettext ' The variable Personalwb is initialised at : ')"$Personalwb
    echo "$(gettext ' The variable Personalco is initialised at : ')"$Personalco
    echo "$(gettext ' The variable Personal is initialised at : ')"$Personal
    
        echo "$(gettext ' Delete files: *.html *.str *.img *.lnk tmp temp *.tmp *.temp *.list ? ')"
        echo -e "$(gettext ' \033[31m 'y' to approve the deletion. \033[0m  ')" 
        echo "$(gettext '  Return to continue, Ctrl-C to exit. ')"
        read -n1 -p -s Inkey
        echo "$(gettext ' Inkey =  ')"$Inkey
    
        if [ "$Inkey" = "y" ]
        then {
            cd $Project
            echo -e "$(gettext ' \033[31mDeleting files.\033[0m  ')"
            rm -R *.html *.str *.img *.lnk tmp temp *.tmp *.temp *.list
         }
        else echo "$(gettext ' No file deletion ! ... Continue ... ')"
        fi
        
        if test -d $WorkDir/Verbose-mode; then echo -n "" ; else mkdir $WorkDir/Verbose-mode; fi;
        if test -d $WorkDir/Silent-mode; then echo -n "" ; else mkdir $WorkDir/Silent-mode; fi;
    
          if [ $Verbose = "true" ]
          then 
            $ComDir/list.sh $1 2> $Workdir/Verbode-mode/list-errors.txt
          else   
            $ComDir/list.sh $1 > $WorkDir/Silent-mode/list-cmd.txt 2> $Workdir/Silent-mode/list-errors.txt
          fi     
    
    Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module 'list' in silent mode. See Silent-mode/list-cmd.txt ')"
          exit 1
        fi
    exit
    cd $RepCom
    
          if [ $Verbose = "true" ]
          then
            ./download.sh $1
          else
            ./download.sh $1 > download-cmd.txt      
          fi  
    
    Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module 'download' in silent mode. See download-cmd.txt ')"
          exit 1
        fi
    
    
    cd $RepCom
    
          if [ $Verbose = "true" ]
          then   
            ./add_sclt.sh $1
          else
            ./add_sclt.sh $1 > add_sclt-cmd.txt
          fi       
            
    Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module 'add-sclt' in silent mode. See add_sclt-cmd.txt ')"
          exit 1
        fi
    
    
    cd $RepCom
    
        if [ $Personal = "false" ]
        then
          if [ $Verbose = "true" ]
          then
            ./add_sclic.sh $1
          else
            ./add_sclic $1 > add_sclic-cmd.txt
          fi 
        cat $Project/$1.sclic > $Project/$1.scli
        fi
         
    Return=$?
        if [ $Return -gt '0' ] && [ $Personal = "false" ];
        then
          echo "$(gettext ' Error in shell module 'add_sclic' in silent mode. See add_sclic-cmd.txt ')"
          exit 1
        fi        
          
    
    cd $RepCom
        if [ "$Personalco" == "true" ]
          then
          if [ "$Verbose" == "true" ]; then ./sclipco.sh $1; else ./sclipco.sh $1 > sclipco-cmd.txt; fi;
          echo "$(gettext ' sclipco.sh has been executed ')";
        fi
        if [ $Return -gt '0' ] && [ $Personalpc = "true" ];
        then
          echo "$(gettext ' Error in shell module 'slipco'. See sclipco-cmd.txt ')"
          exit 1
        fi  
        
        
    cd $RepCom
        if [ "$Personalwb" == "true" ]
          then
          if [ "$Verbose" == "true" ]; then ./sclipwb.inc $1; else ./sclipwb.inc $1 > scliwb-cmd.txt; fi;
          echo "$(gettext ' sclipwb.sh has been executed ')";
        fi
        if [ $Return -gt '0' ] && [ $Personalwb = "true" ];
        then
          echo "$(gettext ' Error in shell module 'slipwb'. See scliwb-cmd.txt ')"
          exit 1
        fi  
    
    
    cd $Project
    
          cat $1.sclt > $1.appendix
    
        if [ $Personal == "true" ]
        then cat $Project/$1.sclip >> $Project/$1.appendix; echo "$(gettext ' $1.sclip is copied to $1.appendix ')";
        else
          cat $1.sclic >> $1.appendix echo "$(gettext ' $1.sclic is copied to $1.appendix ')";
        fi
    
          echo "$(gettext ' == License == ')" >> $1.appendix
          cat $1/$1.license >> $1.appendix
          echo "" >> $1.appendix
          #echo "{{Nouvelle page imprimée}}" >> $1.appendix
          echo "$(gettext ' <br style=\"page-break-after: always\"> ')" >> $1.appendix
          
    echo ""
    echo ""
    echo ""
    echo "$(gettext ' Copy the contents of the file "$1/appendix" to the 'appendix' page of the book  ')"$1.
    exit 0
    # End annex.sh