« Auto-éditer un wikilivre/addappendix/reconstruction et tests du script addappendix » : différence entre les versions

m
→‎script addapendix.sh : WL:RD : * diverses retouches
m (→‎script tests_addappendix.bash : WL:RD : * diverses retouches)
m (→‎script addapendix.sh : WL:RD : * diverses retouches)
#P -------------------------------
 
VERSION=220113220117
TEXTDOMAIN=addappendix
TEXTDOMAINDIR="/usr/share/locale"
#O Then print the short syntax ant exit -1
then
echo -n -e "\033[31m"
echo -n $"No parameter. addappendix [ <full url of book> | ? | -v ]"
exit -1
echo -e "\033[0m"
fi
exit -1
fi
 
#O If firt parameter is '?'
if [ "$1" = "?" ]
#O Then print syntax whih examples and exit 0
then
echo -n -e "\033[32m"
echo $"Syntax: addappendix [ <full url of book> | -v ]"
echo $"Example 1 Syntax: addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix[ <full url of book> | -v ]"
echo $" Example 21 : addappendix https://fren.wikibooks.org/wiki/WikilivresWikibooks:CompilationsCollections/Faire_sa_fleur_de_selGuide_to_Unix"
echo $" Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel"
echo -e "\033[0m"
exit 0
fi
#O Then print addapendix version
then
echo $"addapendix-n version-e : $VERSION"\033[32m"
echo -n $"addapendix version : $VERSION"
echo -e "\033[0m"
exit 0
fi
#O *** First parameter analysis ***
#T echo "File $1 exists"
#O Test if the first parameter points to wikibooks.org/wiki
if echo $1 | grep wikibooks.org/wiki
then
echo "OK-n for-e wikibooks.org/wiki"\033[32m"
echo -n $" is a wiki-books"
echo -e "\033[0m"
else
echo "$1-n is-e not a book on wikibooks"\033[31m"
echo -n $"$1 is not a wiki-book on wikibooks.org"
echo -e "\033[0m"
exit -1
fi
#O Check if $1 file exist
if wget --spider $1 2>/dev/null; then
echo -n -e "\033[32m"
echo "File $1 exists"
echo -n $"File $1 does notis existfound"
echo -e "\033[0m"
else
echo -n -e "\033[31m"
echo "File $1 does not exist"
echo -n $"File $1 is not found"
echo -e "\033[0m"
exit -1
fi
#O Find the bookname
echo $1 | awk -F"/" ' { print $NF }' > bookname.txt
read BOOKNAMEBookname<bookname.txt
echo; "Bookecho name-n :-e $BOOKNAME"\033[1;32m"
echo -n $"Book name : $Bookname"
#O Create Bookname diredtory
echo -e "\033[0m"
install -d ~/Add_appendix/books/$BOOKNAME
echo $1 | awk -F"/" ' { print $5 }' > Compilations.txt
#O Télécharger la page compilée
read Compilations<Compilations.txt
cd ~/Add_appendix/books/$BOOKNAME
echo -n -e "\033[1;32m"
wget -r -linif -k -p -E -i $1
echo -n $"Compilations name: $Compilations"
echo -e "\033[0m"
if [ "$Compilations" = "Wikilivres:Compilations" ]; then Suffix=compiled; fi
if [ "$Compilations" = "Wikibokoks:Collections" ]; then Suffix=collection; fi
if test -z $Suffix; then Suffix=compiled; fi
echo -n -e "\033[1;32m"
echo "Suffix = $Suffix"
echo -e "\033[0m"
 
#O Create Bookname diredtorydirectory
install -d ~/Add_appendix/books/$BOOKNAMEBookname
cd Projectdir=~/Add_appendix/books/$BOOKNAMEBookname
#O Create temp directory in Wordir
Workdir=~/Add_appendix
mkdir -p $Workdir/temp
##O Create the file bookname.suffix
#T ***********************
#O Create $Projectdir/resources/TMP to download
mkdir -p $Projectdir/resources/TMP
#O Download $1
cd $Projectdir/resources/TMP
rm -Rf $Projectdir/resources/TMP/* 2> /dev/null
wget -N $1 -o $Workdir/temp/wget-log-télécharger.txt
ls -1 > ../filename.txt
read Filename<../filename.txt
if [ "$Filename" = "filename.txt" ]; then echo $"line 113: \$Filename = filename.txt error, exit -1"; exit -1; fi
rm ../filename.txt
#O go up in the directory resources and rename 'TMP' '$Filename'
cd ..
if test -e $Filename; then rm -R $Filename; fi
if test -d $Filename 2>/dev/null
then rm -R $Filename 2>/dev/null
fi
mv TMP $Filename
cd $Filename
#T ls -al
cat $Filename|grep "<li><a href=">extract-li
cat extract-li | sed "s/title=\"/\n[[/g" | grep -v "<li><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>\|Cat\|<div" >extract-li1
cat $Filename|grep "<dd><a href=">extract-dd
cat extract-dd | sed "s/title=\"/\n[[/g" | grep -v "<dd><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>" >extract-dd1
cat extract-dd1 > $Bookname.$Suffix
cat extract-li1 >> $Bookname.$Suffix
#T echo "$Bookname.$Suffix = "
cp $Bookname.$Suffix $Projectdir/$Bookname.$Suffix
#T ***********************
if test -e $Projectdir/$Bookname.$Suffix
then
echo -n -e "\033[1;32m"
echo -n "$Bookname.$Suffix : "
echo -e "\033[0m"
cat $Projectdir/$Bookname.$Suffix
fi
#O Download the book in html form
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E )
echo; echo "Dowload $1"
wget -r -linf -k -p -E "$1" -o $Workdir/temp/wget-log-télécharger.txt
 
 
exit 0