version 1.3, 2021/09/26 14:02:56 |
version 1.6, 2022/05/29 14:33:42 |
|
|
# Purpose: Minetest server Control |
# Purpose: Minetest server Control |
# License: Copyright (C) 2021 by Miniontoby <miniontoby@ircnow.org> |
# License: Copyright (C) 2021 by Miniontoby <miniontoby@ircnow.org> |
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
VERSION="1.2" |
VERSION="1.4" |
config=[] |
config=[] |
config[0]="no"; config[1]="/usr/local/share/minetest/" |
config[0]="no"; config[1]="/usr/local/share/minetest/" |
|
|
|
|
echo -e "mtctl: $MSG" | sed -e 's/\\n/\\nmtctl: /' |
echo -e "mtctl: $MSG" | sed -e 's/\\n/\\nmtctl: /' |
} |
} |
mthelp() { |
mthelp() { |
echo -e "usage: mtctl start|stop|restart|status|create|backup worldname\n mtctl list|help|version|check_updates"; exit 1 |
echo -e "usage: mtctl start|stop|restart|status|create|backup worldname\n mtctl list|help|version|check_updates" |
} |
} |
if [ "x$1" == "x" ]; then mthelp; exit 1; fi |
if [ "x$1" == "x" ]; then mthelp; exit 0; fi |
|
|
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
|
|
if [ "${config[0]}" == "yes" ]; then SERVEREXE="${config[1]}/bin/minetestserver"; else SERVEREXE="`which minetestserver`"; fi |
if [ "${config[0]}" == "yes" ]; then SERVEREXE="${config[1]}/bin/minetestserver"; else SERVEREXE="`which minetestserver`"; fi |
WORLDBASE=${config[1]}/worlds |
WORLDBASE=${config[1]}/worlds |
LOGDIR=${config[1]}/log |
LOGDIR=${config[1]}/log |
EXITFLAGALL=$EXITDIR/minestop.all |
|
OK=0; cd ${config[1]} || exit 1 |
OK=0; cd ${config[1]} || exit 1 |
touch temp.test && OK=1; if [ "@$OK" == "@0" ]; then mtinfo "Error: Directory tree should be owned by the MT user:\n${config[1]}"; exit 1; fi |
touch temp.test && OK=1; if [ "@$OK" == "@0" ]; then mtinfo "Error: Directory tree should be owned by the MT user:\n${config[1]}"; exit 1; fi |
rm temp.test || exit 1 |
rm temp.test || exit 1 |
|
|
CHECK="Offline" |
CHECK="Offline" |
fi |
fi |
EXTRA="\n" |
EXTRA="\n" |
else if [ "$CHECK" == "Failed" ]; then EXTRA=" \n"; fi; fi |
elif [ "$CHECK" == "Failed" ]; then EXTRA=" \n"; |
|
elif [ "$CHECK" == "Backup failed" ]; then EXTRA=" \n"; |
|
elif [ "$CHECK" == "Backup success" ]; then EXTRA=" \n"; fi |
echo -ne "\r$NAME($CHECK)$EXTRA" |
echo -ne "\r$NAME($CHECK)$EXTRA" |
} |
} |
|
|
|
|
exit 1 |
exit 1 |
fi |
fi |
|
|
EXITFLAGWORLD=$EXITDIR/minestop.$NAME |
EXITFLAGWORLD=$EXITDIR/mtctlstop.$NAME |
MINETEST_SUBGAME_PATH=${config[1]}/games |
MINETEST_SUBGAME_PATH=${config[1]}/games |
# MAYBE Export if linux doesnt work |
# MAYBE Export if linux doesnt work |
|
|
rm -f $EXITFLAGALL $EXITFLAGWORLD |
rm -f $EXITFLAGALL |
sleep 1; DIR=`pwd` || exit 1; cd $WORLDDIR || exit 1 |
sleep 1; DIR=`pwd` || exit 1; cd $WORLDDIR || exit 1 |
F1=env_meta.txt; F2=env_meta.old; if [ -s $F1 ]; then N=`grep EnvArgsEnd $F1 | wc -l` || exit 1; if [ "x$N" == "x0" ]; then rm -f $F1 || exit 1; fi; fi; if [ -s $F1 ]; then rm -f $F2; cp -p $F1 $F2 || exit 1; else if [ -s $F2 ]; then rm -f $F1; cp -p $F2 $F1 || exit 1; else rm -f $F1 || exit 1; fi; fi |
F1=env_meta.txt; F2=env_meta.old; if [ -s $F1 ]; then N=`grep EnvArgsEnd $F1 | wc -l` || exit 1; if [ "x$N" == "x0" ]; then rm -f $F1 || exit 1; fi; fi; if [ -s $F1 ]; then rm -f $F2; cp -p $F1 $F2 || exit 1; else if [ -s $F2 ]; then rm -f $F1; cp -p $F2 $F1 || exit 1; else rm -f $F1 || exit 1; fi; fi |
cd $DIR || exit 1 |
cd $DIR || exit 1 |
|
|
( |
( |
while true; do |
while true; do |
$SERVEREXE --config $WORLDDIR/world.conf --port $PORT --logfile $LOGDIR/debug-$NAME.log --map-dir $WORLDDIR >> $LOGDIR/$NAME.log 2>&1 |
$SERVEREXE --config $WORLDDIR/world.conf --port $PORT --logfile $LOGDIR/debug-$NAME.log --map-dir $WORLDDIR >> $LOGDIR/$NAME.log 2>&1 |
if [ -f $EXITFLAGALL ]; then exit 0; fi; if [ -f $EXITFLAGWORLD ]; then exit 0; fi; sleep 10 |
if [ -f $EXITFLAGWORLD ]; then exit 0; fi; sleep 10 |
done |
done |
) > $LOGDIR/start-$NAME.txt & |
) > $LOGDIR/start-$NAME.txt & |
mtstatus "Ok" |
mtstatus "Ok" |
|
|
SetWorld "$1"; mtstatus |
SetWorld "$1"; mtstatus |
GetPIDS "$WORLDDIR" "$NAME" |
GetPIDS "$WORLDDIR" "$NAME" |
if [ "x$FOO$BAR" == "x" ]; then mtstatus "Failed"; mtinfo "$NAME seems to be stopped already"; exit 0; fi |
if [ "x$FOO$BAR" == "x" ]; then mtstatus "Failed"; mtinfo "$NAME seems to be stopped already"; exit 0; fi |
if [ "x$FOO" \!= "x" ]; then kill -SIGINT $FOO 2> /dev/null ; sleep 1; kill -SIGINT $FOO 2> /dev/null ; sleep 1; kill -SIGINT $FOO 2> /dev/null ; sleep 1; kill -SIGINT $FOO 2> /dev/null ; fi |
touch $EXITDIR/mtctlstop.$NAME |
if [ "x$BAR" \!= "x" ]; then kill -9 $BAR; fi |
|
|
|
|
if [ "x$FOO" \!= "x" ]; then |
|
kill -SIGINT $FOO |
|
else |
|
if [ "x$BAR" \!= "x" ]; then |
|
kill -9 $BAR |
|
fi |
|
fi |
|
|
mtstatus "Waiting" |
mtstatus "Waiting" |
sleep 15; GetPIDS "$WORLDDIR" "$NAME" |
sleep 5; GetPIDS "$WORLDDIR" "$NAME" |
|
|
if [ "x$FOO$BAR" == "x" ]; then |
if [ "x$FOO$BAR" == "x" ]; then |
mtstatus "Ok" |
mtstatus "Ok" |
else |
else |
kill -9 $FOO; kill -9 $FOO; kill -9 $FOO; kill -9 $FOO; |
|
if [ "x$BAR" \!= "x" ]; then kill -9 $BAR; fi |
|
|
|
mtstatus "Waiting." |
mtstatus "Waiting." |
sleep 15; GetPIDS "$WORLDDIR" "$NAME" |
sleep 5; GetPIDS "$WORLDDIR" "$NAME" |
if [ "x$FOO$BAR" == "x" ]; then |
if [ "x$FOO$BAR" == "x" ]; then |
mtstatus "Ok" |
mtstatus "Ok" |
else |
else |
|
|
} |
} |
|
|
statusMT() { |
statusMT() { |
SetWorld "$1"; |
SetWorld "$1" |
mtstatus "Ok" |
GetPIDS "$WORLDDIR" "$NAME" |
|
if [ "x$FOO$BAR" \!= "x" ]; then |
|
STATUS="Online" |
|
else |
|
STATUS="Offline" |
|
fi |
|
LASTLOG="`tail -n 5 $LOGDIR/$NAME.log`" |
|
echo -e "mtctl.$1 - The Minetest Server Control\n Active: $STATUS\n Process: $FOO\n Main PID: $BAR\n\n$LASTLOG" |
} |
} |
|
|
listMT() { |
listMT() { |
|
|
|
|
cd $WORLDBASE; mkdir $NAME; cd $NAME |
cd $WORLDBASE; mkdir $NAME; cd $NAME |
echo -e "server_name = $NAME\nserver_description = $SERVER_DESCRIPTION\nport = $PORT\nmotd = $MOTD\nfixed_map_seed = $SEED\ncreative_mode = $CREATIVE_MODE\nenable_damage = $ENABLE_DAMAGE\nenable_pvp = $ENABLE_PVP\nname = $USERNAME\nserver_announce = true\nserverlist_url = servers.minetest.net\nsqlite_synchronous = 0\nserver_unload_unused_data_timeout = 900\nserver_map_save_interval = 900.0" > world.conf |
echo -e "server_name = $NAME\nserver_description = $SERVER_DESCRIPTION\nport = $PORT\nmotd = $MOTD\nfixed_map_seed = $SEED\ncreative_mode = $CREATIVE_MODE\nenable_damage = $ENABLE_DAMAGE\nenable_pvp = $ENABLE_PVP\nname = $USERNAME\nserver_announce = true\nserverlist_url = servers.minetest.net\nsqlite_synchronous = 0\nserver_unload_unused_data_timeout = 900\nserver_map_save_interval = 900.0" > world.conf |
echo -e "creative_mode = $CREATIVE_MODE\nenable_damage = $ENABLE_DAMAGE\nauth_backend = sqlite3\nbackend = sqlite3\nplayer_backend = sqlite3\ngameid = minetest\nworld_name = $NAME" > world.mt |
echo -e "creative_mode = $CREATIVE_MODE\nenable_damage = $ENABLE_DAMAGE\nbackend = SQLite3\nplayer_backend = SQLite3\nmod_storage_backend = SQLite3\nauth_backend = SQLite3\ngameid = minetest\nworld_name = $NAME" > world.mt |
echo -ne "\nWorld created!\nWant to start the world?(yes/no): "; read startit |
echo -ne "\nWorld created!\nWant to start the world?(yes/no): "; read startit |
if [[ "$startit" == "yes" ]]; then /usr/bin/mtctl start $NAME; fi |
if [[ "$startit" == "yes" ]]; then /usr/bin/mtctl start $NAME; fi |
echo -e "\nSuccess: \033[1;32mDone \033[m\nFeel free to join your new server at port $PORT" |
echo -e "\nSuccess: \033[1;32mDone \033[m\nFeel free to join your new server at port $PORT" |
|
|
NEWESTVERSION=$(curl https://cvsweb.planetofnix.com/cgi-bin/cvsweb/~checkout~/mtctl/version.txt?content-type=text/plain 2> /dev/null) |
NEWESTVERSION=$(curl https://cvsweb.planetofnix.com/cgi-bin/cvsweb/~checkout~/mtctl/version.txt?content-type=text/plain 2> /dev/null) |
if [ "$NEWESTVERSION" \!= "$VERSION" ]; then |
if [ "$NEWESTVERSION" \!= "$VERSION" ]; then |
mtinfo "Update avaible!\n\nInstalling update NOW!" |
mtinfo "Update avaible!\n\nInstalling update NOW!" |
curl -sSLk https://ircforever.org/mtctl.php | $SHELL |
curl -sSL https://ircforever.org/mtctl.php | $SHELL |
fi |
fi |
;; |
;; |
help) |
help) |