Ajout régénération fichier world.mt depuis script upgrade.sh

This commit is contained in:
Sys Quatre 2019-05-01 12:11:42 +02:00
parent 640efc2ea1
commit 557e312955
1 changed files with 102 additions and 8 deletions

View File

@ -46,6 +46,7 @@ usage() {
echo -e "\tbitchange\tLes paramètres de bitchange"
echo -e "\tchristmas\tLes paramètres de christmas_craft"
echo -e "\trandommsg\tLes messages aléatoires"
echo -e "\tworldmt\tRégénère le fichier world.mt (peut-être utile avec l'option -m)"
echo "Exemples:"
echo -e "\tMise à jour des mods :"
echo -e "\t$ ./upgrade.sh -m"
@ -55,6 +56,93 @@ usage() {
echo -e "\t$ ./upgrade.sh -m -w nalc-1.1 -b 1.1 -f news"
}
regen_worldmt() {
local worldfile=$serverpath/world.mt
echo "Regénération du fichier $worldfile..."
# Faire une sauvegarde du fichier world.mt actuel
cp $worldfile $serverpath/world.mt.bak
# Créer un nouveau fichier temporaire sans les lignes commençant par load_mod
local i=0
cat $worldfile | while read -r line; do
local match=$(echo $line | grep load_mod_)
if [[ -z $match ]]; then
if [[ $i -eq 0 ]]; then
echo $line > /tmp/world.mt
else
echo $line >> /tmp/world.mt
fi
fi
i=$(( $i+1 ))
done
# Recréation des liens symboliques des mods dans le dossier minetest
# et générer une ligne "load_mod_<mod> = true ou false" pour chaque mod
# et l'ajouter au fichier
local mods_path=$serverpath/nalc-server-mods
local mods_minetest=$serverpath/minetest/mods
local mods_custom=$serverpath/custom/mods
rm $mods_minetest/*
if [[ -d $mods_custom ]]; then
ls $mods_custom | while read -r mod; do
if [[ -d $mods_cutom/$mod ]]; then
rm $mods_path/$mod
ln -s $mods_custom/$mod $mods_path/$mod
fi
done
fi
local i=0
local md[1]="" # Mods to disable
local mods="3d_armor_ip 3d_armor_sfinv"
if [[ $BRANCH == "1.0" ]]; then
mods="3d_armor_ip 3d_armor_sfinv worldedit_brush"
fi
for mod in $mods; do
i=$(( $i+1 ))
md[$i]=$mod
done
ls $mods_path | while read -r mod; do
if [[ -d $mods_path/$mod ]]; then
ln -s $mods_path/$mod $mods_minetest/$mod
if [[ -e $mods_path/$mod/modpack.txt ]]; then
ls $mods_path/$mod | while read -r submod; do
if [[ -d $mods_path/$mod/$submod ]]; then
local mod_enable="true"
for (( modn=1; modn<=$i; modn++ )); do
if [[ ${md[$modn]} == $submod ]]; then
mod_enable="false"
fi
done
echo "load_mod_$submod = $mod_enable" >> /tmp/world.mt
fi
done
else
local mod_enable="true"
for (( modn=1; modn<=$i; modn++ )); do
if [[ ${md[$modn]} == $mod ]]; then
mod_enable="false"
fi
done
echo "load_mod_$mod = $mod_enable" >> /tmp/world.mt
fi
fi
done
# Remplacement du l'ancien world.mt par le nouveau
mv /tmp/world.mt $serverpath/world.mt
echo "Regénération terminé."
}
update_mods() {
local mods_path=$serverpath/nalc-server-mods
if [[ ! -d $mods_path ]]; then
@ -81,12 +169,13 @@ update_world() {
fi
if [[ $WORLD_FILE == "all" ]]; then
WORLD_FILE="news technic fbn fbnp bitchange christmas randommsg"
WORLD_FILE="news technic fbn fbnp bitchange christmas randommsg worldmt"
fi
for w_file in $WORLD_FILE; do
local file=""
local file_dest=""
local do_copy=1
case $w_file in
news)
file_dest=$world_dest/news.txt
@ -109,16 +198,21 @@ update_world() {
randommsg)
file_dest=$world_dest/random_messages
file=$world_repos/random_messages-$BRANCH;;
worldmt)
do_copy=0
regen_worldmt;;
*)
error;;
esac
if [[ ! -e $file ]]; then
error "Le fichier $file n'existe pas"
if [[ $do_copy -eq 1 ]]; then
if [[ ! -e $file ]]; then
error "Le fichier $file n'existe pas"
fi
echo "Copie de $file vers $file_dest"
cp -up $file $file_dest
fi
echo "Copie de $file vers $file_dest"
cp -up $file $file_dest
done
}
@ -130,13 +224,13 @@ action() {
if [[ $UP_MODS -eq 1 ]]; then
echo "Mise à jour des mods dans $serverpath/nalc-server-mods..."
update_mods
echo "Terminé."
echo "Mise à jour des mods terminé."
fi
if [[ -n $WORLD_NAME && -n $BRANCH ]]; then
echo "Mise à jour de $WORLD_FILE dans $serverpath/minetest/worlds/$WORLD_NAME de la branche $BRANCH..."
update_world
echo "Terminé."
echo "Mise à jour des fichiers world terminé."
elif [[ -n $WORLD_NAME || -n $BRANCH ]]; then
error
fi