Rewrite of the install script

This commit is contained in:
2022-05-27 14:36:02 +02:00
parent 279a3c6535
commit c2f52add1f
5 changed files with 775 additions and 437 deletions

View File

@@ -2,416 +2,468 @@
# Author: Sys4
# License: GPLv3
# Fonctions
usage() {
echo "Usage: ./install_nalc.sh [options] [--] [destination]"
echo
echo "Description:"
echo -e "\tDownload and install the files needed by the NALC server to the"
echo -e "\toptional [destination] folder. Otherwise the current directory"
echo -e "\twill be used."
echo
echo -e "\tBut, be carefull!"
echo -e "\tBy default the ~/.minetest dir will also be used and modified."
echo -e "\tSo, make a backup of your ~/.minetest directory before the"
echo -e "\tinstallation of this server or specify a new directory with the"
echo -e "\t --minetest-dir or -d option."
echo
echo "Requirements:"
echo -e "\t- Official Minetest server must be already installed on your system."
echo -e "\tIf it is not the case, please refers to the https://minetest.net"
echo -e "\twebsite for the installation instructions."
echo -e "\t- You'll also need git, cmake, make."
echo
echo "Options:"
echo -e "\t-h --help\t This help."
echo -e "\t-b --minetest-bin <path> Minetest server executable path."
echo -e "\t-d --minetest-dir <dir> Minetest directory to use for installing nalc mods, nalc game, minetest.conf…"
echo -e "\t-m --map-backend <sqlite3|leveldb|redis|postgresql|dummy>"
echo -e "\t-p --player-backend <sqlite3|leveldb|postgresql|dummy|files>"
echo -e "\t-a --auth-backend <sqlite3|leveldb|postgresql|files>"
echo -e "\t-M --minetest-mapper Install with minetest mapper support."
echo -e "\t-w --world <name> Custom world name."
echo -e "\t-P --port <port> Custom server port number."
echo -e "\t--url <URL> Custom remote URL."
echo -e "\t--branch <stable|dev|exp> Choose the version to install (stable by default)"
echo
echo "License: GPLv3. Please read the LICENSE file."
echo "Author: Sys4 - https://sys4.fr#contact"
exit 0
}
strip() {
echo $1 | cut -d \' -f 2
}
verif() {
if [ $? -gt 0 ]; then
echo "Erreur ! Arrêt du script."
if [[ $? -gt 0 ]]; then
echo "Error! Exit."
exit 1
fi
}
error() {
echo "ERREUR : Vérifiez vos paramètres !" >&2
echo "Utilisez l'option -h pour en savoir plus" >&2
if [[ -n $1 ]]; then
echo "ERROR: $1"! >&2
else
echo "ERROR: Invalid option!" >&2
echo "Use -h option for help." >&2
fi
exit 1
}
usage() {
echo "Usage : ./install.sh [options] [--] <version>"
echo -e "\nOptions :"
echo -e "\t-h | --help\t\tAffiche cette aide."
echo -e "\t-j | --makeopt\t\tNombre de threads de compilation. (Nombre total de cœurs par défaut)"
echo -e "\t--ssh <user@host>\tIdentifiants ssh."
echo -e "\t--url <URL>\t\tURL distante personnalisée."
echo -e "\t\t\t\tSi l'option --ssh est passée en option, il s'agira du chemin distant."
echo -e "\t-i | --irrlicht\t\tChemin personnalisé des sources irrlicht."
echo -e "\t-p | --postgresql\tBackend map et joueurs avec postgresql. Sinon leveldb sera utilisé par défaut."
echo -e "\t-e | --exec <minetest bin>\tChemin de l'exécutable Minetest. Ex. /usr/local/bin/minetestserver"
echo -e "\t-d | --dir <minetest server dir>\tDossier d'exécution du serveur. Ex. /var/lib/minetest/.minetest"
echo -e "\nversion :"
echo -e "\tstable : La dernière version stable du serveur sera installée avec la dernière version stable de minetest. Suivez les instructions... (Recommandé)"
echo -e "\tdev : La version du serveur en cours de developpement sera installée avec la dernière version stable de minetest. Suivez les instructions... (Le plus à jour mais risques d'instabilités !)"
echo -e "\texperimental : La version experimentale du serveur sera installée avec la branche master de Minetest (version de dev). Suivez les instructions... (Attention, très experimental !)"
echo -e "\nExemples :"
echo -e "\n\t\$ ./install.sh stable"
echo -e "\tInstalle la dernière version stable du serveur avec leveldb comme backend pour la map et les utilisateurs. Tous les cœurs du processeur sont utilisés pour la compilation."
echo -e "\n\t\$ ./install.sh -j12 --url https://sys4.fr/gitea/grossam -i /home/grossam/lib/irrlichtmt -p dev"
echo -e "\tInstalle la version dev d'un fork de nalc créé par l'utilisateur grossam avec 12 threads de compilation, chemin personnalisé d'irrlichtmt et support de PostgreSQL comme backend de la map et des joueurs.\n"
echo -e "\nÀ voir également :"
echo -e "\tGuide de contribution et de développement du serveur NALC"
echo -e "\thttps://sys4.fr/gitea/nalc/nalc-server/wiki/Guide-de-contribution-et-de-d%C3%A9veloppement-du-serveur-NALC\n"
exit 0
save_conf() {
local conf="$1"
echo "MINETEST_BIN=$MINETEST_BIN" > "$conf"
echo "MINETEST_DIR=$MINETEST_DIR" >> "$conf"
echo "MAP_BACKEND=$MAP_BACKEND" >> "$conf"
echo "PLAYER_BACKEND=$PLAYER_BACKEND" >> "$conf"
echo "AUTH_BACKEND=$AUTH_BACKEND" >> "$conf"
echo "MINETEST_MAPPER=$MINETEST_MAPPER" >> "$conf"
echo "URL=$URL" >> "$conf"
echo "BRANCH=$BRANCH" >> "$conf"
echo "WORLD_NAME=$WORLD_NAME" >> "$conf"
echo "PORT=$PORT" >> "$conf"
}
ssh() {
ssh=$(strip $1)
echo "Installation avec identifiants ssh : $ssh"
load_conf() {
. "$1"
}
url() {
url=$(strip $1)
}
makeopt() {
makeopt=$(strip $1)
}
postgresql() {
echo "Les indications à fournir ci-après nécessite d'avoir configuré un serveur postgresql au préalable. (Ctrl-C) pour annuler."
read -p "Indiquez l'adresse de la base de données : " pg_url
read -p "Indiquez l'utilisateur de la BDD : " pg_user
read -p "Indiquez le mot de passe : " pg_password
read -p "Indiquez le nom de la BDD à utiliser : " pg_dbname
echo "gameid = nalc_game" > world.mt
echo "backend = postgresql" >> world.mt
echo "player_backend = postgresql" >> world.mt
echo "pgsql_connection = host=$pg_url user=$pg_user password=$pg_password dbname=$pg_dbname" >> world.mt
echo "pgsql_player_connection = host=$pg_url user=$pg_user password=$pg_password dbname=players-$pg_dbname" >> world.mt
echo "auth_backend = sqlite3" >> world.mt
}
install_minetest() {
if [ -z $makeopt ]; then
local makeopt=$(grep -c processor /proc/cpuinfo)
fi
local branch="-b 5.5.0"
if [ $ver == "dev" ]; then
branch="-b stable-5"
elif [ $ver == "experimental" ]; then
branch="-b master"
install_game() {
local game_dir="$MINETEST_DIR/games/nalc_game"
if [ -d "$game_dir" ]; then
echo "Previous installation of NALC game detected."
read -p "Upgrade? ([Y]es/[n]o/clean/[c]ancel) " continue
case "$continue" in
[yY][eE][sS]|[yY]|"")
echo "Upgrading…"
pushd "$game_dir"
git pull
verif
popd;;
[cC][lL][eE][aA][nN])
echo "Cleaning…"
rm -rf "$game_dir"
verif;;
[cC][aA][nN][cC][eE][lL]|[cC])
echo "Upgrade cancelled."
exit 0;;
esac
fi
if [ ! -d "$game_dir" ]; then
local git_branch
local depth
case $BRANCH in
"stable")
git_branch="-b master"
depth="--depth 1"
;;
"dev")
git_branch="-b dev"
;;
"exp")
git_branch="-b experimental"
;;
esac
[ -z "$git_branch" ] && error "Invalid branch"
if [ -d minetest ]; then
echo "Installation précédente de Minetest détecté."
read -p "Mettre à jour ? (y,n,clean,cancel) : " continue
if [ $continue == "clean" ]; then
echo "Attention ! Cela va supprimer définitivement toutes les données."
read -p "Êtes-vous certains de vouloir continuer ? (y or n) : " continue
if [ $continue == "y" ]; then
rm -rf minetest
echo "Répertoire minetest supprimé."
else
echo "Installation annulée. Fin"
exit 0
fi
elif [ $continue == "y" ]; then
cd minetest
git pull
verif
cd ..
elif [ $continue == "cancel" ]; then
echo "Installation annulée. Fin"
exit 0
fi
fi
if [ ! -d minetest ]; then
if [ -n $ssh ]; then
git clone --depth 1 $branch $ssh\:minetest/minetest.git
else
git clone --depth 1 $branch https://github.com/minetest/minetest.git
fi
echo "Cloning $URL""nalc/nalc_game.git to $game_dir"
mkdir -p "$MINETEST_DIR/games"
verif
git clone $depth $git_branch $URL"nalc/nalc_game.git" "$game_dir"
verif
fi
echo "Minetest va être (re)compilé..."
sleep 3
cd minetest
cmake . -DBUILD_CLIENT=0 -DBUILD_SERVER=1 -DENABLE_SOUND=0 -DENABLE_SYSTEM_GMP=1 -DENABLE_JSONCPP=1 $irrlicht_src -DENABLE_LEVELDB=1 -DENABLE_REDIS=1 -DENABLE_POSTGRESQL=1 -DRUN_IN_PLACE=1 -DENABLE_GETTEXT=1 -DENABLE_FREETYPE=1 -DENABLE_LUAJIT=1 -DENABLE_CURL=0 -DENABLE_CURSES=1 -DENABLE_SPATIAL=1
make -j$makeopt
verif
echo "Installation de Minetest terminé."
cd ..
}
install_minetest_game() {
if [ -d nalc_game ]; then
echo "Installation précédente du jeux NALC détecté."
read -p "Mettre à jour ? (y,n,clean,cancel) " continue
if [ $continue == "y" ]; then
cd nalc_game
git pull
verif
cd ..
echo "Mise à jour du jeux NALC depuis dépôt distant terminé."
elif [ $continue == "clean" ]; then
echo "/!\ Cette action va effacer les données du répertoire nalc_game"
read -p "Êtes-vous sûr de vouloir continuer ? (y or n) " continue
if [ $continue == "y" ]; then
rm -rf nalc_game
echo "Jeux NALC supprimé."
else
echo "Mise à jour annulée. Terminé."
exit 0
fi
elif [ $continue == "cancel" ]; then
echo "Mise à jour annulée. Terminé."
exit 0
fi
fi
if [ ! -d nalc_game ]; then
local branch="-b master"
if [ $ver == "dev" ]; then
branch="-b dev"
elif [ $ver == "experimental" ]; then
branch="-b experimental"
fi
git clone --depth 1 $branch $URL/nalc_game.git
verif
echo "Clonage de nalc_game terminé."
fi
if [ ! -L minetest/games/nalc_game ]; then
ln -s $(pwd)/nalc_game minetest/games/nalc_game
echo "Lien symbolique minetest/games/nalc_game vers $(pwd)/nalc_game créé."
fi
echo "Installation/Mise à jour du jeux NALC terminé."
echo "NALC game installed/upgraded."
}
install_mods() {
if [ -d nalc-server-mods ]; then
echo "Le dossier de mods est déjà présent. Que souhaitez-vous faire ?"
read -p "Choisissez parmi la liste, ([1]update, [2]clean update, [3]cancel, [4]Ne rien faire) : " continue
if [ $continue == 1 ]; then
./upgrade.sh -m
elif [ $continue == 2 ]; then
rm -rf nalc-server-mods
elif [ $continue == 3 ]; then
echo "Mise à jour des mods annulé. Terminé."
exit 0
fi
local mods_dir="$MINETEST_DIR/mods"
if [ -d "$mods_dir" ]; then
echo "Mods directory is not empty."
read -p "Upgrade? ([Y]es/[n]o/clean/[c]ancel) " continue
case "$continue" in
[yY][eE][sS]|[yY]|"")
echo "Upgrading…"
"$SCRIPT_DIR"/upgrade.sh -m -s "$DESTINATION"
verif
;;
[cC][lL][eE][aA][nN])
echo "Cleaning…"
rm -rf "$mods_dir"
verif
;;
[cC][aA][nN][cC][eE][lL]|[cC])
echo "Upgrade cancelled."
exit 0;;
esac
fi
if [ ! -d nalc-server-mods ]; then
local branch="master"
if [ $ver == "dev" ]; then
branch="dev"
elif [ $ver == "experimental" ]; then
branch="experimental"
fi
git clone --depth 1 -b $branch $URL/nalc-server-mods.git
if [ ! -d "$mods_dir" ]; then
local git_branch
local depth
case $BRANCH in
"stable")
git_branch="-b master"
depth="--depth 1"
;;
"dev")
git_branch="-b dev"
;;
"exp")
git_branch="-b experimental"
;;
esac
[ -z $git_branch ] && error "Invalid branch"
echo "Cloning $URL/nalc-server-mods.git to $mods_dir"
git clone $depth $git_branch $URL"nalc/nalc-server-mods.git" "$mods_dir"
verif
./upgrade.sh -m
fi
if [ -z $pg_dbname ]; then
cp worldmt-1.1.conf world.mt
pushd "$mods_dir"
git submodule update --init --recursive
verif
popd
fi
echo "Mods for NALC installed/upgraded."
}
install_world() {
local world_name="nalc-$ver"
if [ -n $pg_dbname ]; then
world_name=$pg_dbname
fi
if [ -d minetest/worlds/$world_name ]; then
echo "Une map est déjà présente. Que souhaitez-vous faire ?"
read -p "Choisissez parmi la liste ([1]Nouveau, [2]Mettre à jour [3]Ne rien faire) : " continuer
if [ $continuer == 1 ]; then
if [ -n $pg_dbname ]; then
read -p "Les BDD $pg_dbname et players-$pg_dbname ne seront pas effacées. À vous de le faire manuellement après ce script ! -- Press enter -- : " continuer
fi
# On sauvegarde l'ancien world
if [ -d "minetest/worlds/"$world_name"_old" ]; then
rm -rf "minetest/worlds/"$world_name"_old"
fi
mv minetest/worlds/$world_name "minetest/worlds/"$world_name"_old"
elif [ $continuer == 2 ]; then
# On sauvegarde l'ancien world
if [ -d "minetest/worlds/"$world_name"_old" ]; then
rm -rf "minetest/worlds/"$world_name"_old"
fi
cp -r minetest/worlds/$world_name "minetest/worlds/"$world_name"_old"
# On met à jour les fichiers contenues dans cette map
./upgrade.sh -w $world_name -b $ver
fi
local world_dir="$MINETEST_DIR/worlds/$WORLD_NAME"
if [ -d "$world_dir" ]; then
echo "$WORLD_NAME already exist."
read -p "Upgrade $WORLD_NAME? ([Y]es/[n]o/[c]lean) " continue
case "$continue" in
[yY][eE][sS]|[yY]|"")
echo "Upgrading…"
[ -d "$world_dir"_old ] && rm -rf "$world_dir"_old
cp -r "$world_dir" "$world_dir"_old
verif
;;
[cC][lL][eE][aA][nN]|[cC])
echo "Cleaning…"
[ -d "$world_dir"_old ] && rm -rf "$world_dir"_old
mv "$world_dir" "$world_dir"_old
verif
;;
esac
fi
if [ ! -d "$world_dir" ]; then
mkdir -p "$world_dir/runes"
verif
if [ ! -d minetest/worlds/$world_name ]; then
mkdir -p minetest/worlds/$world_name
if [ -n $pg_dbname ]; then
createdb $pg_dbname
createdb players-$pg_dbname
fi
./upgrade.sh -w $world_name -b $ver
mkdir -p minetest/worlds/$world_name/runes
fi
}
post_install() {
if [ ! -a minetest/minetest.conf ]; then
local world_name="nalc-$ver"
if [ -n $pg_dbname ]; then
world_name=$pg_dbname
fi
./upgrade.sh -w $world_name -b $ver -f mtconf
local mt=$world_dir/world.mt
echo "Generating $mt""…"
echo "Veuillez éditer le fichier $(pwd)/minetest/minetest.conf"
fi
if [ ! -d logs ]; then
mkdir logs
fi
if [ ! -a start.sh ]; then
cp start.sh.example start.sh
chmod u+x start.sh
echo "Veuillez éditer le fichier $(pwd)/start.sh"
echo "Veuillez éditer le fichier $(pwd)/backup.sh"
echo "Veuillez éditer le fichier $(pwd)/shutdown.sh"
echo ""
echo "Pour utiliser la génération de la carte, installer ImageMagick avec la dépendance fontconfig et truetype."
echo "Il faudra aussi autoriser lecture et écriture pour PS. Dans le fichier de gestion de la police de sécurité d'ImageMagick."
echo "gameid = nalc_game" > $mt
echo "enable_damage = true" >> $mt
echo "creative_mod = false" >> $mt
case $MAP_BACKEND in
"sqlite3"|"")
echo "backend = sqlite3" >> $mt
;;
"leveldb")
echo "backend = leveldb" >> $mt
;;
"redis")
echo "backend = redis" >> $mt
read -p "redis_address? " val
echo "redis_address = $val" >> $mt
read -p "redis_hash? " val
echo "redis_hash = $val" >> $mt
read -p "redis_port? (6379) " val
[ -z $val ] && val=6379
echo "redis_port = $val" >> $mt
;;
"postgresql")
echo "backend = postgresql" >> $mt
read -p "DB address? " val
read -p "DB user? " val2
read -p "DB password? " val3
read -p "DB name? " val4
read -p "DB port? (5432) " val5
[ -z $val5 ] && val5=5432
echo "pgsql_connection = host=$val port=$val5 user=$val2 password=$val3 dbname=$val4" >> $mt
;;
"dummy")
echo "backend = dummy" >> $mt
;;
*)
error "$MAP_BACKEND is not valid";;
esac
case $PLAYER_BACKEND in
"sqlite3"|"")
echo "player_backend = sqlite3" >> $mt
;;
"leveldb")
echo "player_backend = leveldb" >> $mt
;;
"postgresql")
echo "player_backend = postgresql" >> $mt
read -p "DB address? ($val) " vval
read -p "DB user? ($val2) " vval2
read -p "DB password? ($val3) " vval3
read -p "DB name? (players-$val4) " vval4
read -p "DB port? ($val5) " vval5
[ -z $vval ] && vval=$val
[ -z $vval2 ] && vval2=$val2
[ -z $vval3 ] && vval3=$val3
[ -z $vval4 ] && vval4="players-$val4"
[ -z $vval5 ] && vval5=$val5
echo "pgsql_player_connection = host=$vval port=$vval5 user=$vval2 password=$vval3 dbname=$vval4" >> $mt
;;
"dummy")
echo "player_backend = dummy" >> $mt
;;
"files")
echo "player_backend = files" >> $mt
;;
*)
error "$PLAYER_BACKEND is not valid";;
esac
case $AUTH_BACKEND in
"sqlite3"|"")
echo "auth_backend = sqlite3" >> $mt
;;
"leveldb")
echo "auth_backend = leveldb" >> $mt
;;
"postgresql")
echo "auth_backend = postgresql" >> $mt
read -p "DB address? ($val) " vval
read -p "DB user? ($val2) " vval2
read -p "DB password? ($val3) " vval3
read -p "DB name? (auth-$val4) " vval4
read -p "DB port? ($val5) " vval5
[ -z $vval ] && vval=$val
[ -z $vval2 ] && vval2=$val2
[ -z $vval3 ] && vval3=$val3
[ -z $vval4 ] && vval4="auth-$val4"
[ -z $vval5 ] && vval5=$val5
echo "pgsql_auth_connection = host=$vval port=$vval5 user=$vval2 password=$vval3 dbname=$vval4" >> $mt
;;
"files")
echo "auth_backend = files" >> $mt
;;
*)
error "$AUTH_BACKEND is not valid";;
esac
read -p "Server announce? (y/N) " val
if [[ $val =~ [yY][eE][sS]|[yY] ]]; then
echo "server_announce = true" >> $mt
else
echo "server_announce = false" >> $mt
fi
fi
}
install_mtmapper() {
if [ -n $ssh ]; then
URL=$ssh\:minetest
else
URL="https://sys4.fr/gitea/minetest"
fi
if [ ! -d "$(pwd)/minetestmapper" ]; then
git clone --depth 1 $URL/minetestmapper.git
if [ ! -d "$DESTINATION/minetestmapper" ]; then
echo "Clone Minetest mapper…"
git clone --depth 1 $URL"/minetest/minetestmapper.git" "$DESTINATION/minetestmapper"
verif
else
echo "Upgrading Minetest mapper…"
pushd "$DESTINATION/minetestmapper"
git pull
verif
popd
fi
pushd "$(pwd)/minetestmapper"
git pull
pushd "$DESTINATION/minetestmapper"
cmake .
[ $? -eq 1 ] && echo "Vérifiez les dépendances de minetestmapper puis recompilez."
make -j$makeopt
[ $? -eq 1 ] && error "CMake failed. Check dependencies"
make -j$(nproc)
verif
popd
if [ -n $ssh ]; then
URL=$ssh\:nalc
else
URL="https://sys4.fr/gitea/nalc"
fi
if [ ! -d "$(pwd)/leaftest" ]; then
git clone --recursive --depth 1 $URL/leaftest.git
if [ ! -d "$DESTINATION/leaftest" ]; then
echo "Installing leaftest…"
git clone --recursive --depth 1 $URL"nalc/leaftest.git" "$DESTINATION/leaftest"
verif
else
echo "Upgrading leaftest…"
pushd "$DESTINATION/leaftest"
git pull
verif
popd
fi
}
init() {
ver=$(strip $1)
if [ -n $ssh && -n $url ]; then
URL=$ssh\:$url
elif [ -n $url ]; then
URL=$url
else
URL="https://sys4.fr/gitea/nalc"
post_install() {
if [[ "$DESTINATION" != "$SCRIPT_DIR" ]]; then
cp "$SCRIPT_DIR/mods_disabled.txt" "$DESTINATION"
fi
read -p "L'installation va démarrer. Continuer ? (y or n) : " continue
if [ $continue == "y" ]; then
# Vérification de l'environnement
install_minetest
install_minetest_game
install_mods
install_world
install_mtmapper
post_install
echo "L'installation est terminé. Bravo !"
else
echo "Installation annulée. Fin."
"$SCRIPT_DIR"/upgrade.sh -w $WORLD_NAME -b $BRANCH -s "$DESTINATION"
"$SCRIPT_DIR"/upgrade.sh -w $WORLD_NAME -b $BRANCH -f mtconf -s "$DESTINATION"
echo "Please, review and edit the following files:"
echo -e "\t- $MINETEST_DIR/minetest.conf"
echo -e "\t- $DESTINATION/mods_disabled.txt"
echo
if [ $MINETEST_MAPPER -eq 1 ]; then
echo "The use of Minetest Mapper needs ImageMagick with fontconfig and truetype dependencies."
echo "You also need to allow read and write permissions for PS. The configuration can be found in the file that manage the security policy of ImageMagick."
fi
}
action() {
local arg=$(strip $1)
if [ $arg == "dev" || $arg == "stable" || $arg == "experimental" ]; then
init $arg
else
error
echo "Preparing the installation…"
DESTINATION="$1"
GIT=$(which git)
CMAKE=$(which cmake)
MAKE=$(which make)
[ ! -e "$GIT" ] && error "git not found"
[ ! -e "$CMAKE" ] && error "cmake not found"
[ ! -e "$MAKE" ] && error "make not found"
if [ -e "$DESTINATION/nalc.conf" ]; then
read -p "Previous installation is detected. Do you want to load previous settings? [Y/n] " continue
if [ -z $continue ] || [[ "$continue" =~ ^[yY][eE][sS]|[yY]$ ]]; then
load_conf "$DESTINATION/nalc.conf"
fi
fi
[ -z $MINETEST_BIN ] && MINETEST_BIN=$(which minetestserver)
[ -z $MINETEST_DIR ] && MINETEST_DIR=~/.minetest
[ -z $MAP_BACKEND ] && MAP_BACKEND=sqlite3
[ -z $PLAYER_BACKEND ] && PLAYER_BACKEND=sqlite3
[ -z $AUTH_BACKEND ] && AUTH_BACKEND=sqlite3
[ -z $MINETEST_MAPPER ] && MINETEST_MAPPER=0
[ -z $PORT ] && PORT=30000
[ -z $URL ] && URL="https://sys4.fr/gitea/"
[[ $URL =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$ ]] && URL="$URL:"
[ -z $BRANCH ] && BRANCH="stable"
[ -z $WORLD_NAME ] && WORLD_NAME="nalc"
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
[ -z $DESTINATION ] && DESTINATION="$SCRIPT_DIR"
[ ! -e $MINETEST_BIN ] && error "$MINETEST_BIN not found"
[ ! -d $MINETEST_DIR ] && error "$MINETEST_DIR not found"
echo "Installation summary:"
echo -e "\t- Server files will be downloaded from $URL"
echo -e "\t- NALC server will be installed to $DESTINATION."
echo -e "\t- World of NALC will be installed to $MINETEST_DIR/worlds/$WORLD_NAME"
echo -e "\t- The minetestserver executable $MINETEST_BIN will be used."
echo -e "\t- The $MINETEST_DIR directory will be used."
echo -e "\t- $MAP_BACKEND will be used as map backend."
echo -e "\t- $PLAYER_BACKEND will be used as player backend."
echo -e "\t- $AUTH_BACKEND will be used as auth backend."
echo -e "\t- Port used: $PORT."
[ $MINETEST_MAPPER -eq 1 ] && echo -e "\t- Minetest mapper support added."
echo
read -p "Installation of NALC server will begin. Continue? [Y/n] " continue
if [ -z $continue ] || [[ "$continue" =~ ^[yY][eE][sS]|[yY]$ ]]; then
save_conf "$DESTINATION/nalc.conf"
install_game
install_mods
install_world
[ $MINETEST_MAPPER -eq 1 ] && install_mtmapper
post_install
fi
echo "End of the NALC server installation. Good Bye!"
exit 0
}
irrlicht() {
local arg=$(strip "$1")
if [ -d "$arg" ]; then
irrlicht_src="-DIRRLICHT_INCLUDE_DIR=$arg"
fi
}
[ $# -lt 0 ] && usage
exepath() {
local arg=$(strip "$1")
if [ -e "$arg" ]; then
minetest_bin="$arg"
else
error "$arg n'existe pas"
fi
}
minedir() {
local arg=$(strip "$1")
if [ -d "$arg" ]; then
minetest_dir="$arg"
else
error "$arg n'est pas un répertoire"
fi
}
# Pas de paramètre
#[ $# -lt 1 ] && error
# ou
[ $# -lt 1 ] && usage
# -o : Options courtes
# -l : options longues
OPT=$(getopt -o h,p,j:,i:,e:,d: -l help,postgresql,url:,ssh:,makeopt:,irrlicht:,exec:,dir: -- "$@")
# éclatement de $options en $1, $2...
OPT=$(getopt -o h,b:,d:,m:,p:,a:,M,w:,P: -l help,minetest-bin:,minetest-dir:,map-backend:,player-backend:,auth-backend:,minetest-mapper,url:,branch:,world:,port: -- "$@")
set -- $OPT
while true; do
case "$1" in
-h|--help)
usage;;
-i|--irrlicht)
irrlicht $2
-b|--minetest-bin)
MINETEST_BIN=$(strip "$2")
shift 2;;
-p|--postgresql)
postgresql
shift;;
--ssh)
ssh $2
-d|--minetest-dir)
MINETEST_DIR=$(strip "$2")
shift 2;;
-m|--map-backend)
MAP_BACKEND=$(strip "$2")
shift 2;;
-p|--player-backend)
PLAYER_BACKEND=$(strip "$2")
shift 2;;
-a|--auth-backend)
AUTH_BACKEND=$(strip "$2")
shift 2;;
-M|--minetest-mapper)
MINETEST_MAPPER=1
shift 1;;
-w|--world)
WORLD_NAME=$(strip "$2")
shift 2;;
-P|--port)
PORT=$(strip $2)
shift 2;;
--url)
url $2
URL=$(strip "$2")
shift 2;;
-j|--makeopt)
makeopt $2
--branch)
BRANCH=$(strip "$2")
shift 2;;
-e|--exec)
exepath $2
shift 2;;
-d|--dir)
minedir $2
shift 2;;
--)
--)
shift;;
*)
action $1
action $(strip "$1")
shift;;
esac
done