Auto-éditer un wikilivre/install annex.sh

Remarquelink={{{link}}}

L'intallation classique est ./install_annex.sh Annexer pour le code d'origine en français et ./install_annex.sh Add_ppendix pour la version internationalisée.

#! /bin/bash
#H File install_annex.sh in 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/21 by GC
#P This file installs the program 'annex' to create the 'Appendix' pages for wikibooks.
#P

#O Version
    Version=200321
    echo "Version of install_annex.sh "$Version

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

#O cd home directory and print the home directory.
    cd
    echo""; echo -n "current directory = "; pwd; echo ""
    
#O if $1 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=$Installdir/sbin; echo "Units-Tests-dir for commands and translations = Testdir = "$Testdir; 
    if test -d $Testdir; 
      then echo " is ok."; 
      else echo " is not present, create it"; mkdir $Testdir;
    fi
#T exit 0

#O Create or recreate directory hierarchy
      cd $Installdir 
      echo -n "The current directory to create $Installdir sub directories = "; pwd
      mkdir -p datas resources src
      mkdir -p bin lib  sbin share man man/{man1,fr,fr/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 
exit 0

#O cd home directory and print the home 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 [ test -a $Installdir/src/annex.sh ];
    then echo " annex.sh is OK in src directory $Installdir/src";
#O else print install all annex 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";
      exit -1;
    fi
    
#O List the Installdir/src directory and recreate the tmp/shell_files.prj
    rm -r ./tmp; rm ./tmpfiles
    mkdir ./tmp 
    ls $Installdir/src/*.sh > ./tmp/shell_files.prj
#T 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
      read file < tmpfile
#T	  echo " file = "$file
      cat $line | grep -v '#' > $Testdir/$file
    done < ./tmp/shell_files.prj
	rm ./tmpfile
    #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 $Testdir/header.inc#.sh
    xgettext -L shell -o $Installdir/share/locale/en/annex.pot --from-code=UTF-8 $Testdir/annex#.sh

#O Message of the tasks to be accomplished.  
    echo "-----"
    echo "Tasks to be accomplished :"
	echo "Modify these files as functions"
    echo "Integrate these functions in the librairie $Installdir/lib/annex.lib"
    
#O Fin du programme d'installation install_annex.sh
exit 0