=================================================================== RCS file: /cvs/mtctl/mtctl_default.sh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -p -r1.8 -r1.9 --- mtctl/mtctl_default.sh 2022/12/06 15:34:44 1.8 +++ mtctl/mtctl_default.sh 2023/05/02 18:04:20 1.9 @@ -3,7 +3,7 @@ # Purpose: Minetest Server Control # License: Copyright (C) 2021-2022 by Miniontoby #--------------------------------------------------------------------- -VERSION="1.5" +VERSION="1.6" 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 @@ -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"