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/05/19 by GC
#P Last test date    : 2021/05/19 by GC
#P This program installs the directory structure for the annex program of wikibooks.
#P

#O clean screen
   clear;
   
#O Version
    VERSION=210519
    if [ "$1" = "--v" ]; then echo "Version of install_annex.sh $VERSION"; exit 0; fi

#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 [ --v | ? | 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
    
    Testdir="$Workdir/tests"; echo "Units-Tests directory Testdir = "$Testdir; 
    if test -d $Testdir; 
      then echo " is ok."; 
      else echo " is not present, create it"; mkdir $Testdir;
    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 books lib lib/src resources sbin share src temp vars man man/{man1,fr,fr/man1,fr.UTF8,fr.UTF8/man1,es,es/man1}
    cd share
    echo "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 findbook.sh, ecfpb.sh, ecfpc.sh, exist in the lib/src directory, build the annex.lib file
    if test -e $Workdir/lib/src/findbook.sh && test -e $Workdir/lib/src/ecfpb.sh && test -e $Wordir/lib/src/ecfpc;
    then
      cat $Workdir/lib/src/findbook.sh | grep -v "#O\|#P\|#T" > $Workdir/lib/annex.lib
      cat $Workdir/lib/src/ecfpb.sh | grep -v "#O\|#P\|#T" >> $Workdir/lib/annex.lib
      cat $Workdir/lib/src/ecfpc.sh | grep -v "#O\|#P\|#T" >> $Workdir/lib/annex.lib
    else echo "annex.lib is not builded or not updated in $Workdir/lib/annex.lib"
    fi

#O Cd home directory and print the current directory.
    cd ~
    echo""; echo -n "current directory = "; pwd; echo ""
    
#O If the file annex.sh exist in the sources directory 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 List the Installdir/src directory and recreate the tmp/shell_files.prj
    rm -r ./tmp
    mkdir ./tmp 
    Srcdir=$Installdir/src
    ls $Srcdir/*.sh > ./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
#O Clean tmpfile
    rm tmpfile.txt
    #rm -r ./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"
    echo "See also users_install_annex.sh, best command for user"
    
#O Put install dirs to  /vars/installdir.var   
    rm $Workdir/vars/installdir.var
    echo "Installdir=$Installdir" > $Workdir/vars/installdir.var
    echo "Workdir=$Workdir" >> $Workdir/vars/installdir.var    
    echo; echo "Content of file $Workdir/vars/installdir.var"
    cat $Workdir/vars/installdir.var
   
#O End 'install_annex.sh'