2019-02-13 23:07:44 +01:00
|
|
|
#!/bin/bash
|
2019-04-28 22:43:57 +02:00
|
|
|
# Author: Sys4
|
|
|
|
# Licence: GPLv3
|
2019-04-28 15:52:46 +02:00
|
|
|
serverpath=/home/minetest/nalc-stable
|
|
|
|
world=nalc-stable
|
|
|
|
world_file=all # news|technic|fbn|fbnp|bitchange|christmas|randommsg
|
|
|
|
branch=stable # 1.0|1.1|dev
|
2021-08-27 01:44:15 +02:00
|
|
|
mountpoint=/mnt/demonix.fr
|
|
|
|
mapdest=$mountpoint/www
|
2019-04-07 18:20:06 +02:00
|
|
|
bak=0
|
2019-04-28 15:52:46 +02:00
|
|
|
update=0
|
2019-04-07 18:20:06 +02:00
|
|
|
restart=0
|
2021-08-27 01:44:15 +02:00
|
|
|
regenmap=0
|
2019-02-13 23:07:44 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
usage() {
|
2021-08-27 01:44:15 +02:00
|
|
|
echo "usage: ./shutdown.sh [-h|--help] [-r|--restart] [-b|--bak] [-u|--update]"
|
|
|
|
echo "Options:"
|
|
|
|
echo -e "\t-h --help\tAffiche cette aide."
|
|
|
|
echo -e "\t-r --restart\tRedémarre le serveur après arrêt."
|
|
|
|
echo -e "\t-b --bak\tRéalise une sauvegarde après arrêt."
|
|
|
|
echo -e "\t-u --update\tRéalise une mise à jour après arrêt."
|
|
|
|
echo -e "\t-m --regen-map\tRégénère une carte du monde."
|
|
|
|
exit 0
|
2019-04-28 15:52:46 +02:00
|
|
|
}
|
|
|
|
|
2019-04-07 18:20:06 +02:00
|
|
|
action() {
|
|
|
|
kill -s TERM $(pidof minetestserver)
|
|
|
|
sleep 10
|
2019-02-13 23:07:44 +01:00
|
|
|
|
2019-04-07 18:20:06 +02:00
|
|
|
kill -s TERM $(pidof -x $serverpath/start.sh)
|
2019-02-13 23:07:44 +01:00
|
|
|
|
2019-04-07 18:20:06 +02:00
|
|
|
[[ $bak -eq 1 ]] && $serverpath/backup.sh
|
2021-08-27 01:44:15 +02:00
|
|
|
if [ $regenmap -eq 1 ]; then
|
|
|
|
mount $mountpoint
|
2021-08-27 23:58:10 +02:00
|
|
|
sleep 3
|
2021-08-27 11:19:52 +02:00
|
|
|
$serverpath/genmap.sh $serverpath $world $mapdest
|
2021-08-27 01:44:15 +02:00
|
|
|
umount $mountpoint
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $update -eq 1 ]] && $serverpath/upgrade.sh -s $serverpath -m -w $world -b $branch -f $world_file
|
2019-04-07 18:20:06 +02:00
|
|
|
[[ $restart -eq 1 ]] && $serverpath/start.sh&
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Pas de paramètre
|
|
|
|
#[[ $# -lt 1 ]] && error
|
|
|
|
# ou
|
|
|
|
[[ $# -lt 1 ]] && action
|
|
|
|
|
|
|
|
# -o : Options courtes
|
|
|
|
# -l : options longues
|
2021-08-27 01:44:15 +02:00
|
|
|
OPT=$(getopt -o b,r,h,u,m -l bak,restart,help,update,regen-map -- "$@")
|
2019-04-07 18:20:06 +02:00
|
|
|
|
|
|
|
# éclatement de $options en $1, $2...
|
|
|
|
set -- $OPT
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-b|--bak)
|
|
|
|
bak=1
|
|
|
|
shift;;
|
|
|
|
-r|--restart)
|
|
|
|
restart=1
|
|
|
|
shift;;
|
2021-08-27 01:44:15 +02:00
|
|
|
-h|--help)
|
|
|
|
usage;;
|
|
|
|
-u|--update)
|
|
|
|
update=1
|
|
|
|
shift;;
|
|
|
|
-m|--regen-map)
|
|
|
|
regenmap=1
|
|
|
|
shift;;
|
2019-04-07 18:20:06 +02:00
|
|
|
--)
|
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
action
|
|
|
|
shift;;
|
|
|
|
esac
|
|
|
|
done
|