VERSION=200604
clear
function put_syntax #P peut-être à revoir ...
 echo "$(gettext ' Syntaxe : ')"
 echo "$(gettext ' INSTALLER.sh [ liste | pour moi | pour tous | pour admin ] ')"
 echo "$(gettext ' Exemples dans le répertoire d installation : ~/tmp ')"
 echo "$(gettext ' -> example ./INSTALLER.sh annexer.list, pour télécharger les articles depuis wikilivres. ')"
 echo "$(gettext ' -> example ./INSTALLER.sh pour moi, pour copier les codes dans ~/Annexer. ')"
 echo ""
 exit 0
function make_clean
 echo -e "\033[5;31m ATTENTION ! Suppression du contenu du répertoire ~/tmp \033[0m "
 echo ""
 echo " Ctrl-C pour quitter."
 read -n1 -p -s Inkey
 echo "Inkey = "$Inkey
 rm -f ~/tmp/*.tmp; rm -f ~/tmp/*.txt; rm -f ~/tmp/temp/*.tmp; rm -f ~/tmp/temp/*.txt; rm -f ~/tmp/temp/*.sh;
 if [ "$1" = "pour" ] 
 then 
 if [ "$2" = "moi" ]
 then 
 echo -n "Cette option de tests 'pour moi' doit copier tous les fichiers dans le"
 echo "répertoire 'Annexer', sous le répertoire racine de l'utilisateur."
 if test -w ~/Annexer; then echo -e "\033[5;33m Le répertoire 'Annexer' pré-existe, il doit être supprimé ou renommé. \033[0m "; exit -1; fi
 mkdir ~/Annexer ~/Annexer/bin; cp ~/tmp/bin/* ~/Annexer/bin/.; chmod 755 ~/Annexer/bin/*
 ln -s -v ~/Annexer/bin/annexer ~/Annexer/annexer
 mkdir ~/Annexer/src; cp ~/tmp/src/* ~/Annexer/src/.
 mkdir ~/Annexer/doc; cp -R ~/tmp/doc/* ~/Annexer/doc/.
 echo "Le nettoyage du répertoire '~/tmp' n'est pas envisagée avec l'option de tests 'pour moi'."
 exit 0
 fi
 if [ "$2" = "tous" ]
 then 
 echo "Version française."
 echo "Cette option 'pour tous' n'est pas encore en service." 
 # copie les fichiers dans les répertoires :" 
 make_clean
 exit 0
 fi
 if [ "$2" = "admin" ]
 then 
 echo "Cette option 'pour administrateurs' n'est pas encore en service."
 make_clean
 exit 0
 fi 
 fi 
if test -d ~/tmp; then echo "~/tmp existe et ne sera pas recréé."; else mkdir -p ~/tmp; fi
 if ! test $1; then echo "Syntaxe : $0 [ liste | pour moi | pour tous | pour admin ]"; exit -1; fi
 if [ "$1" = "pour" ] 
 then copier;
 fi
 echo "Catalogue du fichier $1 entré en premier paramètre. :"
 echo " Liste des fichiers à télécharger : "
 cat $1
 echo ""
 echo " Retour-chariot pour continuer, Ctrl-C pour quitter."
 read -n1 -p -s Inkey
 echo "Inkey = "$Inkey
 cd ~/tmp
 wget -r -linf -k -p -E -i $1 -o wget-log-$1.txt
 rm html_data_conversions
 rm html_url_conversions
 if test -a "html_data_conversions"
 then echo "Le fichier html_data_conversions est présent"
 else 
 echo "s/&lt\;/</g; s/&gt\;/>/g; s/&amp\;/&/g; s/&quot\;/\"/g;" > html_data_conversions
 echo "s/&#39\;/'/g;" » html_data_conversions
 echo "s/&eacute\;/é/g; s/&eacute\;/É/g; s/&egrave\;/è/g; s/&ecirc\;/ê/g;" » html_data_conversions
 echo "s/&agrave\;/à/g;" » html_data_conversions
 echo "s/&iuml\;/ï/g;" » html_data_conversions
 echo "s/&ccedil\;/ç/g;" » html_data_conversions
 echo "s/&ntilde\;/ñ/g;" » html_data_conversions
 echo "s/&AElig\;/Æ/g;" »html_data_conversions
 echo "s/&euro\;/€/g; s/&#8364\;/€/g;" » html_data_conversions
 echo "s/&copy\;/©/g; s/&#169\;/©/g;" » html_data_conversions
 echo "s/&reg\;/®/g; s/&#174\;/®/g;" » html_data_conversions
 echo "s/&deg\;/°/g; s/&#176\;/°/g;" » html_data_conversions
 echo "s/&ordm\;/º/g;" » html_data_conversions
 echo "s/&laquo\;/«/g; s/&#171\;/«/g;" » html_data_conversions
 echo "s/&raquo\;/»/g; s/&#187\;/»/g;" » html_data_conversions
 echo "s/&micro\;/µ/g; s/&#181\;/µ/g;" » html_data_conversions
 echo "s/&para\;/¶/g; s/&#182\;/¶/g;" » html_data_conversions
 echo "s/&frac14\;/¼/g; s/&#188\;/¼/g;" » html_data_conversions
 echo "s/&frac12\;/½/g; s/&#189\;/½/g;" » html_data_conversions
 echo "s/&frac34\;/¾/g; s/&#190\;/¾/g;" » html_data_conversions
 echo "s/&#156\;/œ/g;" » html_data_conversions
 echo "s/<\/span>//g;" » html_data_conversions
 echo "s/<span class=c1>//g;" » html_data_conversions
 echo "s/<span class=\"c1\">//g;" » html_data_conversions
 echo "s/<span class=nb>//g; s/<span class=nv>//g;" » html_data_conversions
 echo "s/<span class=\"nb\">//g; s/<span class=\"nv\">//g;" » html_data_conversions
 echo "s/<span class=s1>//g; s/<span class=s2>//g; " » html_data_conversions
 echo "s/<span class=\"s1\">//g; s/<span class=\"s2\">//g; " » html_data_conversions
 echo "s/<span class=k>//g;s/<span class=m>//g;s/<span class=o>//g;" » html_data_conversions
 echo "s/<span class=\"k\">//g;s/<span class=\"m\">//g;s/<span class=\"o\">//g;" » html_data_conversions
 echo "s/<span class=p>//g; s/<span class=\"p\">//g;" » html_data_conversions
 echo "s/<span class=ch>//g; s/<span class=\"ch\">//g;" » html_data_conversions
 echo "s/#!/'\n'#!/g; s/<pre><span>/'\n'/g;" » html_data_conversions
 echo "s/%E2%80%99/\&#8217\;/g;s/%E2%82%AC/\&#8364\;/g;s/%2F/\//g;s/%3F/\?/g;" > html_url_conversions
 echo "s/%24/\$/g;s/%21/\!/g;s/%25/%/g;s/%2B/+/g;s/%3C/\\\&lt\;/g;s/%3E/\&gt\;/g;" » html_url_conversions
 echo "s/%5C/\\\/g;s/%B0/°/g" » html_url_conversions
 echo "s/%E0/à/g;s/%E2/â/g" » html_url_conversions
 echo "s/%E8/è/g;s/%E9/é/g;s/%EA/ê/g;s/%EB/ë/g" » html_url_conversions
 echo "s/%EE/î/g;s/%EF/ï/g" » html_url_conversions
 echo "s/%F4/ô/g" » html_url_conversions
 echo "s/%F9/ù/g;s/%FB/û/g" » html_url_conversions
 echo 's/%2C/,/g;s/%21/!/g;s/%3F/?/g;s/%40/@/g;s/%23/#/g;s/%24/$/g' » html_url_conversions
 echo "s/%25/%/g;" » html_url_conversions
 echo "s/%26/\&#x26\;/g;" » html_url_conversions
 echo "s/%28/(/g; s/%29/)/g;" » html_url_conversions
 echo "s/%2B/+/g;" » html_url_conversions
 echo "s/%3A/:/g;" » html_url_conversions
 echo "s/%3D/=/g;" » html_url_conversions
 echo "s/%5B/[/g;" » html_url_conversions
 echo "s/%5D/]/g" » html_url_conversions
 echo "s/%3B/;/g;s/%2F/\//g;s/%27/"/g" » html_url_conversions
 echo 's/%22/"/g' » html_url_conversions
 echo "s/%C3%A7/ç/g;s/%E7/ç/g" » html_url_conversions
 echo "s/+/ /g;s/%7E/~/g;s/\\\/\&#92\;/g" » html_url_conversions
 echo "s/%0D/\&#x0D\;/g;s/%0A/\&#x0A\;/g" » html_url_conversions
 echo "s/%C3%A0/à/g;s/%C3%A2/â/g" » html_url_conversions
 echo "s/%C3%A9/é/g;s/%C3%A8/è/g;s/%C3%AA/ê/g" » html_url_conversions
 echo "s/%C3%AE/î/g;s/%C3%AF/ï/g" » html_url_conversions
 echo "s/%C3%B4/ô/g" » html_url_conversions
 echo "s/%C3%B9/ù/g;s/%C3%BB/û/g" » html_url_conversions
 echo "s/%C2%B7/-/g;s/%C2%AB/«/g;s/%C2%BB/»/g" » html_url_conversions
 fi
echo "-----"
Srcdir=~/tmp/fr.wikibooks.org/wiki
Destdir=~/tmp
Datadir=~/tmp
echo " Répertoire source : "$Srcdir
echo " Répertoire de destination : "$Destdir
echo " Répertoire des données : "$Datadir
echo "-----"
cd $Datadir
 cat $Datadir/$1 | grep -i '.sh' | sed -f $Destdir/html_url_conversions | cut -c9- > $Datadir/shell.prj
 cat $Datadir/$1 | grep -v -e '^$' -e '.sh' | sed -f $Destdir/html_url_conversions | cut -c9- > $Datadir/data.prj
 mkdir -p $Destdir/temp $Destdir/src $Destdir/bin $Destdir/doc $Destdir/man
 while read line
 do
 echo $line | awk -F "/" '{print $NF}' > $Datadir/temp/file.tmp
 read Destfile < $Datadir/temp/file.tmp 
 echo "Destfile : "$Destfile
 echo "Fichier sélectionné : "$line.html
 #cat $line.html | grep "span class" > $Destdir/temp/$Destfile.txt
 cat $line.html | grep "span class" > $Destfile.txt
 echo -n " > $Destdir/temp/$Destfile
 while read txt
 do
 echo $txt | sed -f $Datadir/html_data_conversions | sed "s/033\[/\\\033\[/g" » $Destdir/temp/$Destfile
 cat $Destdir/temp/$Destfile | grep -v "div" | sed s/\'\'//g | sed s/\'#!/#!/g | sed '/^$/d' > $Destdir/src/$Destfile
 done < "$Destfile.txt"
 mkdir -p $Destdir/doc/$Destfile
 grep '#O' $Destdir/src/$Destfile > $Destdir/doc/$Destfile/$Destfile.algorithm
 grep '#D' $Destdir/src/$Destfile > $Destdir/doc/$Destfile/$Destfile.documentation
 grep -n -E "#H|#P|#T|#w" $Destdir/src/$Destfile > $Destdir/doc/$Destfile/$Destfile.maintainers
 echo $Destfile | sed s/.sh//g > $Destdir/temp/$Destfile.tempo
 read Exename < $Destdir/temp/$Destfile.tempo
 echo "Url de l'exécutable : "$Destdir/bin/$Exename
 echo "#! /bin/bash" > $Destdir/bin/$Exename
 echo -n " > $Destdir/doc/$Destfile/$Destfile.allcomments
 while read Script
 do
 if [ "${Script:0:1}" = '#' ] 
 then echo $Script » $Destdir/doc/$Destfile/$Destfile.allcomments
 else echo $Script » $Destdir/bin/$Exename
 fi
 done < $Destdir/src/$Destfile
 done < $Datadir/shell.prj
 rm *.txt
 put_syntax