=================================================================== RCS file: /cvs/mtctl/mtctl_default.sh,v retrieving revision 1.7 retrieving revision 1.10 diff -u -p -r1.7 -r1.10 --- mtctl/mtctl_default.sh 2022/11/22 11:28:03 1.7 +++ mtctl/mtctl_default.sh 2023/05/02 18:59:16 1.10 @@ -3,7 +3,7 @@ # Purpose: Minetest Server Control # License: Copyright (C) 2021-2022 by Miniontoby #--------------------------------------------------------------------- -VERSION="1.5" +VERSION="1.6.1" config=[] config[0]="no"; config[1]="/usr/local/share/minetest/" @@ -15,7 +15,7 @@ mtinfo() { echo -e "mtctl: $MSG" | sed -e 's/\\n/\\nmtctl: /' } 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 @@ -204,7 +204,7 @@ createMT() { 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 "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 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" @@ -266,7 +266,60 @@ backupMT() { 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 ACTION="$1" @@ -299,6 +352,17 @@ case $ACTION in backup) mtsetup backupMT "$2" + ;; + startup) + startupMT + ;; + enable) + mtsetup + enableMT "$2" + ;; + disable) + mtsetup + disableMT "$2" ;; version) mtinfo "Version: $VERSION"