Jump to content

bashscript for applying sql-updates from mangos


Guest balrok

Recommended Posts

you need to configure it right in the top of the script, and then just run it with argument1 as starting revision number, (starting means, from what point all updates are read)

it only works since mangos rev6936 and sd2 rev221

if you give a number as second argument the script determines, if this is a sd or mangos rev

improvements are welcome :)

#!/bin/bash
DB_MANGOS="mangos"
DB_CHARACTERS="characters"
DB_REALMD="realmd"
DB_SCRIPTDEV="scriptdev2"
USER="root"
PASS="lalala"
EXECUTE=0
DIR="/home/mangos/mangos/source"

if [ -z $1 ]; then
   echo "usage: ./mysql_updater #startrevision"
   echo "if #startrevision is lower than 6936 it guesses a sd2-rev"
   echo "else it thinks its a mangos-rev"
   exit 1
fi
if [[ $1 =~ ^[0-9]+$ ]]; then
   if [ $1 -lt 6936 ]; then
       if [ $1 -lt 221 ]; then
           echo "revisions lower 221 are not supported - your rev" $1
           exit 1
       fi
       echo "sd2 revnumber - patching sd2 from rev" $1
   else
       echo "mangos revnumber - patching mangos from rev" $1
   fi
else
   echo "you should use integers as revisionnumber"
   exit 1
fi
START_REV=$1 #startrevision
if [ $1 -ge 6936 ]; then
#mangos
   MANGDIR=$DIR"/sql/updates"
   for b in $( ls ${MANGDIR} | grep -v "2008" | grep -v "acid" | grep sql); do
       REV=$(echo $b | sed -r 's/([0-9]*).*/\\1/')
       if [ $REV -lt 6936 ]; then
           echo "strange file recived stopping " $b
           exit 1
       fi
       if [ $REV -lt $START_REV ]; then
           continue
       fi
       if echo "$b" | grep -q mangos; then
           echo "mysql "$DB_MANGOS" -u"$USER" -p"$PASS" < "$MANGDIR"/"$b";"
           if [ $EXECUTE -eq 1 ]; then
               mysql $DB_MANGOS -u$USER -p$PASS < $MANGDIR"/"$b";"
           fi
       elif  echo "$b" | grep -q characters; then
           echo "mysql "$DB_CHARACTERS" -u"$USER" -p"$PASS" < "$MANGDIR"/"$b";"
           if [ $EXECUTE -eq 1 ]; then
               mysql $DB_CHARACTERS -u$USER -p$PASS < $MANGDIR"/"$b";"
           fi
       elif  echo "$b" | grep -q realmd; then
           echo "mysql "$DB_REALMD" -u"$USER" -p"$PASS" < "$MANGDIR"/"$b";"
           if [ $EXECUTE -eq 1 ]; then
               mysql $DB_REALMD -u$USER -p$PASS < $MANGDIR"/"$b";"
           fi
       else
           echo "-------WARNING ONE FILE IS MISSING:---" $MANGDIR"/"$b
       fi
   done

else
#sd2
   SD2DIR=$DIR"/src/bindings/ScriptDev2/sql/Updates/"
   for b in $( ls ${SD2DIR} | grep sql | grep "r[0-9]*_" ); do
       REV=$(echo $b | sed -r 's/r([0-9]*).*/\\1/')
       if [ $REV -ge 6936 -o $REV -lt 221 ]; then
           echo "strange file recived stopping " $b
           exit 1
       fi
       if [ $REV -lt $START_REV ]; then
           continue
       fi
       if echo "$b" | grep -q mangos; then
           echo "mysql "$DB_MANGOS" -u"$USER" -p"$PASS" < "$SD2DIR"/"$b";"
           if [ "$EXECUTE" -eq "1" ]; then
               mysql $DB_MANGOS -u$USER -p$PASS < $SD2DIR"/"$b";"
           fi
       elif  echo "$b" | grep -q scriptdev2; then
           echo "mysql "$DB_SCRIPTDEV" -u"$USER" -p"$PASS" < "$SD2DIR"/"$b";"
           if [ "$EXECUTE" -eq "1" ]; then
               mysql $DB_SCRIPTDEV -u$USER -p$PASS < $SD2DIR"/"$b";"
           fi
       elif  echo "$b" | grep -q characters; then
           echo "mysql "$DB_CHARACTERS" -u"$USER" -p"$PASS" < "$SD2DIR"/"$b";"
           if [ "$EXECUTE" -eq "1" ]; then
               mysql $DB_CHARACTERS -u$USER -p$PASS < $SD2DIR"/"$b";"
           fi
       elif  echo "$b" | grep -q realmd; then
           echo "mysql "$DB_REALMD" -u"$USER" -p"$PASS" < "$SD2DIR"/"$b";"
           if [ "$EXECUTE" -eq "1" ]; then
               mysql $DB_REALMD -u$USER -p$PASS < $SD2DIR"/"$b";"
           fi
       else
           echo "-------WARNING ONE FILE IS MISSING:---" $SD2DIR"/"$b
       fi
   done
fi

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use