2019-02-13 23:07:44 +01:00
|
|
|
#!/bin/bash
|
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
|
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
|
2019-02-13 23:07:44 +01:00
|
|
|
|
2019-04-28 15:52:46 +02:00
|
|
|
usage() {
|
|
|
|
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."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
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
|
2019-04-28 15:52:46 +02:00
|
|
|
[[ $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
|
2019-04-28 15:52:46 +02:00
|
|
|
OPT=$(getopt -o b,r,h,u -l bak,restart,help,update -- "$@")
|
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;;
|
2019-04-28 15:52:46 +02:00
|
|
|
-h|--help)
|
|
|
|
usage;;
|
|
|
|
-u|--update)
|
|
|
|
update=1
|
|
|
|
shift;;
|
2019-04-07 18:20:06 +02:00
|
|
|
--)
|
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
action
|
|
|
|
shift;;
|
|
|
|
esac
|
|
|
|
done
|