[BACK]Return to mtctl_default.sh CVS log [TXT][DIR] Up to [local] / mtctl

Diff for /mtctl/mtctl_default.sh between version 1.6 and 1.7

version 1.6, 2022/05/29 14:33:42 version 1.7, 2022/11/22 11:28:03
Line 1 
Line 1 
 #---------------------------------------------------------------------  #---------------------------------------------------------------------
 # Filename: mtctl  # Filename: mtctl
 # Purpose: Minetest server Control  # Purpose: Minetest Server Control
 # License: Copyright (C) 2021 by Miniontoby <miniontoby@ircnow.org>  # License: Copyright (C) 2021-2022 by Miniontoby <miniontoby@ircnow.org>
 #---------------------------------------------------------------------  #---------------------------------------------------------------------
 VERSION="1.4"  VERSION="1.5"
 config=[]  config=[]
 config[0]="no"; config[1]="/usr/local/share/minetest/"  config[0]="no"; config[1]="/usr/local/share/minetest/"
   
Line 28  if [ \! -d $CONFDIR ]; then mkdir -p $CONFDIR || exit 
Line 28  if [ \! -d $CONFDIR ]; then mkdir -p $CONFDIR || exit 
 if [ \! -f $CONFDIR/config ]; then  if [ \! -f $CONFDIR/config ]; then
         mtinfo "\nNo configfile found!\nCreating it now!\n\n"          mtinfo "\nNo configfile found!\nCreating it now!\n\n"
         echo -n 'Use custom build minetest folder (yes/no): '; read MTBUILD          echo -n 'Use custom build minetest folder (yes/no): '; read MTBUILD
         case $MTBUILD in          case $MTBUILD in
                 YES|yes) MTBUILD='yes'                  YES|yes) MTBUILD='yes'
                         EXAMPLEDIR="$HOME/minetest"                          EXAMPLEDIR="$HOME/minetest"
                         ;;                          ;;
