Auto-éditer un wikilivre/Annexer (Version internationalisée)/cp-src2bin.sh

Un livre de Wikilivres.
Aller à la navigation Aller à la recherche
Install this executable shell code in sbin ( /usr/local/sbin | ~/Add_appendix/sbin | ~/Annexer/sbin )
Installer ce code shell éxécutable dans sbin
espagnol ; Instale este código de shell ejecutable en sbin
#! /bin/bash
#H File users_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/users_install_annex.sh [Install directory | ? ]
#H   The installation directory can be /usr/local or /usr or ~/Annexer or ~/Add_appendixby default
#P Creation date     : 2021/04/16 by GC
#P Modification date : 2021/04/18 by Clara
#P Modification date : 
#P Last test date    : 2021/04/19 by Clara
#P This program install the directory structure for the annex program of wikibooks.
#P

#O clean screen
   clear;
   
#O Version
    VERSION=210419
    if [ "$1" = "-v" ]; then echo "Version of users_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/users_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
    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
#T Breakpoint exit 0

#O Create or recreate directory hierarchy
    cd $Workdir
    echo -n "The current directory to create $Workdir sub directories = "; pwd
    mkdir bin datas lib resources sbin share src
    cd share
    echo "$Workdir/share is the current directory to create sub share directories."; pwd
    mkdir man doc doc/html 
    mkdir -p man man/{man1,fr,fr/man1,fr.UTF8,fr.UTF8/man1,es,es/man1}
#T Breakpoint exit 0
    
#O If the install dir is '/usr/local' and if the number of files in /usr/local/src dir is not 9 files
#O   print copy all source files to appropriate directory
    rm -r ~/tmp; mkdir ~/tmp
    if test "$1"="/usr/local/" 
    then
      ls -l /usr/local/src > ~/tmp/src.txt
      wc -l ~/tmp/src.txt | cut -d ' ' -f1 > ~/tmp/nblines.txt
      read nblines < ~/tmp/nblines.txt
      if test "$nblines" != "10" 
      then 
        echo " Nuber of files '$nblines' in /usr/local/src is incorrect" 
        echo " Please copy all nine annex internationalized sources files in $Workdir/src directory to update $Installdir/bin";
      fi 
    fi

#T Test if  working/src dir empty   
    ls -l $Workdir/src | grep total | cut -d ' ' -f 2 > ~/tmp/n.txt
    read n < ~/tmp/n.txt
    if test "$n" = "0" 
    then 
      echo " Nb files in $Workdir/src is '$n'"
      echo; echo " Directory $Workdir/src is empty"
      echo " If you want install or update $Installdir/bin directory, copy all nine annex internationalized sources files in $Workdir/src directory";
    else
      ls -l $Workdir/src > ~/tmp/src.txt
      wc -l ~/tmp/src.txt | cut -d ' ' -f1 > ~/tmp/nblines.txt
      read local nblines < ~/tmp/nblines.txt
      if "$nblines" != "10" 
      then 
        echo " Nuber of files '$nbline' in /usr/local/src is incorrect" 
        echo " Please copy all nine annex internationalized sources files in $Workdir/src directory to update bin directory"
      else
        echo " Want you update $Bindir files ?"
        read -s -n1 -pinkey  inkey
        if test "$inkey"="y"
        then
