104 lines
2.7 KiB
Bash
Executable File
104 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Author: Sys4
|
|
# Licence: GPLv3
|
|
|
|
# Script pour automatiser la création de la carte de nalc
|
|
|
|
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 : ./genmap.sh [-h|--help] server_path worldname destination_path"
|
|
echo "Génère la carte de nalc vers le fichier destination_path/nalc_map.png"
|
|
}
|
|
|
|
action() {
|
|
[ -z "$1" ] && error "Argument manquant"
|
|
local serverpath=$(strip "$1")
|
|
[ ! -d "$serverpath" ] && error "Le répertoire $serverpath n'existe pas"
|
|
|
|
[ -z "$2" ] && error "Nom du world manquant"
|
|
local world_name=$(strip "$2")
|
|
|
|
local world="$serverpath/minetest/worlds/$world_name"
|
|
[ ! -d "$world" ] && error "Le répertoire $world n'existe pas"
|
|
|
|
[ -z "$3" ] && error "Chemin de destination manquant"
|
|
local destination=$(strip "$3")
|
|
[ ! -d "$destination" ] && error "Le répertoire $destination n'existe pas"
|
|
|
|
[ ! -d "$serverpath/minetestmapper" ] && error "minetestmapper ne semble pas installé"
|
|
[ ! -d "$serverpath/leaftest" ] && error "leaftest ne semble pas installé"
|
|
[ ! -e "$serverpath/colors.txt" ] && error "$serverpath/colors.txt manquant"
|
|
|
|
# Copie du dossier leaftest vers /tmp puis on l'exécute de là
|
|
local config="$serverpath/minetest/minetest.conf"
|
|
local workdir=$(mktemp -d "/tmp/minetest-mapper.XXXXXXXXX")
|
|
local spawn=$(grep "^static_spawnpoint" "$config" | tr -d " " | cut -f 2 -d "=" | cut -f 1 -d' ');
|
|
local spawnx=$(cut -f 1 -d "," <<<$spawn)
|
|
local spawnz=$(cut -f 3 -d "," <<<$spawn)
|
|
local mapsize=12288
|
|
|
|
cp -a "$serverpath/leaftest" $workdir
|
|
cp "$serverpath/colors.txt" $workdir/leaftest
|
|
|
|
pushd $workdir/leaftest
|
|
|
|
MAPPERDIR="$serverpath/minetestmapper" \
|
|
MAPPERPARAMS="--colors $serverpath/colors.txt \
|
|
--min-y -25 --max-y 300" \
|
|
JOBNUM=$(nproc) \
|
|
$workdir/leaftest/mapper.sh "$world" $spawnx,$spawnz $mapsize
|
|
|
|
# Copie de leaftest vers le dossier web distant normalement déjà monté
|
|
rm -rf "$destination/$world_name"
|
|
cp -rL $workdir/leaftest/www "$destination/$world_name"
|
|
popd
|
|
|
|
rm -rf $workdir
|
|
}
|
|
|
|
# Pas de paramètre
|
|
[[ $# -lt 1 ]] && usage
|
|
|
|
# -o : Options courtes
|
|
# -l : Options longues
|
|
options=$(getopt -o h -l help -- "$@")
|
|
|
|
# Éclatement de $options en $1, $2...
|
|
set -- $options
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0;;
|
|
--)
|
|
shift;;
|
|
*)
|
|
action $1 $2 $3
|
|
exit 0
|
|
shift;;
|
|
esac
|
|
done
|
|
|
|
exit 0
|