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

Un livre de Wikilivres.
Aller à la navigation Aller à la recherche
#! /bin/bash
#H File install_annex.sh in ~/tmp or re-install_annex.sh in /usr/local/sbin directory
#H Codage UTF-8 sans BOM
#H Syntax : ~/Add_appendix/sbin/install_annex.sh [Install directory | ? ]
#H   The installation directory can be /usr/local or /usr or ~/Annexer or ~/Add_appendixby default
#P Creation date     : 2020/06/10 by GC
#P Modification date : 2020/06/12 by GC 
#P Modification date : 2021/03/28 by GC
#P Last test date    : 2021/04/17 by GC
#P This program install the directory structure for the annex program of wikibooks.
#P

#O clean screen
   clear;
   
#O Version
    VERSION=210417
    echo "Version of install_annex.sh "$VERSION

#O If the first parameter '$1' is empty or '?' print syntax.  
    if [ "$1" = "?" ]; then echo "Syntax : $0 [ <Install-directory> ]"; exit 0; fi
    if [ -z $1 ]; 
    then 
      echo "Syntax ~/Tmp/install_annex.sh [ ? | Add_appendix | Annexer | /usr/local ]"; exit 0
    fi

#P Do not use sudo
    if [ $USER = "root" ]; then echo "USER = $USER"; echo "Do not use 'sudo' please."; exit -1; fi
  
#O Go to home directory and print the current directory.
    cd ~
    echo""; echo -n "current directory = "; pwd; echo ""
    
#O If the first parameter is not empty  
    if [ $1 ];
    then 
      if [ $1 = "/usr" ]; then Installdir=$1; echo "Installdir = /usr";
      elif [ $1 = "/usr/local" ]; then  Installdir=$1; echo "Installdir = /usr/local";
      elif [ $1 = "Annexer" ]; then Installdir=~/Annexer; echo "Installdir = "$Installdir
      elif [ $1 = "Add_appendix" ]; then Installdir=~/Add_appendix; echo "Installdir = "$Installdir
      fi
    fi
    
#O Test if Install directory exist
    if [ -d $Installdir ];
    then echo " is ok, $Installdir is present." 
    else echo " $Installdir not exist, i create it"; mkdir $Installdir;
    fi    

#O Create variables : Workdir, Bindir, Testdir,
    if [ $1 = "Add_appendix" ] && [ $1 != "Annexer" ]; then Workdir=~/Add_appendix; echo "Workdir = "$Workdir; fi
    if [ $1 = "Annexer" ] && [ $1 != "Add_appendix" ]; then Workdir=~/Annexer; echo "Workdir = "$Workdir; fi
    if [ $1 = "/usr" ] || [ $1 = "/usr/local" ]; then Workdir=~/Add_appendix; echo "Workdir = "$Workdir; fi 
    if [ -d $Workdir ]; then echo " $Workdir is present."; else echo " $Workdir is not present, i create it."; mkdir $Workdir; fi
    
    Bindir="$Installdir/bin"; echo "Bindir : "$Bindir; 
    if test -d $Bindir; 
      then echo " is ok."; 
      else echo " not present, create it"; mkdir $Installdir; 
    fi
    
    Testsdir="$Workdir/tests"; echo "Units-Tests directory Testsdir = "$Testsdir; 
    if test -d $Testsdir; 
      then echo " is ok."; 
      else echo " is not present, create it"; mkdir $Testsdir;
    fi
#T Breakpoint exit 0

#O Create or recreate directory hierarchy
    cd $Workdir
    echo -n "The current directory to create $Workdir sub directories = "; pwd
    mkdir -p datas resources resources/{lang,lang/po,lang/man,man,man/de,man/en,man/fr}
    mkdir -p bin lib  sbin share src man man/{man1,fr,fr/man1,fr.UTF8,fr.UTF8/man1,es,es/man1}
    mkdir -p tests/{1-annex.lib,2-annex.sh,3-header.inc.sh,4-list.sh,5-dowload.sh,6-add_sclt.sh,7-add_sclic.sh,8-add_sclip.inc.sh,9-sclipco.sh,10-sclipwb.sh}
    echo "$Workdir/tests/1-annex.lib is the current directory to create annex.lib sub-directories"
    cd $Workdir/tests/1-annex.lib
    mkdir 11-findbook.sh 12-ecfpb.sh 13-ecfpc.sh
    cd $Workdir/share
    echo "$Workdir/share is the current directory to create sub share directories."; pwd
    mkdir -p doc icons mime locale locale/{en,fr,es,fr/LC_MESSAGES,es/LC_MESSAGES}
    
#T Breakpoint exit 0

    
#O If the file annex.sh exist in the install directory 'source', print OK annex.sh is in src dir.
    if [ -r $Installdir/src/annex.sh ];
    then 
      echo " annex.sh is OK in src directory $Installdir/src";
#O Else print 'install all annex program files in Installdir/src'
    else 
      echo " annex.sh not found in src directory $Installdir/src";
      echo " Please copy all annex internationalized files in $Installdir/src directory";
      echo "   and re-run this command to product pot files."
      exit -1;
    fi
    
