87 lines
1.9 KiB
Bash
87 lines
1.9 KiB
Bash
|
#!/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 : ./regen-map.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="$1"
|
||
|
[ ! -d $serverpath ] && error "Le répertoire $serverpath n'existe pas"
|
||
|
|
||
|
[ -z "$2" ] && error "Nom du world manquant"
|
||
|
local world_name="$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="$3"
|
||
|
[ ! -d destination ] && error "Le répertoire $destination n'existe pas"
|
||
|
|
||
|
[ ! -d "$serverpath/minetestmapper" ] && error "minetestmapper ne semble pas installé"
|
||
|
[ ! -e "$serverpath/colors.txt" ] && error "$serverpath/colors.txt manquant"
|
||
|
|
||
|
pushd "$serverpath/minetestmapper"
|
||
|
./minetestmapper -i "$world" -o /tmp/nalc_map.png \\
|
||
|
--colors "$serverpath/colors.txt" --min-y -25 --max-y 300 \\
|
||
|
--geometry -5000:-5000+10000+10000
|
||
|
verif
|
||
|
popd
|
||
|
|
||
|
mv /tmp/nalc_map.png "$destination/"
|
||
|
verif
|
||
|
}
|
||
|
|
||
|
# 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
|
||
|
exit 0
|
||
|
shift;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
exit 0
|