change var name and stop script if error

This commit is contained in:
rick 2023-01-17 23:32:47 +01:00
parent 76c726c81b
commit 31d0917827
Signed by: Rick
GPG key ID: 4A6223D66294EB20

View file

@ -18,9 +18,11 @@
# this program. If not, see <https://www.gnu.org/licenses/>. # this program. If not, see <https://www.gnu.org/licenses/>.
################################################################################ ################################################################################
set -e
# liste des fichiers html à générer # liste des fichiers html à générer
#files="autres.html copaings.html index.html ou.html projets.html rss.html apropos.html" #files="autres.html copaings.html index.html ou.html projets.html rss.html apropos.html"
files="lang" langDir="lang"
tmpHeader="/tmp/header.html" tmpHeader="/tmp/header.html"
annexes="css img" annexes="css img"
@ -115,12 +117,12 @@ fi
mkdir $target mkdir $target
for l in $(ls -d $files/*/ | cut -d\/ -f2) for l in $(ls -d $langDir/*/ | cut -d\/ -f2)
do do
generate_header lang/$l/header.link generate_header lang/$l/header.link
echo "Create folder $l in $target..." echo "Create folder $l in $target..."
mkdir "$target/$l" mkdir "$target/$l"
for i in $(ls $files/$l) for i in $(ls $langDir/$l)
do do
echo "[$l] Generate $i..." echo "[$l] Generate $i..."
file="$target/$l/$i" file="$target/$l/$i"
@ -133,7 +135,7 @@ do
# https://stackoverflow.com/questions/68573654/copy-a-content-from-one-file-and-need-to-replace-in-another-file-using-sed # https://stackoverflow.com/questions/68573654/copy-a-content-from-one-file-and-need-to-replace-in-another-file-using-sed
# https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string # https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string
# TODO pouvoir mettre plusieurs lignes link # TODO pouvoir mettre plusieurs lignes link
newHeader=$(sed -n -e "/%link%/,/%endlink%/p" $files/$l/$i | sed -e "/%link%/d;/%endlink%/d" -e 's/\//\\\//g' -e "i<link " -e 'a\ \\\/>' | tr -d "\n") newHeader=$(sed -n -e "/%link%/,/%endlink%/p" $langDir/$l/$i | sed -e "/%link%/d;/%endlink%/d" -e 's/\//\\\//g' -e "i<link " -e 'a\ \\\/>' | tr -d "\n")
# je suppose que s'il y a moins de 10 caractères, alors on ne prend pas # je suppose que s'il y a moins de 10 caractères, alors on ne prend pas
# en compte le nouveau link. # en compte le nouveau link.
@ -146,7 +148,7 @@ do
sed -i -e "/%links%/a$newHeader" $file sed -i -e "/%links%/a$newHeader" $file
fi fi
cat $files/$l/$i >> $file cat $langDir/$l/$i >> $file
cat $footer >> $file cat $footer >> $file
# nettoyage des balises précédemment utilisées # nettoyage des balises précédemment utilisées
sed -i -e "/%links%/d" $file sed -i -e "/%links%/d" $file
@ -161,7 +163,7 @@ do
done done
echo "Header links translation..." echo "Header links translation..."
mapfile translateHeader < lang/links.config mapfile translateHeader < $langDir/links.config
langs=${translateHeader[0]} langs=${translateHeader[0]}
nbLang=$(echo "$langs" | grep -c "|") nbLang=$(echo "$langs" | grep -c "|")
for (( i=1; i<${#translateHeader[@]}; i++ )) for (( i=1; i<${#translateHeader[@]}; i++ ))
@ -180,7 +182,7 @@ do
lang=$(echo ${translateHeader[0]} | cut -d\| -f$(( $k + 1 )) | tr -d " ") lang=$(echo ${translateHeader[0]} | cut -d\| -f$(( $k + 1 )) | tr -d " ")
file=$(echo ${translateHeader[$i]} | cut -d\| -f$(( $k + 1 )) | tr -d " ") file=$(echo ${translateHeader[$i]} | cut -d\| -f$(( $k + 1 )) | tr -d " ")
sed -i -e "s/href=\"\/$lang\/.*\.html/href=\"\/$lang\/$file.html/" www/$currentLang/$currentFile.html sed -i -e "s/href=\"\/$lang\/.*\.html/href=\"\/$lang\/$file.html/" $target/$currentLang/$currentFile.html
done done
done done
done done