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

#!/bin/bash
#H File: findversions.sh
#H Syntax: findversions <dir> [ ? | --v ]
#H Created by user GC 22/10/2021
#H Updated by GC 24/10/2021
#H Updated by GC to remove the line with the content "FILES"
#H

VERSION=211124

if [ "$1" = "--v" ]; then echo "findversions.sh version $VERSION"; exit 0; fi
if test -z $1; then echo "Syntax: findversions <dir> [ ? | --v ]"; exit -1; fi
if [ "$1" = "?" ]; then echo "Syntax: findversions <src_dir> [ ? | --v ]"; echo "Example: 'cd ~/Add_appendix/src; findversions .'"; exit 0; fi
#D Documentation for findversions
#D ------------------------------
#D Findversions create a list of version files in <dir> directory
#D Example: 'findversions .'
#D

#O Create src/*.sh files list and ../../sbin/* or ../bin/* files list
    Pwd=$PWD
#O Create src-Versions file
    cd $1; ls -1 *.sh | grep -v ".txt\|.list" > src_files.list
    rm SRCFILES_VERSIONS src_versions.txt src_versions2.txt
    echo "$PWD/SRCFILES_VERSIONS" > SRCFILES_VERSIONS
    echo > src_versions.txt 
    while read line
	do
	 echo -n "$line: " >> src_versions.txt
	 cat $line | grep VERSION | grep -v "echo\|unset\|FILES" >> src_versions.txt
	 echo
	done < src_files.list
	cat src_versions.txt | sed "s/.\//\n/g" > src_versions2.txt
#O Cut empty lines 
    echo "Create SRCFILES_VERSIONS.txt in '$1' directory"
    grep '\S' src_versions2.txt >> SRCFILES_VERSIONS
	rm *.txt *.list
    cd $Pwd
#
#O Create bin-files-list
    if test -d "$1/../../sbin"; then cd $1/..; rm BINFILES_VERSIONS; ls -1 | grep -v ".txt\|.list\|src\|.sh" > sbin_files.list; BINFILES=sbin_files
    elif test -d "$1/../bin"; then cd $1/../bin; rm BINFILES_VERSIONS; ls -1 | grep -v "README\|.txt" > bin_files.list; BINFILES=bin_files
    else echo "Bin file not found to create BINFILES_VERSIONS"
    fi
    echo "----"
    echo "$BINFILES.list selected"
#O Create $BINFILES.Versions txt
    rm BINFILES_VERSIONS $BINFILES.versions.txt $BINFILES.versions2.txt
    echo "$PWD/BINFILES_VERSIONS" > BINFILES_VERSIONS
    echo > $BINFILES.versions.txt 
    while read line
	do
	 echo -n "$line: " >> $BINFILES.versions.txt
	 cat $line | grep VERSION | grep -v "echo\|unset\|FILES" >> $BINFILES.versions.txt
	 echo
	done < $BINFILES.list
	cat $BINFILES.versions.txt | sed "s/.\//\n/g" | grep -v "src\n" > $BINFILES.versions2.txt
#O Cut empty lines 
    echo "Create $BINFILES BINFILES_VERSIONS"
    grep '\S' $BINFILES.versions2.txt >> BINFILES_VERSIONS
    #rm *.list *.txt
    cd $Pwd
#O end of file findversions.sh