290 lines
7.7 KiB
Bash
Executable File
290 lines
7.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Author: Sys4
|
|
# License: GPLv3
|
|
|
|
serverpath=$(pwd)
|
|
UP_MODS=0
|
|
WORLD_FILE=all
|
|
|
|
strip() {
|
|
echo $1 | cut -d \' -f 2
|
|
}
|
|
|
|
verif() {
|
|
if [[ $? -gt 0 ]]; then
|
|
echo "Erreur ! Arrêt du script."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
error() {
|
|
if [[ -n $1 ]]; then
|
|
echo "ERREUR : $1 !"
|
|
else
|
|
echo "ERREUR : paramètres invalides !" >&2
|
|
echo "utilisez l'option -h pour en savoir plus" >&2
|
|
fi
|
|
exit 1
|
|
}
|
|
|
|
usage() {
|
|
echo "Usage : ./upgrade.sh [-h|--help] | [-s|--serverpath <path>] [-m|--mods] [ -w|--world <world> < -b|--branch <branch> [-f|--world-file <arg>] > ]"
|
|
echo "WARNING: This is for an experimental usage. Don't use it!"
|
|
echo "Options:"
|
|
echo -e "\t-h --help\t\tAffiche cette aide"
|
|
echo -e "\t-s --serverpath <path>\tRépertoire racine du serveur"
|
|
echo -e "\t-m --mods\t\tMet à jour les mods"
|
|
echo -e "\t-w --world <name>\tNom de la carte"
|
|
echo -e "\t-b --branch <branch>\tBranche concerné"
|
|
echo -e "\t-f --world-file <arg>\tFichier(s) a mettre à jour :"
|
|
echo -e "\t<arg> doit être une des valeur suivante :"
|
|
echo -e "\tall\t\tToutes les mise à jour suivantes seront executés sauf 'mtconf'"
|
|
echo -e "\tnews\t\tLes news du serveur"
|
|
echo -e "\ttechnic\t\tLes paramètres de technic"
|
|
echo -e "\tfbn\t\tLes paramètres de forbidden_names"
|
|
echo -e "\tfbnp\t\tLes paramètres de forbidden_names_patterns"
|
|
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 -e "\tmtconf\tMet à jour le fichier minetest.conf"
|
|
echo "Exemples:"
|
|
echo -e "\tMise à jour des mods :"
|
|
echo -e "\t$ ./upgrade.sh -m"
|
|
echo -e "\tMise à jour du fichier minetest.conf :"
|
|
echo -e "\t$ ./upgrade.sh -w nalc-stable -b stable -f mtconf"
|
|
echo -e "\tMise à jour complète (mods et fichiers world, sauf minetest.conf) :"
|
|
echo -e "\t$ ./upgrade.sh -m -w nalc-1.1 -b 1.1"
|
|
}
|
|
|
|
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 -f $mods_minetest/*
|
|
|
|
if [[ -d $mods_custom ]]; then
|
|
ls $mods_custom | while read -r mod; do
|
|
if [[ -d $mods_cutom/$mod ]]; then
|
|
rm -f $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"
|
|
elif [[ $BRANCH == "dev" || $BRANCH == "1.2" ]]; then
|
|
mods="3d_armor_ip 3d_armor_sfinv 3dmushrooms"
|
|
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 || -e $mods_path/$mod/modpack.conf ]]; 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
|
|
error "Le répertoire $mods_path n'existe pas"
|
|
fi
|
|
|
|
pushd $mods_path > /dev/null 2>&1
|
|
git pull
|
|
verif
|
|
git submodule update --init --recursive
|
|
verif
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
update_world() {
|
|
local world_repos=$serverpath/world
|
|
local world_dest=$serverpath/minetest/worlds/$WORLD_NAME
|
|
|
|
if [[ ! -d $world_repos ]]; then
|
|
error "$world_repos n'existe pas"
|
|
fi
|
|
if [[ ! -d $world_dest ]]; then
|
|
error "$world_dest n'existe pas"
|
|
fi
|
|
|
|
if [[ $WORLD_FILE == "all" ]]; then
|
|
WORLD_FILE="moretrees 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
|
|
moretrees)
|
|
file_dest=$world_dest/moretrees_settings.txt
|
|
file=$world_repos/moretrees_settings-$BRANCH.txt;;
|
|
news)
|
|
file_dest=$world_dest/news.txt
|
|
file=$world_repos/news-$BRANCH.txt;;
|
|
technic)
|
|
file_dest=$world_dest/technic.conf
|
|
file=$world_repos/technic-$BRANCH.conf;;
|
|
fbn)
|
|
file_dest=$world_dest/forbidden_names.txt
|
|
file=$world_repos/forbidden_names-$BRANCH.txt;;
|
|
fbnp)
|
|
file_dest=$world_dest/forbidden_names_patterns.txt
|
|
file=$world_repos/forbidden_names_patterns-$BRANCH.txt;;
|
|
bitchange)
|
|
file_dest=$world_dest/bitchange_config.txt
|
|
file=$world_repos/bitchange_config-$BRANCH.txt;;
|
|
christmas)
|
|
file_dest=$world_dest/christmas_craft.conf
|
|
file=$world_repos/christmas_craft-$BRANCH.conf;;
|
|
randommsg)
|
|
file_dest=$world_dest/random_messages
|
|
file=$world_repos/random_messages-$BRANCH;;
|
|
worldmt)
|
|
do_copy=0
|
|
regen_worldmt
|
|
rm -f $world_dest/world.mt
|
|
ln -s $serverpath/world.mt $world_dest/world.mt;;
|
|
mtconf) # Exception ici car n'est pas un fichier world. Doit être appelé seul.
|
|
file_dest=$serverpath/minetest/minetest.conf
|
|
file=$serverpath/minetest-$BRANCH.conf;;
|
|
*)
|
|
error;;
|
|
esac
|
|
|
|
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
|
|
done
|
|
}
|
|
|
|
action() {
|
|
if [[ ! -d $serverpath ]]; then
|
|
error "Le répertoire $serverpath n'existe pas"
|
|
fi
|
|
|
|
if [[ $UP_MODS -eq 1 ]]; then
|
|
echo "Mise à jour des mods dans $serverpath/nalc-server-mods..."
|
|
update_mods
|
|
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 "Mise à jour des fichiers world terminé."
|
|
elif [[ -n $WORLD_NAME || -n $BRANCH ]]; then
|
|
error
|
|
fi
|
|
}
|
|
|
|
# Pas de paramètre
|
|
[[ $# -lt 1 ]] && usage
|
|
|
|
# -o : Options courtes
|
|
# -l : Options longues
|
|
options=$(getopt -o h,s:,m,w:,b:,f: -l help,serverpath:,mods,world:,branch:,world-file: -- "$@")
|
|
|
|
# Éclatement de $options en $1, $2...
|
|
set -- $options
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0;;
|
|
-s|--serverpath)
|
|
serverpath=$(strip $2)
|
|
shift 2;;
|
|
-m|--mods)
|
|
UP_MODS=1
|
|
shift;;
|
|
-w|--world)
|
|
WORLD_NAME=$(strip $2)
|
|
shift 2;;
|
|
-b|--branch)
|
|
BRANCH=$(strip $2)
|
|
shift 2;;
|
|
-f|--world-file)
|
|
WORLD_FILE=$(strip $2)
|
|
shift 2;;
|
|
--)
|
|
shift;;
|
|
*)
|
|
action
|
|
exit 0
|
|
shift;;
|
|
esac
|
|
done
|
|
|
|
exit 0
|