[Linux Bash] Automatically Update Tc, Compile And Import Db Updates

Hello all!

Thank you for keeping TrinityCore alive.

I find that updating, patching and compiling takes quite some time. To automate this procedure, I have created this script to update the TC source, patch the code with AH Bot, compile and import all the latest DB updates, on my Ubuntu 10.04LTS installation.

I am sharing this for two reasons:

[ol][li]Others might find it useful and benefit from it[/li]
[li]Feel free to discuss, correct mistakes and suggest features or improvements[/li]
[/ol]

If you find it useful, please comment and/or +Like

I will try to keep this post/script up-to-date.

[SIZE=18px]DISCLAIMER[/SIZE]

I can NOT guarantee that the following code is 100% correct or it will work on any environment. I strongly advise you to backup your TrinityCore installation before using this script.



#!/bin/bash

# This script updates the TrinityCore code and TrinityCore DB

# Made by Jasmine

# v0.1 Basic Framework

# v0.2 After a new TDB gets released lots of renames appear when updating git. Added message for user to stop the process.

# To make this file executable run "chmod u+x <script file name>"

# Colors in scripts: http://tldp.org/LDP/abs/html/colorizing.html

# init

function pause(){

   read -p "$*"

}

clear


# SECTION 1

# Define Variables

TrinityCoreBaseDir="$HOME/TrinityCore/"

AHBotPatch="ahbot.9239339.(2011-08-06).patch"

DBUser="DBUsername"

DBPass="DBPass"

BuildDIR="$HOME/TrinityCore/build"

ServerDir="$HOME/TrinityCore/server"


echo -e '\E[33;40m'


echo "This script will update the TrinityCore code, compile and update the DB."

echo "		  Remember to exit the WorldServer and Authserver"

echo "  All work is done inside a directory named TrinityCore in home."

echo "  Servers will be built in $ServerDir"

echo "		  Don't forget to put your maps and vmaps in there."

echo -e '\E[1;31;40m'

echo "				Please check for any errors!"

echo

tput sgr0


# SECTION 2

# Checking if a TrinityCore directory exists. If not cloning the git into TrinityCore directory.

if [ -d $TrinityCoreBaseDir ];

then

echo "Directory $TrinityCoreBaseDir exists. I will not clone git"

else

echo "Cloning TrinityCore git, please wait..."

cd ~/

git clone git://github.com/TrinityCore/TrinityCore.git TrinityCore

fi


# SECTION 3

# Checking if the build directory exists. If not, it gets created inside TrinityCore directory

if [ -d $BuildDIR ];

then

echo "Directory $BuildDIR exists so I will not create it"

else

mkdir $BuildDIR

echo "Directory $BuildDIR was created"

fi


# SECTION 4

# Checking if the server directory exists. If not, it gets created inside TrinityCore directory

if [ -d $ServerDir ];

then

echo "Directory $ServerDir exists so I will not create it"

else

mkdir $ServerDir

echo "Directory $ServerDir was created"

fi


# SECTION 5

# Updating git from repository

echo

pause "Press ENTER to update TrinityCore"

cd $TrinityCoreBaseDir

git pull origin master

echo -e '\E[1;31;40m'

echo If you saw lots of SQL file renames then STOP HERE by pressing CTRL+C.

echo Most probably a new TDB has been released which needs to be imported manually.

tput sgr0


# SECTION 6

# Patching with AHBot. The patch file needs to be in TrinityCore directory. Comment out this section if you don't need it.

# You can find AHBot @ http://www.trinitycore.org/f/topic/10-ac1-ahbot-telenpc2-for-trinitycore-917ffdf-2011-08-18/

echo

pause "Press ENTER to patch the code with AHBOT"

git apply $AHBotPatch


# SECTION 7

# Running CMAKE to prepare the build.

echo

pause "Press ENTER to begin with CMAKE"

cd $BuildDIR

cmake $TrinityCoreBaseDir -DPREFIX=$ServerDir -DWITH_WARNINGS=1 -DTOOLS=1


# SECTION 8

# It's time to compile the code

echo

pause "Press ENTER to build the code... It may take a while so please stand by..."

make --jobs=2

make install


# SECTION 9

# Importing all the sql updates released after a TDB

echo

pause "Press ENTER to update the Database"

for file in "$TrinityCoreBaseDir"sql/updates/world/*.sql; do mysql --user=$DBUser --password=$DBPass --database=world < $file; done

for file in "$TrinityCoreBaseDir"sql/updates/characters/*.sql; do mysql --user=$DBUser --password=$DBPass --database=characters < $file; done


echo

echo "All done (hopefully)"

spelling mistake replace:


echo "This script will update the TrinityCore code, compile and update the DB."

echo "      	Remember to exit WorldServer and Authserver"

echo "	All work is don inside directory named TrinityCore in home."

echo "  Servers will be built in $ServerDir"

echo "    	Don't forget to put your maps and vmpas in there."

with:


echo "This script will update the TrinityCore code, compile and update the DB."

echo "      	Remember to exit the WorldServer and Authserver"

echo "	All work is done inside a directory named TrinityCore in home."

echo "  Servers will be built in $ServerDir"

echo "    	Don't forget to put your maps and vmaps in there."

/emoticons/default_tongue.png else fucking amazing work /emoticons/default_smile.png thanks for sharing +1 !

Correction made. Thank you Shadowblade for both the correction and your kind words /emoticons/default_smile.png

Athena’s code is more sophisticated with better task handling. I switched to it after some minor corrections…

A damn great script mate, works a charm /emoticons/default_smile.png