Rewrite of the install script
This commit is contained in:
123
upgrade.sh
123
upgrade.sh
@@ -2,7 +2,8 @@
|
||||
# Author: Sys4
|
||||
# License: GPLv3
|
||||
|
||||
serverpath=$(pwd)
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||
serverpath="$SCRIPT_DIR"
|
||||
UP_MODS=0
|
||||
WORLD_FILE=all
|
||||
|
||||
@@ -58,16 +59,16 @@ usage() {
|
||||
}
|
||||
|
||||
regen_worldmt() {
|
||||
local worldfile=$serverpath/world.mt
|
||||
local worldfile="$MINETEST_DIR/worlds/$WORLD_NAME/world.mt"
|
||||
|
||||
echo "Regénération du fichier $worldfile..."
|
||||
|
||||
# Faire une sauvegarde du fichier world.mt actuel
|
||||
cp $worldfile $serverpath/world.mt.bak
|
||||
cp "$worldfile" "$worldfile".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
|
||||
cat "$worldfile" | while read -r line; do
|
||||
local match=$(echo $line | grep load_mod_)
|
||||
if [[ -z $match ]]; then
|
||||
if [[ $i -eq 0 ]]; then
|
||||
@@ -83,52 +84,39 @@ regen_worldmt() {
|
||||
# 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_DIR/mods"
|
||||
local mods_custom="$serverpath/custom/mods"
|
||||
|
||||
# Suppression d'éventuels liens symboliques du dossier des mods
|
||||
ls "$mods" | while read -r mod; do
|
||||
[ -L "$mods/$mod" ] && rm -f "$mods/$mod"
|
||||
done
|
||||
|
||||
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
|
||||
if [ -d "$mods_custom" ]; then
|
||||
ls $mods_custom | while read -r mod; do
|
||||
if [[ -d $mods_custom/$mod ]]; then
|
||||
rm -f $mods_path/$mod
|
||||
ln -s $mods_custom/$mod $mods_path/$mod
|
||||
fi
|
||||
[ -d $mods_custom/$mod ] && ln -s $mods_custom/$mod $mods/$mod
|
||||
done
|
||||
fi
|
||||
|
||||
# Liste des mods à désactiver
|
||||
local mods="3d_armor_ip 3d_armor_sfinv 3dmushrooms"
|
||||
|
||||
local md[1]=""
|
||||
local i=0
|
||||
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
|
||||
readarray -t md < "$serverpath/mods_disabled.txt"
|
||||
|
||||
if [[ -e $mods_path/$mod/init.lua ]]; then
|
||||
# Populate world.mt
|
||||
ls "$mods" | while read -r mod; do
|
||||
if [ -d $mods/$mod ]; then
|
||||
if [ -e $mods/$mod/init.lua ]; then
|
||||
local mod_enable="true"
|
||||
for (( modn=1; modn<=$i; modn++ )); do
|
||||
if [[ ${md[$modn]} == $mod ]]; then
|
||||
mod_enable="false"
|
||||
fi
|
||||
for (( modn=0; modn<${#md[@]}; modn++ )); do
|
||||
[ ${md[$modn]} == $mod ] && mod_enable="false"
|
||||
done
|
||||
echo "load_mod_$mod = $mod_enable" >> /tmp/world.mt
|
||||
else
|
||||
ls $mods_path/$mod | while read -r submod; do
|
||||
if [[ -d $mods_path/$mod/$submod ]]; then
|
||||
ls "$mods/$mod" | while read -r submod; do
|
||||
if [ -d "$mods/$mod/$submod" ]; then
|
||||
local mod_enable="true"
|
||||
for (( modn=1; modn<=$i; modn++ )); do
|
||||
if [[ ${md[$modn]} == $submod ]]; then
|
||||
mod_enable="false"
|
||||
fi
|
||||
for (( modn=0; modn<${#md[@]}; modn++ )); do
|
||||
[ ${md[$modn]} == $submod ] && mod_enable="false"
|
||||
done
|
||||
echo "load_mod_$submod = $mod_enable" >> /tmp/world.mt
|
||||
fi
|
||||
@@ -138,18 +126,16 @@ regen_worldmt() {
|
||||
done
|
||||
|
||||
# Remplacement du l'ancien world.mt par le nouveau
|
||||
mv /tmp/world.mt $serverpath/world.mt
|
||||
mv /tmp/world.mt "$MINETEST_DIR/worlds/$WORLD_NAME/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
|
||||
local mods_path="$MINETEST_DIR/mods"
|
||||
[ ! -d "$mods_path" ] && error "$mods_path not found"
|
||||
|
||||
pushd $mods_path > /dev/null 2>&1
|
||||
pushd "$mods_path" > /dev/null 2>&1
|
||||
git pull
|
||||
verif
|
||||
git submodule update --init --recursive
|
||||
@@ -158,17 +144,17 @@ update_mods() {
|
||||
}
|
||||
|
||||
update_world() {
|
||||
local world_repos=$serverpath/world
|
||||
local world_dest=$serverpath/minetest/worlds/$WORLD_NAME
|
||||
local world_repos="$SCRIPT_DIR/world"
|
||||
local world_dest="$MINETEST_DIR/worlds/$WORLD_NAME"
|
||||
|
||||
if [[ ! -d $world_repos ]]; then
|
||||
error "$world_repos n'existe pas"
|
||||
if [ ! -d "$world_repos" ]; then
|
||||
error "$world_repos not found"
|
||||
fi
|
||||
if [[ ! -d $world_dest ]]; then
|
||||
error "$world_dest n'existe pas"
|
||||
if [ ! -d "$world_dest" ]; then
|
||||
error "$world_dest not found"
|
||||
fi
|
||||
|
||||
if [[ $WORLD_FILE == "all" ]]; then
|
||||
if [ $WORLD_FILE == "all" ]; then
|
||||
WORLD_FILE="moretrees news technic fbn fbnp bitchange christmas randommsg worldmt"
|
||||
fi
|
||||
|
||||
@@ -203,20 +189,16 @@ update_world() {
|
||||
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;;
|
||||
regen_worldmt;;
|
||||
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;;
|
||||
file_dest="$MINETEST_DIR/minetest.conf"
|
||||
file="$SCRIPT_DIR/minetest-$BRANCH.conf";;
|
||||
*)
|
||||
error;;
|
||||
esac
|
||||
|
||||
if [[ $do_copy -eq 1 ]]; then
|
||||
if [[ ! -e $file ]]; then
|
||||
error "Le fichier $file n'existe pas"
|
||||
fi
|
||||
if [ $do_copy -eq 1 ]; then
|
||||
[ ! -e $file ] && error "Le fichier $file n'existe pas"
|
||||
|
||||
echo "Copie de $file vers $file_dest"
|
||||
cp -up $file $file_dest
|
||||
@@ -225,21 +207,22 @@ update_world() {
|
||||
}
|
||||
|
||||
action() {
|
||||
if [[ ! -d $serverpath ]]; then
|
||||
error "Le répertoire $serverpath n'existe pas"
|
||||
fi
|
||||
[ ! -d "$serverpath" ] && error "$serverpath not found"
|
||||
. "$serverpath/nalc.conf"
|
||||
[[ $BRANCH == "exp" ]] && BRANCH="experimental"
|
||||
|
||||
if [[ $UP_MODS -eq 1 ]]; then
|
||||
echo "Mise à jour des mods dans $serverpath/nalc-server-mods..."
|
||||
if [ $UP_MODS -eq 1 ]; then
|
||||
echo "Updating $MINETEST_DIR/mods…"
|
||||
update_mods
|
||||
echo "Mise à jour des mods terminé."
|
||||
echo "Mods updated."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -n $WORLD_NAME && -n $BRANCH ]]; then
|
||||
echo "Mise à jour de $WORLD_FILE dans $serverpath/minetest/worlds/$WORLD_NAME de la branche $BRANCH..."
|
||||
if [ -n $WORLD_NAME ] && [ -n $BRANCH ]; then
|
||||
echo "Updating $WORLD_FILE from $WORLD_NAME and branch $BRANCH"…
|
||||
update_world
|
||||
echo "Mise à jour des fichiers world terminé."
|
||||
elif [[ -n $WORLD_NAME || -n $BRANCH ]]; then
|
||||
echo "World files updated."
|
||||
elif [ -n $WORLD_NAME ] || [ -n $BRANCH ]; then
|
||||
error
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user