Différences entre les versions de « Auto-éditer un wikilivre/Annexer (Version internationalisée)/cp-src2bin.sh »

Re-copie du fichier source
m (Ajout d'un commentaire)
(Re-copie du fichier source)
 
<syntaxhighlight lang="Bash">
#! /bin/bash
#P File : .../sbin/cp-src2bin.sh. This file must be copied in executable mode
#H File users_install_annex.sh in ~/tmp or re-install_annex.sh in /usr/local/sbin directory
#P Copy the source files to the executables directory.
#H Codage UTF-8 sans BOM
#P The tests directory is used to individual test bash files from annex programm.
#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
 
clear
#O clean screen
clear;
#O Version
VERSION=210419
if [ "$1" = "-v" ]; then echo "Version of users_install_annex.sh "$VERSION; exit 0; fi
 
VERSION=210419
#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
 
if [ "$1" = "-v" ]; then echo "cp-src2bin.sh : VERSION $VERSION"; 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
 
#P Find the current directory
#O Create variables : Workdir, Bindir
pwd > pwd.txt
if [ $1 = "Add_appendix" ] && [ $1 != "Annexer" ]; then Workdir=~/Add_appendix; echo "Workdir = "$Workdir; fi
read Currentdir < pwd.txt
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
 
#P Find the working name directory
#O Create or recreate directory hierarchy
cat pwd.txt | cut -d "/" -f4 > workname.txt
cd $Workdir
read Workname < workname.txt
echo -n "The current directory to create $Workdir sub directories = "; pwd
echo -n "Working name directory= $Workname"
mkdir bin datas lib resources sbin share src
if [ $Workname = "Annexer" ] || [ $Workname = "Add_appendix" ]
cd share
then echo " is found";
echo "$Workdir/share is the current directory to create sub share directories."; pwd
else echo " is not a working name directory"; exit -1
mkdir man doc doc/html
fi
mkdir -p man man/{man1,fr,fr/man1,fr.UTF8,fr.UTF8/man1,es,es/man1}
#T Breakpoint exit 0
#P Find full directories install, working etc.
source ~/$Workname/datas/installdir.var
#O If the install dir is '/usr/local' and if the number of files in /usr/local/src dir is not 9 files
echo "Install directory : $Installdir"
#O print copy all source files to appropriate directory
echo "Working dir : $Workdir"
rm -r ~/tmp; mkdir ~/tmp
echo "Bin dir : $Bindir"
if test "$1"="/usr/local/"
echo "Lib dir : $Libdir"
echo "Sbindir : $Sbindir"
#T Test break exit 0
 
#P Make list files.pj
echo "Make files list from src directory in files.pj"
ls $Installdir/src/*.sh > files.pj
 
#P If files.pj is not empty copy all files *.sh to executable directory
if [ -s "files.pj" ];
then
echo "files in files.pj :"
ls -l /usr/local/src > ~/tmp/src.txt
cat files.pj
wc -l ~/tmp/src.txt | cut -d ' ' -f1 > ~/tmp/nblines.txt
else
read nblines < ~/tmp/nblines.txt
echo "files.pj is empty, exit from cp-src2bin.sh"
if test "$nblines" != "10"
thenexit 1
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
 
#P Copy copy without extension .sh, and make files executables
#T Test if working/src dir empty
while read line
ls -l $Workdir/src | grep total | cut -d ' ' -f 2 > ~/tmp/n.txt
do
read n < ~/tmp/n.txt
#T echo "copy the ligne $line from files.pj '.sh' in the file exename without extension .sh"
if test "$n" = "0"
echo $line | sed s/.sh//g | awk -F "/" '{print $NF}'> exename.txt
then
 
echo " Nb files in $Workdir/src is '$n'"
#P Affect the value in 'exename.txt' at the variable $Exename
echo; echo " Directory $Workdir/src is empty"
read Exename < exename.txt
echo " If you want install or update $Installdir/bin directory, copy all nine annex internationalized sources files in $Workdir/src directory";
echo "copy $Installdir/src/$Exename.sh to $Installdir/bin/$Exename"
else
cat $Installdir/src/$Exename.sh | grep -v "#O\|#P\|#T" > $Installdir/bin/$Exename
ls -l $Workdir/src > ~/tmp/src.txt
echo "Add mode 755 'executable' at file $Installdir/bin/$Exename"
wc -l ~/tmp/src.txt | cut -d ' ' -f1 > ~/tmp/nblines.txt
readchmod local755 nblines < ~$Installdir/tmpbin/nblines.txt$Exename
ifecho "$nblines----" != "10"
done < then files.pj
#T Breakpoint exit 0
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"
#P clean sbin directory
else
rm files.pj pwd.txt exename.txt
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
 
#P End cp-src2bin
#O Clean tmpfiles
rm -r ~/tmp
</syntaxhighlight>
{{Autocat}}