« Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/download.sh » : différence entre les versions

Un livre de Wikilivres.
Contenu supprimé Contenu ajouté
Création
 
Ligne 152 : Ligne 152 :
#O End tests_download.bash
#O End tests_download.bash
</syntaxhighlight>
</syntaxhighlight>

{{AutoCat}}

Version du 29 mai 2021 à 03:00

download.sh

#! /bin/bash
#H File download.sh
#H Syntax in console : "./bin/dowload <bookname>"
#H Example : "./download.sh LivreTest" in test mode in a terminal
#H Creation date : 28/03/2020
#H Modified : 26 april 2020 par GC
#H Modified : 30 may 2020 par GC for automatic insrallation
#H Modified : 27 may 2021 for Add_Appendix
#H Documentation version de la documentation on WikiLivres le : 26 april 2020
#H
#D download.sh documentation
#D header.inc is included and there is no need to recreate the environment
#D   variables
#D Download creates or recreates a local html book with html subdirectories of all articles
#D Create a concatenated sub-list locale.list of the book from book articles-list 
#D To document the book with its subpages :
#D Create a directory containing the main html page of the book and local directories 
#D   containing an html version of the articles 
#D
VERSION=210528
#O . gettext.sh for translation
   . gettext.sh
#O Include the file header.inc
    if test -e ~/Add_appendix/bin/header.inc; then source ~/Add_appendix/bin/header.inc
    else echo "$Bindir/header.inc not found. Execute sbin/cp-src2bin.sh"; exit -1
    fi
#O Download the complete book structure in working directory
    Projectdir=$Workdir/books/$1
    cd $Projectdir
    mkdir temp
    if [ "$2" = "--t" ]; then echo "current dir : "; pwd; fi
    echo "télécharger tous des répertoires du livre '$1'"
    wget -r -linf -k -p -E  -i $1.list -o $Projectdir/temp/wget-log-download.txt
    echo "----------"
#O Move the html pages into working sub-directories to document the pages and sub pages
#O   create a local list to the downloaded directories $ Projectdir/$1.locale.list
      echo "create the complete concatenated hierarchy of the directories of the book '$1'"
      cat $Projectdir/$1.list | sed "s/https:\/\///g" | sed "s/\ /\\\ /g" | tr '\n' ',' > $Projectdir/$1.locale.list
      echo "   Concatenated local list $Projectdir/$1.locale.list :"
      echo ""
      cat $Projectdir/$1.locale.list
      echo "----------"
#O Copy the html files to respective directories
#O   Create a file with the pagename $Projectdir/$1.mainPage
      echo "créer la page du lien local vers la page principale, 'le livre'."
      echo "create the page from the local link to the main page, 'the book'"
      cat $Projectdir/$1.locale.list | sed "s/ /\\ /g" | cut -d ',' -f1 > $Projectdir/$1.mainPage
      echo "----------"
#O   Initialize the variable $mainPage
      read mainPage < $Projectdir/$1.mainPage
      echo "variable mainPage = $mainPage"     
    #T cat $Projet/$1.mainPage | awk -F"/" '{print NF}' > nbchamps
    #T read NbChamps < nbchamps
    #T echo "Variable NbChamps = $NbChamps"
      echo "----------"
#O   Create a file of the working directories to be created.
      ls "$mainPage" | sed "s/.html//g"  > $Projectdir/$1.dirs
      echo "sub-working-diectories : "
      cat  $Projectdir/$1.dirs
      echo "----------" 
#O   Copy the html pages and subpages in the respective directories
      while read line
      do
        echo "$line".html | sed "s/https:\/\///g" | tr '\n' ' ' > source
        read Source < source
        echo "Source = $Source"

        echo "$line" | awk -F"/" '{ print $NF }'| tr '\n' '/' > destination 
        read dir < destination
        mkdir $dir
        echo "$line".html | awk -F"/" '{ print $NF }' >> destination
        read Destination < destination
        echo "Destination = $Destination"
        echo "Copier : cp ./$Source $Destination"
        cp -f "./$Source" "$Destination"
      done < $Projectdir/$1.list
      rm source ; rm destination
#O Quitter le programme d'essai et passer à la création de la page "Annexe" des articles.
    echo "----------"
# echo -en "\033[31mRetour-chariot une pour créer l'Annexe des articles, Ctrl-C pour quitter.\033[0m "
# read -p ">"
# "\033[31mRetour-chariot une pour créer l'Annexe, Ctrl-C pour quitter >"
# exit 0
# End download.sh

tests_download.sh

#! /bin/bash
#P file : tests_download.bash
#P Syntax ./tests_download.bash

VERSION=210528

#O Clean screen
    clear
#O Include install variables
    pwd > pwd.txt
    if cat pwd.txt | grep ~/Annexer; then Workdir=~/Annexer; elif cat pwd.txt | grep ~/Add_appendix; \
    then Workdir=~/Add_appendix; else echo "Workind directory not found"; exit -1;fi
    rm pwd.txt    
#O Download global variables
    source $Workdir/vars/installdir.var
#O Print tests_download.bash version
    echo " tests_download.bash version = $VERSION"
    sleep 2
#T    echo "----"
#O Control if the test download.sh file is clean
    echo -e "\033[1;33m Control download.sh in the local test directory \033[0m" > text-control.txt 
    echo -e "\033[1;33m Please check that the comment line does not contain an command \033[0m" >> text-control.txt
    echo -e "\033[1;33m ----  \033[0m"
    grep -n -e "#T\|#O\|#P" download.sh >> text-control.txt
    more text-control.txt
    echo; echo -e "\033[47m\033[1;30m Continue ? \033[0m"
    read -s -e -n 1 -t 60 -p "y/n ? : " Inkey;echo
#T     echo "Inkey = $Inkey"
    if [ "$Inkey" != 'y' ]; then echo " Inkey is not yes, or time out after 60 sec, exit from $0"; exit 0;fi
#O test download.sh in test-mode
    echo "Command ./download.sh - --t to verify environnement variables"
    echo "  in test mode with first param empty"
    ./download.sh - --t
    echo;echo " wait for 2 sec"
    sleep 5; echo "----"
#O Test with first param empty
    echo "Command ./download.sh without parameter"
    ./download.sh
    echo;echo " wait for 2 sec"
    sleep 2; echo "----"
#O Test, all with option --t 
   echo " All tests whith parameter --t"   
#O download local books for tests
    Inkey=1
    for i in 'seq 1 9'
    do 
      cat $Workdir/tests/sitelist.txt; echo
      echo -e "\033[47m\033[1;30m Choose the site number to test \033[0m"
      read -s -n1 -p "inkey number 1 to 9 : " Inkey; echo;
      if [ "$Inkey" = "1" ]; then ./download.sh LivreTest --t
      elif [ "$Inkey" = "2" ]; then ./download.sh Hélices_de_navires_à_déplacement --t
      elif [ "$Inkey" = "3" ]; then ./download.sh TestBook --t
      elif [ "$Inkey" = "4" ]; then ./download.sh Mkd_\(Extracteur_de_documents\) --t
      elif [ "$Inkey" = "5" ]; then ./download.sh Faire_fleurir_le_sel --t
      elif [ "$Inkey" = "6" ]; then ./download.sh Faire_sa_fleur_de_sel --t      
      elif [ "$Inkey" = "7" ]; then ./download.sh Guide_to_Unix --t
      elif [ "$Inkey" = "8" ]; then ./download.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./download.sh LivreTest --t
      else echo "$inkey local url of site not found"; exit 0
      fi
    done
#O End tests_download.bash