version 1.7, 2022/11/22 11:28:03 |
version 1.10, 2023/05/02 18:59:16 |
|
|
# Purpose: Minetest Server Control |
# Purpose: Minetest Server Control |
# License: Copyright (C) 2021-2022 by Miniontoby <miniontoby@ircnow.org> |
# License: Copyright (C) 2021-2022 by Miniontoby <miniontoby@ircnow.org> |
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
VERSION="1.5" |
VERSION="1.6.1" |
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" |
echo -e "usage: mtctl start|stop|restart|status|create|backup|enable|disable worldname\n mtctl list|help|version|check_updates" |
} |
} |
if [ "x$1" == "x" ]; then mthelp; exit 0; fi |
if [ "x$1" == "x" ]; then mthelp; exit 0; fi |
|
|
|
|
|
|
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\nbackend = SQLite3\nplayer_backend = SQLite3\nmod_storage_backend = SQLite3\nauth_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" |
|
|
done |
done |
} |
} |
|
|
|
startupMT() { |
|
if [[ -f "$CONFDIR/startup" ]]; then |
|
if [[ -f "$CONFDIR/.booted" ]]; then |
|
exit 1 |
|
fi |
|
failed="" |
|
while read -r line |
|
do |
|
/usr/bin/mtctl start "$line" || failed="$failed, $line" |
|
done < "$CONFDIR/startup" |
|
if [[ "x$failed" == "x" ]]; then |
|
echo "Success!" |
|
else |
|
echo "Servers have failed to start$failed" |
|
fi |
|
touch $CONFDIR/.booted |
|
fi |
|
} |
|
|
|
enableMT() { |
|
SetWorld "$1" |
|
if [[ -f "$CONFDIR/startup" ]]; then |
|
INCLUDES=$(grep -x "$NAME" $CONFDIR/startup) |
|
if [[ "X$INCLUDES" == "X$NAME" ]]; then |
|
echo "$NAME is already enabled!" |
|
return |
|
fi |
|
fi |
|
if [[ $(crontab -l | egrep -v "^(#|$)" | grep -q '/usr/bin/mtctl startup'; echo $?) == 1 ]]; then |
|
set -f |
|
crontab -l > temp |
|
echo '@reboot rm $HOME/.mtctl/.booted 2>/dev/null; /usr/bin/mtctl startup' >> temp |
|
cat temp | crontab - |
|
rm temp |
|
set +f |
|
fi |
|
echo "$NAME" >> $CONFDIR/startup |
|
echo "$NAME is enabled!" |
|
} |
|
|
|
disableMT() { |
|
SetWorld "$1" |
|
if [[ -f "$CONFDIR/startup" ]]; then |
|
INCLUDES=$(grep -x "$NAME" $CONFDIR/startup) |
|
if [[ "X$INCLUDES" == "X$NAME" ]]; then |
|
grep -xv "$NAME" $CONFDIR/startup > temp && mv temp $CONFDIR/startup |
|
echo "$NAME is disabled!" |
|
return |
|
fi |
|
fi |
|
echo "$NAME is already disabled!" |
|
} |
|
|
|
|
#--------------------------------------------------------------------- |
#--------------------------------------------------------------------- |
# Handle the actions |
# Handle the actions |
ACTION="$1" |
ACTION="$1" |
|
|
backup) |
backup) |
mtsetup |
mtsetup |
backupMT "$2" |
backupMT "$2" |
|
;; |
|
startup) |
|
startupMT |
|
;; |
|
enable) |
|
mtsetup |
|
enableMT "$2" |
|
;; |
|
disable) |
|
mtsetup |
|
disableMT "$2" |
;; |
;; |
version) |
version) |
mtinfo "Version: $VERSION" |
mtinfo "Version: $VERSION" |