#O *** Copy src files from install directory to tests directory
#P 1-annex.lib,2-annex.sh,3-header.inc.sh,4-list.sh,5-dowload.sh,6-add_sclt.sh,7-add_sclic.sh,8-add_sclip.inc.sh,9-sclipco.sh,10-sclipwb.sh
    cd $Installdir/src
    echo "$Installdir/src is the current directory to copy source files to $Testsdir directories"
    if test -a annex.sh; then cp annex.sh $Testsdir/2-annex.sh/.; chmod 755 $Testsdir/2-annex.sh/annex.sh; fi
    if test -a header.inc.sh; then cp header.inc.sh $Testsdir/3-header.inc.sh/.; chmod 755 $Testsdir/3-header.inc.sh/header.inc.sh; fi
    if test -a list.sh; then cp list.sh $Testsdir/4-list.sh/.; chmod 755 $Testsdir/4-list.sh/list.sh; fi
    if test -a download.sh; then cp download.sh $Testsdir/5-download.sh/.; chmod 755 $Testsdir/5-download.sh/download.sh; fi
    if test -a add_sclt.sh; then cp add_sclt.sh $Testsdir/6-add_sclt.sh/.; chmod 755 $Testsdir/6-add_sclt.sh/add_sclt.sh; fi
    if test -a add_sclic.sh; then cp add_sclic.sh $Testsdir/7-add_sclic.sh/.; chmod 755 $Testsdir/7-add_sclic.sh/; fi
    if test -a add_sclip.inc.sh; then cp add_sclip.inc.sh $Testsdir/8-add_sclip.inc.sh/.; chmod 755 $Testsdir/8-add_sclip.inc.sh/add_sclip.inc.sh; fi
    if test -a src/sclipco.sh; then cp src/sclipco.sh $Testsdir/9-sclipco.sh/.; chmod 755 $Testsdir/9-sclipco.sh/sclipco.sh; fi
    if test -a sclipwb.sh; then cp sclipwb.sh $Testsdir/10-sclipwb.sh/.; chmod 755 $Testsdir/10-sclipwb.sh/sclipwb.sh; fi

#O *** Copy user src files from working directory to tests directory
#O List the Workdir/src directory and recreate the tmp/shell_files.prj
    cd ~; rm -r ./tmp
    mkdir ./tmp 
    Srcdir=$Workdir/src
    ls $Srcdir > ./tmp/shell_files.prj
#T Breakpoint exit 0

#O While line read in shell_files.prj
    while read line
    do
#O   Read $line, delete comments, write the result in Testdir directory for the Units Tests.
      echo $line | awk -F "/" '{print $NF}' > tmpfile.txt
      read file < tmpfile.txt
#T	  
echo " file = "$file
      mkdir $Testdir/$file
      cp $Srcdir/$file $Testdir/$file/$file; chmod 755 $Testdir/$file/$file
    done < ./tmp/shell_files.prj

    rm $Workdir/datas/installdir.var
    echo "Installdir=$Installdir" > $Workdir/datas/installdir.var
    echo "Workdir=$Workdir" >> $Workdir/datas/installdir.var
    echo "Bindir=$Bindir" >> $Workdir/datas/installdir.var
    echo "Testsdir=$Testsdir" >> $Workdir/datas/installdir.var
    
    if [ ! test -a /usr/local/lib/annex.lib ] || [ ! test -a $Workdir/lib/annex.lib ]; 
    then
      if [ ! test -a /usr/local/lib/annex.lib ]; then Libdir=/usr/local/lib; elif [ ! test -a $Workdir/lib/annex.lib ]; then Libdir=$Workdir/lib; fi
      echo "Libdir=$Libdir" >> $Workdir/datas/installdir.var
      echo; echo "Found in $Libdir : "; ls $Libdir
    else echo; echo "Lib directory not found"
    fi
    
    if [ ! test -a /usr/local/sbin/users_install_annex.sh ] || [ ! test -a $Workdir/sbin/users_install_annex.sh ];
    then
      if [ ! test -a /usr/local/sbin/users_install_annex.sh ]; then Sbindir=/usr/local/sbin; elif [ ! test -a $Workdir/sbin/users_install_annex.sh ]; then Sbindir=$Workdir/sbin; fi
      echo "Sbindir=$Sbindir" >> $Workdir/datas/installdir.var
      echo; echo "Found in $Sbindir : "; ls $Sbindir; echo
    else echo "sbin directory not found" 
    fi
    
    echo; echo "Content of file $Workdir/datas/installdir.var"
    cat $Workdir/datas/installdir.var

#O Clean tmpfile
    rm tmpfile.txt
    #rm ~/tmp

#O Create .pot files to translate messages.
    #xgettext -L shell -o $Installdir/share/locale/en/header.inc.pot --from-code=UTF-8 $Installdir/src/header.inc.sh
    #xgettext -L shell -o $Installdir/share/locale/en/annex.pot --from-code=UTF-8 $Installdir/src/annex.sh
    xgettext -L shell -o $Workdir/resources/lang/po/header.inc.pot --from-code=UTF-8 $Installdir/src/header.inc.sh
    xgettext -L shell -o $Workdir/resources/lang/po/annex.pot --from-code=UTF-8 $Installdir/src/annex.sh
    echo "-----"    
    echo "You find Pot-files in $Workdir/resources/lang/po for translations :"
    ls $Workdir/resources/lang/po/*.pot

#O Message of the tasks to be accomplished.  
    echo "-----"
    echo "Tasks to be accomplished :"
	  echo "Modify these files as functions"
    echo "Integrate functions in the librairie $Installdir/lib/annex.lib"
    echo "Copy include functions in $Installdir/lib and include files in $Installdir/bin"
    echo "*** Copy install_annex.sh in $Installdir/sbin ***"
    
#O End 'install_annex.sh'
exit 0