Mods et fichiers worlds peuvent être mis à jour par script
- upgrade.sh entièrement réécrit - shutdown.sh peut faire une mise à jour des mods et des fichiers worlds à le fermeture du serveur en appelant le script upgrade.sh - install.sh fait appel au script upgrade.sh pour remplir le dossier world lors de sa création. - Réorganisation des fichier world - Mise à jour des news - Désactivation des frames de technic
This commit is contained in:
269
upgrade.sh
269
upgrade.sh
@@ -1,6 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
auth="https"
|
||||
serverpath=$(pwd)
|
||||
UP_MODS=0
|
||||
WORLD_FILE=all
|
||||
|
||||
strip() {
|
||||
echo $1 | cut -d \' -f 2
|
||||
}
|
||||
|
||||
verif() {
|
||||
if [[ $? -gt 0 ]]; then
|
||||
@@ -10,167 +16,166 @@ verif() {
|
||||
}
|
||||
|
||||
error() {
|
||||
echo "ERREUR : paramètres invalides !" >&2
|
||||
echo "utilisez l'option -h pour en savoir plus" >&2
|
||||
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 [options]"
|
||||
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 "--help ou -h : Afficher l'aide"
|
||||
echo "--ssh : Authentification par ssh"
|
||||
echo "--https : Authentification publique anonyme"
|
||||
echo "--mods-link : Met à jour les liens symboliques des mods et le fichier world.mt"
|
||||
echo "--mods <mod|all> : Met à jour le(s) mod(s) depuis le dépôt distant"
|
||||
echo "--minetest : Met à jour le moteur du jeux depuis le dépot distant"
|
||||
echo "--game : Met à jour le jeux minetest depuis le dépot distant"
|
||||
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"
|
||||
}
|
||||
|
||||
modslink() {
|
||||
# Suppression des liens
|
||||
rm minetest/mods/*
|
||||
|
||||
# Supression du world.mt
|
||||
if [[ -a world.mt ]]; then
|
||||
rm world.mt
|
||||
fi
|
||||
# Création du fichier world.mt depuis sa conf
|
||||
cp worldmt.conf world.mt
|
||||
|
||||
# Création des liens
|
||||
while read -r mod
|
||||
do
|
||||
if [[ -d nalc-server-mods/$mod ]]; then
|
||||
ln -s $(pwd)/nalc-server-mods/$mod minetest/mods/$mod
|
||||
|
||||
# Ajout dans world.mt
|
||||
if [[ -a nalc-server-mods/$mod/modpack.txt ]]; then
|
||||
while read -r submod
|
||||
do
|
||||
echo "load_mod_"$submod" = true" >> world.mt
|
||||
done <<< $(ls nalc-server-mods/$mod)
|
||||
else
|
||||
echo "load_mod_"$mod" = true" >> world.mt
|
||||
fi
|
||||
fi
|
||||
done <<< $(ls nalc-server-mods)
|
||||
|
||||
echo "Liens des mods créés dans minetest/mods/"
|
||||
|
||||
# Lien symbolique world.mt
|
||||
if [[ ! -a minetest/worlds/nalc/world.mt ]]; then
|
||||
ln -s $(pwd)/world.mt minetest/worlds/nalc/world.mt
|
||||
echo "Lien vers world.mt créé dans minetest/worlds/nalc/"
|
||||
fi
|
||||
}
|
||||
|
||||
modsupgrade() {
|
||||
if [[ $auth == "ssh" ]]; then
|
||||
read -p "Please enter <username>@<host> : " ident
|
||||
ident=$ident\:
|
||||
else
|
||||
ident="https://sys4.fr/gogs/"
|
||||
update_mods() {
|
||||
local mods_path=$serverpath/nalc-server-mods
|
||||
if [[ ! -d $mods_path ]]; then
|
||||
error "Le répertoire $mods_path n'existe pas"
|
||||
fi
|
||||
|
||||
mods=$(echo $1 | cut -f 2 -d \')
|
||||
|
||||
if [[ $mods == "all" ]]; then
|
||||
|
||||
# On met à jour le dépot local des mods
|
||||
cd nalc-server-mods
|
||||
git pull
|
||||
git submodule update --remote --recursive
|
||||
verif
|
||||
cd ..
|
||||
else
|
||||
# Mise à jour du mod spécifié en ligne de commande
|
||||
cd nalc-server-mods
|
||||
git pull
|
||||
git submodule update --remote --recursive $1
|
||||
verif
|
||||
cd ..
|
||||
fi
|
||||
|
||||
# Mise à jour des liens
|
||||
modslink
|
||||
}
|
||||
|
||||
minetestupgrade() {
|
||||
cd minetest
|
||||
pushd $mods_path > /dev/null 2>&1
|
||||
git pull
|
||||
verif
|
||||
cmake . -DRUN_IN_PLACE=true -DENABLE_GETTEXT=true
|
||||
make -j33
|
||||
cd ..
|
||||
echo "Upgrade du moteur Minetest terminé."
|
||||
git submodule update --init --recursive
|
||||
verif
|
||||
popd > /dev/null 2>&1
|
||||
}
|
||||
|
||||
gameupgrade() {
|
||||
cd minetest/games/minetest_game
|
||||
git pull
|
||||
cd ../../..
|
||||
echo "Upgrade du jeux Minetest terminé."
|
||||
}
|
||||
update_world() {
|
||||
local world_repos=$serverpath/world
|
||||
local world_dest=$serverpath/minetest/worlds/$WORLD_NAME
|
||||
|
||||
upgradeall() {
|
||||
gameupgrade
|
||||
modsupgrade "all"
|
||||
minetestupgrade
|
||||
}
|
||||
|
||||
|
||||
sshauth() {
|
||||
if [[ -z `pidof ssh-agent` ]]; then
|
||||
echo "Exécutez les commandes suivantes :"
|
||||
echo "$ eval \`ssh-agent -s\`"
|
||||
echo "$ ssh-add <chemin vers votre clé privé>"
|
||||
echo "Relancez de nouveau le script : ./upgrade.sh --ssh [options]"
|
||||
exit 0
|
||||
else
|
||||
auth="ssh"
|
||||
echo "Authentification ssh activé."
|
||||
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="news technic fbn fbnp bitchange christmas randommsg"
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
echo "Copie de $file vers $file_dest"
|
||||
cp -up $file $file_dest
|
||||
done
|
||||
}
|
||||
|
||||
httpauth() {
|
||||
auth="https"
|
||||
echo "Authentification https activé."
|
||||
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 "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é."
|
||||
elif [[ -n $WORLD_NAME || -n $BRANCH ]]; then
|
||||
error
|
||||
fi
|
||||
}
|
||||
|
||||
# Pas de paramètre
|
||||
[[ $# -lt 1 ]] && error
|
||||
[[ $# -lt 1 ]] && usage
|
||||
|
||||
# -o : Options courtes
|
||||
# -l : Options longues
|
||||
options=$(getopt -o h -l help,https,ssh,mods-link,minetest,game,mods: -- "$@")
|
||||
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
|
||||
--ssh) sshauth
|
||||
shift;;
|
||||
--https) httpsauth
|
||||
shift;;
|
||||
--mods-link) modslink
|
||||
shift;;
|
||||
--mods) modsupgrade $2
|
||||
shift 2;;
|
||||
--minetest) minetestupgrade
|
||||
shift;;
|
||||
--game) gameupgrade
|
||||
shift;;
|
||||
--all) upgradeall
|
||||
shift;;
|
||||
-h|--help) usage
|
||||
exit 0;;
|
||||
-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
|
||||
break;;
|
||||
*) error
|
||||
shift;;
|
||||
shift;;
|
||||
*)
|
||||
action
|
||||
exit 0
|
||||
shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user