#O       *** Copy src files from install directory to bin 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 $Workdir/src
          Lbindir=$Workdir/bin
          echo "$Workdir/src is the current directory to copy source files to $LBindir directories"
          if ! test -e annex.sh; then cat annex.sh | grep -v "#o\|#P\|#T" > $LBindir/annex; chmod 755 $LBindir/annex; fi
          if ! test -e header.inc.sh; then cat header.inc.sh | grep -v "#o\|#P\|#T" > $LBindir/header.inc; chmod 755 $Bindir/header.inc; fi
          if ! test -e list.sh; then cat list.sh | grep -v "#o\|#P\|#T" > $Bindir/list; chmod 755 $LBindir/list; fi 
          if ! test -e download.sh; then cat download.sh | grep -v "#o\|#P\|#T" > $Bindir/download; chmod 755 $LBindir/download; fi
          if ! test -e add_sclt.sh; then cat add_sclt.sh | grep -v "#o\|#P\|#T" > $Bindir/add_sclt; chmod 755 $LBindir/add_sclt; fi
          if ! test -e add_sclic.sh; then cat add_sclic.sh | grep -v "#o\|#P\|#T" > $Bindir/add_sclic; chmod 755 $LBindir/add_sclic; fi
          if ! test -e add_sclip.inc.sh; then cat add_sclip.inc.sh | grep -v "#o\|#P\|#T" > $Bindir/add_sclip.inc; chmod 755 $LBindir/add_sclip.inc; fi
          if ! test -e src/sclipco.sh; then cat src/sclipco.sh | grep -v "#o\|#P\|#T" > $Bindir/src/sclipco; chmod 755 $LBindir/sclipco; fi
          if ! test -e sclipwb.sh; then cat sclipwb.sh | grep -v "#o\|#P\|#T" > $Bindir/sclipwb; chmod 755 $LBindir/sclipwb; fi
#O       Copy user bin files from working directory to installdir bin directory if install directory is /usr/local
          if [ "$Bindir" = "/usr/local" ]; then sudo mv $Lbindir*.* $bindir/.; cp -f *.sh /usr/local/src/.; fi
        else echo " $LBindir directorie is not updated"
      fi
    fi
  fi
      
    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
    
    if ! test -e /usr/local/lib/annex.lib  ||  ! test -e $Workdir/lib/annex.lib 
    then
      if  ! test -e /usr/local/lib/annex.lib ; then Libdir=/usr/local/lib; elif  ! test -e $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 -e /usr/local/sbin/users_install_annex.sh  ||  ! test -e $Workdir/sbin/users_install_annex.sh ;
    then
      if  ! test -e /usr/local/sbin/users_install_annex.sh ; then Sbindir=/usr/local/sbin; elif  ! test -e $Workdir/sbin/users_install_annex.sh ; then Sbindir=$Workdir/sbin; fi
      echo "Sbindir=$Sbindir" >> $Workdir/datas/installdir.var
      echo; echo "annex.lib 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
	
	if [ $1 = "Annexer" ]; 
	then 
	  echo; echo "Commande = $1"
	  echo; echo "Se connecter à l'url :"
	  echo "https://fr.wikibooks.org/wiki/Autoéditer_un_wikilivre/Annexer_(Version_internationalisée)#src.orig_en_français"
	  echo "Copier les pages de codes, les coller dans un éditeur de texte et les enregistrer dans les répertoires spécialisés"
	  echo "Les fichiers : "
	  echo " sources, dans le répertoire $1/src"
	  echo " de données dans $1/datas"
	  echo " de librairies, dans $1/lib"
	  echo " d'exécutables de maintenance, dans  $1/sbin (chmod 755 * dans sbin)"
	  echo " de documentation dans $1/share/doc"
	  echo " de manuels dans $1/share/man"
	  echo; echo "Finalement rééxécuter cette commande $1/sbin/users_install_annex.sh"
	fi
	  
	if [ $1 = "Add_appendix" ] || [ "$1" = "/usr/local" ];
	then 
	  echo; echo "Command = $1"
	  echo; echo "Login to url :"
	  echo "https://fr.wikibooks.org/wiki/Autoéditer_un_wikilivre/Annexer_(Version_internationalisée)#Codes_sources_(internationalized_source_code)"
      echo "Copy code pages in memory, paste them in a text editor and save in the specialized directory"
	  echo "The files :"
	  echo " sources in the directory Add_appendix/src"
	  echo " datas in Add_appendix/datas"
	  echo " library in Add_appendix/lib"
	  echo " executable for maintenance, in Add_appendix/sbin (chmod 755 * in sbin)"
	  echo " documentation in Add_appendix/share/doc"
	  echo " manuals in Add_appendix/share/man"
	  echo; echo "Finaly reexecute this command Add_appendix/sbin/users_install_annex.sh"
	  if [ "$1" = "/usr/local" ]; then echo "copy all files and directories to /usr/local :"; echo "  sudo cp -R Add_appendix/* $1/.";fi
	fi

#O Clean tmpfiles
    rm -r ~/tmp