2018-03-16 23:47:34 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
serverpath=$(pwd)
|
|
|
|
UP_MODS=0
|
|
|
|
WORLD_FILE=all
|
|
|
|
|
|
|
|
strip() {
|
|
|
|
echo $1 | cut -d \' -f 2
|
|
|
|
}
|
2018-03-17 10:38:42 +01:00
|
|
|
|
2018-03-16 23:47:34 +01:00
|
|
|
verif() {
|
|
|
|
if [[ $? -gt 0 ]]; then
|
|
|
|
echo "Erreur ! Arrêt du script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-03-17 10:38:42 +01:00
|
|
|
error() {
|
2019-04-28 15:52:46 +02:00
|
|
|
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
|
2018-03-17 10:38:42 +01:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2019-04-28 15:52:46 +02:00
|
|
|
echo "Usage : ./upgrade.sh [-h|--help] | [-s|--serverpath <path>] [-m|--mods] [ -w|--world <world> < -b|--branch <branch> [-f|--world-file <arg>] > ]"
|
2019-04-22 14:40:36 +02:00
|
|
|
echo "WARNING: This is for an experimental usage. Don't use it!"
|
2019-04-28 15:52:46 +02:00
|
|
|
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\tTous les fichiers seront mis à jours"
|
|
|
|
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 "Exemples:"
|
|
|
|
echo -e "\tMise à jour des mods :"
|
|
|
|
echo -e "\t$ ./upgrade.sh -m"
|
|
|
|
echo -e "\tMise à jour des fichiers world :"
|
|
|
|
echo -e "\t$ ./upgrade.sh -w nalc-stable -b stable"
|
|
|
|
echo -e "\tMise à jour des mods et des news :"
|
|
|
|
echo -e "\t$ ./upgrade.sh -m -w nalc-1.1 -b 1.1 -f news"
|
2018-03-17 10:38:42 +01:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
update_mods() {
|
|
|
|
local mods_path=$serverpath/nalc-server-mods
|
|
|
|
if [[ ! -d $mods_path ]]; then
|
|
|
|
error "Le répertoire $mods_path n'existe pas"
|
2018-03-17 10:38:42 +01:00
|
|
|
fi
|
2019-04-28 15:52:46 +02:00
|
|
|
|
|
|
|
pushd $mods_path > /dev/null 2>&1
|
|
|
|
git pull
|
|
|
|
verif
|
|
|
|
git submodule update --init --recursive
|
|
|
|
verif
|
|
|
|
popd > /dev/null 2>&1
|
2018-03-17 10:38:42 +01:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
update_world() {
|
|
|
|
local world_repos=$serverpath/world
|
|
|
|
local world_dest=$serverpath/minetest/worlds/$WORLD_NAME
|
2018-03-17 10:38:42 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
if [[ ! -d $world_repos ]]; then
|
|
|
|
error "$world_repos n'existe pas"
|
|
|
|
fi
|
|
|
|
if [[ ! -d $world_dest ]]; then
|
|
|
|
error "$world_dest n'existe pas"
|
|
|
|
fi
|
2018-03-17 10:38:42 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
if [[ $WORLD_FILE == "all" ]]; then
|
|
|
|
WORLD_FILE="news technic fbn fbnp bitchange christmas randommsg"
|
2018-03-17 10:38:42 +01:00
|
|
|
fi
|
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
for w_file in $WORLD_FILE; do
|
|
|
|
local file=""
|
|
|
|
local file_dest=""
|
|
|
|
case $w_file in
|
|
|
|
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;;
|
|
|
|
*)
|
|
|
|
error;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ ! -e $file ]]; then
|
|
|
|
error "Le fichier $file n'existe pas"
|
|
|
|
fi
|
2018-03-17 10:38:42 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
echo "Copie de $file vers $file_dest"
|
|
|
|
cp -up $file $file_dest
|
|
|
|
done
|
2018-03-17 11:09:13 +01:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
action() {
|
|
|
|
if [[ ! -d $serverpath ]]; then
|
|
|
|
error "Le répertoire $serverpath n'existe pas"
|
|
|
|
fi
|
2018-03-21 01:28:29 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
if [[ $UP_MODS -eq 1 ]]; then
|
|
|
|
echo "Mise à jour des mods dans $serverpath/nalc-server-mods..."
|
|
|
|
update_mods
|
|
|
|
echo "Terminé."
|
2018-03-16 23:47:34 +01:00
|
|
|
fi
|
2018-03-17 10:38:42 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
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é."
|
|
|
|
elif [[ -n $WORLD_NAME || -n $BRANCH ]]; then
|
|
|
|
error
|
|
|
|
fi
|
2018-03-17 10:38:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Pas de paramètre
|
2019-04-28 15:52:46 +02:00
|
|
|
[[ $# -lt 1 ]] && usage
|
2018-03-17 10:38:42 +01:00
|
|
|
|
|
|
|
# -o : Options courtes
|
|
|
|
# -l : Options longues
|
2019-04-28 15:52:46 +02:00
|
|
|
options=$(getopt -o h,s:,m,w:,b:,f: -l help,serverpath:,mods,world:,branch:,world-file: -- "$@")
|
2018-03-17 10:38:42 +01:00
|
|
|
|
|
|
|
# Éclatement de $options en $1, $2...
|
|
|
|
set -- $options
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2019-04-28 15:52:46 +02:00
|
|
|
-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;;
|
2018-03-17 10:38:42 +01:00
|
|
|
--)
|
2019-04-28 15:52:46 +02:00
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
action
|
|
|
|
exit 0
|
|
|
|
shift;;
|
2018-03-17 10:38:42 +01:00
|
|
|
esac
|
|
|
|
done
|
2018-03-16 23:47:34 +01:00
|
|
|
|
|
|
|
exit 0
|