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

Remarquelink={{{link}}}

incomplet en raison de l'absence des commandes compose.
testabble jusqu'à la commande list.sh inclue.

  1. #!/bin/bash
    #H File    : annex and-or 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 by GC
    #H           see https://fr.wikibooks.org/w/index.php?title=Auto-éditer_un_wikilivre/Auto-référencer#Entête_des_modules
    #H Updated : 2020-05-15 by GC
    #H Updated : 2020-05-24 by GC to translate
    #H Updated : 2021-03-16 by User GC
    #H Update on fr:Wikibooks : 2021-03-26 incomplet
    #H
    
    #P header.inc is included in each module for its individual test and 
    #P   permanently in this command file 'annex'.
    
    #P export permanently ~/Add_appendix/bin in ~/.bashrc file : www is not recommended 
    #P echo "export PATH=$PATH:/home/user/mes_prog" >> /home/user/.bashrc 
    #P
    #P export ~/Add_appendix/bin for this session only
    export PATH=$PATH:~/Add_appendix/bin 
    #T env | grep Add_appendix
    
    #P . gettext for translation
    . gettext.sh
    
    Version=210326
    
    #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/annex [ <book-name> | ? ] [ -v ] [ -pb | -pc ] ')"; 
          exit 0;
        fi 
            
    #P if help whis the '?' character
        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
    
        if [ -d share ]; 
        then 
          echo "Sharedir is OK in annex command";
          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 $0 "
          pwd
          echo "Sharedir not found in $0 command"
          exit -1
        fi
    
    #P include header.inc in binary environnment ~/Add_appendix/bin
        source $Bindir/header.inc
        
    #T spotting
        echo "*** 'annex' command ***"
        
    #T env | grep Add_appendix
        echo "Installdir : "$Installdir
    
    #P initializing modes 
        Verbose="false"
        Personal="false"
        Personalwb="false"
        Personalco="false"   
    #T exit 0
        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 ' -annex- 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 "$(gettext ' -annex- Error : too many parameters ! ')"
          echo "$(gettext ' ./annex ? to display the syntax. ')"
          exit 1
        fi
    
    #P printing variables from the command line
        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 ""
        
    #P print files in project directorie, and delete the files according to the answer
        echo "$(gettext ' -Command annex- Files in project directory : ')"
        ls $Project
        echo "$(gettext ' Delete in the project directory : *.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 rm $Workdir/Verbose-mode/*.txt; echo -n "" ; else mkdir $Workdir/Verbose-mode; fi;
        if test -d $Workdir/Silent-mode; then rm $Workdir/Silent-mode/*.txt; echo -n "" ; else mkdir $Workdir/Silent-mode; fi;
        
    #T echo "Installdir : in annex command : $Installdir"
    
    #P running list.sh
        if [ $Verbose = "true" ]
        then $Bindir/list.sh $1
        else $Bindir/list.sh $1 > $Workdir/Silent-mode/list-cmd.txt
        fi     
    #P return value from list.sh
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module list in silent mode. See See Silent-mode/list-cmd.txt ')"
          exit 1
        fi
    #T 
    exit
    
    #P running downloads.sh
        if [ $Verbose = "true" ]
        then $Bindir/download.sh $1
        else $Bindir/download.sh $1 > $Workdir/Silent-mode/download-cmd.txt      
        fi  
    #P return value from downloads.sh
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module download in silent mode. See See Silent-mode/download-cmd.txt ')"
          exit 1
        fi
    
    #P running add_sclt.sh
        if [ $Verbose = "true" ]
        then   
          $Bindir/add_sclt.sh $1
        else
          $Bindir/add_sclt.sh $1 > $Workdir/Silent-mode/add_sclt-cmd.txt
        fi       
    #P return value from add_sclt.sh        
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module add-sclt in silent mode. See See Silent-mode/add_sclt-cmd.txt ')"
          exit 1
        fi
    
    #P running add_sclic.sh
        if [ $Personal = "false" ]
        then
          if [ $Verbose = "true" ]
          then
            $Bindir/add_sclic.sh $1
          else
            $Bindir/add_sclic.sh $1 > $Workdir/Silent-mode/add_sclic-cmd.txt
          fi 
          cat $Project/$1.sclic > $Project/$1.scli
        fi
    #P return value from add_sclic     
        Return=$?
        if [ $Return -gt '0' ] && [ $Personal = "false" ];
        then
          echo "$(gettext ' Error in shell module add_sclic in silent mode. See Silent-mode/add_sclic-cmd.txt ')"
          exit 1
        fi        
          
    #P if option -pc is validated, running sclipco.sh
        if [ "$Personalco" == "true" ]
        then
          if [ "$Verbose" == "true" ]; then ./sclipco.sh $1; else ./sclipco.sh $1 > $Workdir/Silent-mode/sclipco-cmd.txt; fi;
          echo "$(gettext ' sclipco.sh has been executed ')";
        fi
    #P return value from slipco.sh
        Return=$?
        if [ $Return -gt '0' ] && [ $Personalpc = "true" ];
        then
          echo "$(gettext ' Error in shell module slipco. See Silent-mode/sclipco-cmd.txt ')"
          exit 1
        fi     
        
    #P if option -pb is validated, running sclipw
        if [ "$Personalwb" == "true" ]
        then
          if [ "$Verbose" == "true" ]; then ./sclipwb.inc $1; else ./sclipwb.inc $1 > $Workdir/Silent-mode/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 See Silent-mode/scliwb-cmd.txt ')"
          exit 1
        fi  
    
    #P in project :
        cd $Project
        cat $1.sclt > $1.appendix
    
    #P ? sclip.inc ...?
        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 command