Line 86  SetWorld() {
Line 86  SetWorld() {
         NAME=$1; if [ "x$NAME" == "x" ]; then mthelp; exit 1; fi          NAME=$1; if [ "x$NAME" == "x" ]; then mthelp; exit 1; fi
         WORLDDIR=$WORLDBASE/$NAME; if [ \! -d $WORLDDIR ]; then mtstatus "Failed"; mtinfo "Error: World not found: $NAME"; exit 1; fi          WORLDDIR=$WORLDBASE/$NAME; if [ \! -d $WORLDDIR ]; then mtstatus "Failed"; mtinfo "Error: World not found: $NAME"; exit 1; fi
         PORT=`grep '^port.*=' $WORLDDIR/world.conf | sed -e "s/^.*= *//" -e "s/ .*//"`; if [ "x$PORT" == "x" ]; then mtstatus "Failed"; mtinfo "Error: Port for $NAME not defined in cfg file"; exit 1; fi          PORT=`grep '^port.*=' $WORLDDIR/world.conf | sed -e "s/^.*= *//" -e "s/ .*//"`; if [ "x$PORT" == "x" ]; then mtstatus "Failed"; mtinfo "Error: Port for $NAME not defined in cfg file"; exit 1; fi
           OWNER=`grep '^name.*=' $WORLDDIR/world.conf | sed -e "s/^.*= *//" -e "s/ .*//"`; if [ "x$OWNER" == "x" ]; then mtstatus "Failed"; mtinfo "Error: Owner for $NAME not defined in cfg file"; exit 1; fi
 }  }
 mtstatus() {  mtstatus() {
         CHECK="$1"          CHECK="$1"
Line 98  mtstatus() {
Line 99  mtstatus() {
                         CHECK="Offline"                          CHECK="Offline"
                 fi                  fi
                 EXTRA="\n"                  EXTRA="\n"
         elif [ "$CHECK" == "Failed" ]; then EXTRA="  \n";          elif [ "$CHECK" == "Failed" ]; then EXTRA="\n";
         elif [ "$CHECK" == "Backup failed" ]; then EXTRA="  \n";          elif [ "$CHECK" == "Backup failed" ]; then EXTRA="\n";
         elif [ "$CHECK" == "Backup success" ]; then EXTRA="  \n"; fi          elif [ "$CHECK" == "Backup success" ]; then EXTRA="\n"; fi
         echo -ne "\r$NAME($CHECK)$EXTRA"          echo -ne "\r$NAME($CHECK)$EXTRA"
 }  }
   
Line 118  startMT() {
Line 119  startMT() {
         fi          fi
   
         EXITFLAGWORLD=$EXITDIR/mtctlstop.$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  
         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
Line 143  stopMT() {
Line 143  stopMT() {
   
         if [ "x$FOO" \!= "x" ]; then          if [ "x$FOO" \!= "x" ]; then
                 kill -SIGINT $FOO                  kill -SIGINT $FOO
         else          elif [ "x$BAR" \!= "x" ]; then
                 if [ "x$BAR" \!= "x" ]; then                  kill -9 $BAR
                         kill -9 $BAR  
                 fi  
         fi          fi
   
         mtstatus "Waiting"          mtstatus "Waiting"
Line 172  restartMT() {
Line 170  restartMT() {
 }  }
   
 statusMT() {  statusMT() {
         SetWorld "$1"          SetWorld "$1"
         GetPIDS "$WORLDDIR" "$NAME"          GetPIDS "$WORLDDIR" "$NAME"
         if [ "x$FOO$BAR" \!= "x" ]; then          if [ "x$FOO$BAR" \!= "x" ]; then
                 STATUS="Online"                  STATUS="Online"
         else          else
                 STATUS="Offline"                  STATUS="Offline"
         fi          fi
         LASTLOG="`tail -n 5 $LOGDIR/$NAME.log`"          LASTLOG="`tail -n 5 $LOGDIR/$NAME.log 2> /dev/null`"
         echo -e "mtctl.$1 - The Minetest Server Control\n   Active: $STATUS\n  Process: $FOO\n Main PID: $BAR\n\n$LASTLOG"          echo -e "mtctl.$1 - The Minetest Server Control\n   Active: $STATUS\n  Process: $FOO\n Main PID: $BAR\n\n$LASTLOG"
 }  }
   
 listMT() {  listMT() {
         for WORLDNAME in `ls $WORLDBASE 2> /dev/null | grep '^[a-zA-Z0-9]*$' | sort`; do          for WORLDNAME in `ls $WORLDBASE 2> /dev/null | grep '^[a-zA-Z0-9]*$' | sort`; do
                 SetWorld "$WORLDNAME"                  SetWorld "$WORLDNAME"
                 mtinfo "World: $WORLDNAME Port: $PORT"                  mtinfo "World: $WORLDNAME, Port: $PORT, Owner: $OWNER"
         done          done
 }  }
   
Line 195  createMT() {
Line 193  createMT() {
         if [ "x$NAME" == "x" ]; then echo -e "Failed\nError: Worlds need a name\n"; exit 1; else if [ -d $WORLDBASE/$NAME ]; then echo -e "Failed\nError: World already exist\n"; exit 1; else echo -e "Server name: Ok"; fi; fi          if [ "x$NAME" == "x" ]; then echo -e "Failed\nError: Worlds need a name\n"; exit 1; else if [ -d $WORLDBASE/$NAME ]; then echo -e "Failed\nError: World already exist\n"; exit 1; else echo -e "Server name: Ok"; fi; fi
         echo -ne "\nServer Description: "; read SERVER_DESCRIPTION          echo -ne "\nServer Description: "; read SERVER_DESCRIPTION
         PortCheck () {          PortCheck () {
                 CHECK='yes'; if [ -z "${PORT##*[!0-9]*}" ]; then CHECK='no'; ERROR="Ports are only numeric"; return; fi; for x in `ls /home/$MTUSER/minetest/worlds | sort`; do export WCFILE=$WORLDBASE/$x/world.conf; if [ -f $WCFILE ]; then export PORTF=`grep '^port.*=' $WCFILE | sed -e "s/^.*= *//" -e "s/ .*//"`; if [ "x$PORTF" == "x$1" ]; then CHECK='no'; ERROR="Port already in use"; return; fi; fi; done                  CHECK='yes'; if [ -z "${PORT##*[!0-9]*}" ]; then CHECK='no'; ERROR="Ports are only numeric"; return; fi; for x in `ls $WORLDBASE | sort`; do export WCFILE=$WORLDBASE/$x/world.conf; if [ -f $WCFILE ]; then export PORTF=`grep '^port.*=' $WCFILE | sed -e "s/^.*= *//" -e "s/ .*//"`; if [ "x$PORTF" == "x$1" ]; then CHECK='no'; ERROR="Port already in use"; return; fi; fi; done
         }          }
         while true; do echo -ne "\nPort: "; read PORT; PortCheck $PORT; if [ "$CHECK" == "no" ]; then echo -e "Failed\nError: $ERROR"; sleep 1; else echo -e "Ok"; break; fi; done          while true; do
                   echo -ne "\nPort: "; read PORT; PortCheck $PORT; if [ "$CHECK" == "no" ]; then echo -e "Failed\nError: $ERROR"; exit 1; else echo -e "Ok"; break; fi;
           done
         echo -ne "\nMessage Of The Day [MOTD]: "; read MOTD; echo -ne "\nSeed: "; read SEED; echo -ne "\nCreative (true/false): "; read CREATIVE_MODE          echo -ne "\nMessage Of The Day [MOTD]: "; read MOTD; echo -ne "\nSeed: "; read SEED; echo -ne "\nCreative (true/false): "; read CREATIVE_MODE
         echo -ne "\nEnable Damage (true/false): "; read ENABLE_DAMAGE; echo -ne "\nEnable Player Versus Player [PVP] (true/false): "; read ENABLE_PVP          echo -ne "\nEnable Damage (true/false): "; read ENABLE_DAMAGE; echo -ne "\nEnable Player Versus Player [PVP] (true/false): "; read ENABLE_PVP
         echo -ne "\nUsername: "; read USERNAME          echo -ne "\nUsername: "; read USERNAME
Line 245  backupMT() {
Line 245  backupMT() {
                         until sqlite3 $WORLDDIR/players.sqlite ".backup $BACKUP_DIR/players.sqlite" 2> /dev/null; do                          until sqlite3 $WORLDDIR/players.sqlite ".backup $BACKUP_DIR/players.sqlite" 2> /dev/null; do
                                 continue                                  continue
                         done                          done
                         rsync -ptrW --delete --exclude "*.sqlite" $WORLDDIR/ $BACKUP_DIR/                          rsync -ptrW --delete --exclude "*.sqlite" $WORLDDIR/ $BACKUP_DIR/
                         echo "Backup finished succesfully on $(date)" >> $LOG_FILE                          echo "Backup finished succesfully on $(date)" >> $LOG_FILE
                         mtstatus "Backup success"                          mtstatus "Backup success"
                         rm /tmp/$(basename $WORLDDIR)_local_backup_in_progress 2> /dev/null                          rm /tmp/$(basename $WORLDDIR)_local_backup_in_progress 2> /dev/null
Line 295  case $ACTION in
Line 295  case $ACTION in
         create)          create)
                 mtsetup                  mtsetup
                 createMT "$2"                  createMT "$2"
                   ;;
           backup)
                   mtsetup
                   backupMT "$2"
                 ;;                  ;;
         version)          version)
                 mtinfo "Version: $VERSION"                  mtinfo "Version: $VERSION"

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

CVSweb