Skip to content

Instantly share code, notes, and snippets.

@dyon
Forked from Zoidwaffle/update-trinitycore.sh
Created August 25, 2012 11:44
Show Gist options
  • Save dyon/3464279 to your computer and use it in GitHub Desktop.
Save dyon/3464279 to your computer and use it in GitHub Desktop.
Attempts to make it easy to maintain an updated TrinityCore server on a Linux system
#!/bin/bash
########################################################################################
# Purpose : Updates TrinityCore
#######################################################################################
# Home for the trinity/server user (suggested user "trinity")
HOME="/home/trinity"
# Location of the ACE library, "/usr/lib" is default for system wide installation
LIBACE="/usr/lib"
# WoW 3.5.5a client, needed for map extractions
CLIENT="/home/trinity/client"
# Location of backups and the TDB file
BACKUPSQL="/home/trinity/backup-sql"
# When cleaning up backups, only delete data older than X days
# It will never delete a file older than this age if it's the only file
# left of a particular database backup
# Will ONLY delete files named such as *_world.sql.gz, *_characters.sql.gz, *_auth.sql.gz and TDB_*.sql
BACKUPAGE=30
# Location of custom SQL patches
# Default not defined
# Notice, files need to be in the format <name>_<database>.sql
# Example: mycustomtweaks_world.sql
# Only "world" database is supported at the moment
CUSTOMSQL="/home/trinity/custom-sql"
# Number of threads/cores when compiling
CORES=2
# Verbose enabled
# 1=yes
VERBOSE=1
#######################################################################################
# No changes below here should be needed
#######################################################################################
#######################################################################################
# Functions
#######################################################################################
# [y]es, [q]uit or [s]kip
yesquitskip(){
while true
do
read -p "[y]es, [q]uit or [s]kip (default [y]): " ANSWER
case ${ANSWER} in
[yY]*|"" )
ANSWER="y"
break;;
[qQ]* )
exit;;
[sS]* )
break;;
* )
echo "Not a valid option, select [y]es, [q]uit or [s]kip";;
esac
done
}
# [y]es or [s]kip
yesquit(){
while true
do
read -p "[y]es or [q]uit (default [y]): " ANSWER
case ${ANSWER} in
[yY]*|"" )
ANSWER="y"
break;;
[qQ]* )
exit;;
* )
echo "Not a valid option, select [y]es or [q]uit";;
esac
done
}
#######################################################################################
# Start screen showing some info and basic sanity checks
#######################################################################################
startscreen(){
echo
echo "--------------------------------------------------------------------------------"
echo " TrinityCore Lazy Updater "
echo "--------------------------------------------------------------------------------"
echo
echo "System information:"
echo "${CORES} CPU core(s) available for compiling"
echo
echo "${HOME}"
if [ -d "${HOME}" ]; then
echo "Root path for TrinityCore/build/server... OK"
else
echo "Root path for TrinityCore/build/server/backup-sql... Failed!"
echo "Please update the HOME path." && exit 1
fi
echo
echo "Location of ACE library: ${LIBACE}"
if [ -d "${LIBACE}" ]; then
echo "Folder for ACE-library found... OK"
else
echo "Folder for ACE-library not found... Failed!"
echo "Please provide the correct path for the ACE-library."
fi
echo
echo "${HOME}/server/etc/worldserver.conf"
if [ -f "${HOME}/server/etc/worldserver.conf" ]; then
echo "World server configuration found... OK"
else
echo "World server configuration found not found, cannot update databases Failed!"
echo "Please setup the world-server first."
fi
echo
if [ -z "${CUSTOMSQL}" ]; then
echo "Custom SQL patches NO"
elif [ -d "${CUSTOMSQL}" ]; then
echo "Custom SQL patches YES"
else
echo "Custom SQL patches, path not found Failed!"
fi
echo
echo "${CLIENT}"
if [ -d "${CLIENT}" ]; then
echo "Game client location... OK"
else
echo "Game client location not found, cannot update maps/vmaps Failed!"
fi
echo
if [ "${VERBOSE}" -eq "1" ]; then
echo "Verbose mode ENABLED"
else
echo "Verbose mode DISABLED"
fi
echo
echo "--------------------------------------------------------------------------------"
echo -n "Continue? "
yesquit
}
#######################################################################################
# ACE
#######################################################################################
addpath(){
export PATH=$PATH:${LIBACE}
}
#######################################################################################
# Source code download/update
#######################################################################################
downloadsource(){
echo "--------------------------------------------------------------------------------"
echo -n "Download source code? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
cd "${HOME}"
if [ ! -d "${HOME}/TrinityCore" ]; then
echo "--------------------------------------------------------------------------------"
echo -n "Creating source directory and downloading source code... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
git clone git://github.com/TrinityCore/TrinityCore.git && echo "Done!" || echo "Failed!"
else
git clone git://github.com/TrinityCore/TrinityCore.git > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
else
cd "${HOME}/TrinityCore"
echo "--------------------------------------------------------------------------------"
echo -n "Updating source code... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
git pull origin master && echo "Done!" || echo "Failed!"
else
git pull origin master > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
fi
}
#######################################################################################
# Compile the latest version
#######################################################################################
compilecode(){
echo "--------------------------------------------------------------------------------"
echo -n "Compile code? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
echo "--------------------------------------------------------------------------------"
if [ ! -d "${HOME}/build" ]; then
echo -n "Creating directory build directory "
mkdir -p "${HOME}/build" && echo " Done" || echo "Failed!"
fi
cd ${HOME}/build
echo -n "Preparing for compiling... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
cmake ../TrinityCore/ -DPREFIX=${HOME}/server -DWITH_SQL=1 -DTOOLS=1 && echo "Done!" || echo "Failed!"
else
cmake ../TrinityCore/ -DPREFIX=${HOME}/server -DWITH_SQL=1 -DTOOLS=1 > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
echo -n "Compiling (this may take a long time)... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
make -j ${CORES} && echo "Done!" || echo "Failed!"
else
make -j ${CORES} > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
}
#######################################################################################
# Install the latest version of TC
#######################################################################################
installtc(){
echo "--------------------------------------------------------------------------------"
echo -n "Install latest compiled version of TrinityCore? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
echo "--------------------------------------------------------------------------------"
cd ${HOME}/build
echo -n "Installing... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
make install && echo "Done!" || echo "Failed!"
else
make install > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
}
#######################################################################################
# Gather connection info for databases
#######################################################################################
dbconstrings(){
# Let's get info for "world"
DBWHOST="`grep "^WorldDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$3'}`"
DBWPORT="`grep "^WorldDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$4'}`"
DBWUSER="`grep "^WorldDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$5'}`"
DBWPASS="`grep "^WorldDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$6'}`"
DBWORLD="`grep "^WorldDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$7'}`"
MYSQLWORLD="${DBWORLD} -h${DBWHOST} -P${DBWPORT} -u${DBWUSER} -p${DBWPASS}"
# Let's get info for "characters"
DBCHOST="`grep "^CharacterDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$3'}`"
DBCPORT="`grep "^CharacterDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$4'}`"
DBCUSER="`grep "^CharacterDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$5'}`"
DBCPASS="`grep "^CharacterDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$6'}`"
DBCHARS="`grep "^CharacterDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$7'}`"
MYSQLCHAR="${DBCHARS} -h${DBCHOST} -P${DBCPORT} -u${DBCUSER} -p${DBCPASS}"
# Let's get info for "auth"
DBAHOST="`grep "^LoginDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$3'}`"
DBAPORT="`grep "^LoginDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$4'}`"
DBAUSER="`grep "^LoginDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$5'}`"
DBAPASS="`grep "^LoginDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$6'}`"
DBAHARS="`grep "^LoginDatabaseInfo" ${HOME}/server/etc/worldserver.conf | sed -e 's/\"//g' -e 's/;/ /g' | awk {'print \$7'}`"
MYSQLAUTH="${DBAHARS} -h${DBAHOST} -P${DBAPORT} -u${DBAUSER} -p${DBAPASS}"
}
#######################################################################################
# Update database
#######################################################################################
updatedb(){
echo "--------------------------------------------------------------------------------"
echo -n "Update database(s)? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
dbconstrings
# Backup folder needs to be there
if [ ! -d "${BACKUPSQL}" ]; then
echo "${BACKUPSQL} not found"
echo -n "Will create the above folder for storing TDB and database backups "
mkdir -p "${BACKUPSQL}" && echo " Done!" || echo "Failed!"
else
echo "Folder for database backups exists... OK"
fi
# Let's see the latest TDB file found locally
CURTDB="`find "${BACKUPSQL}" -type f -name TDB_*.sql | tail -n 1 | awk -F '/' {'print $NF'} | sed "s/sql$/rar/"`"
# Let's see the latest TDB file found online
LATESTTDB="`wget -O - https://github.com/TrinityCore/TrinityCore/downloads 2>/dev/null | egrep -o ">TDB_full.*\.rar<" | tr -d '<>' | head -n 1`"
if [ "${CURTDB}" != "${LATESTTDB}" ]; then
echo -n "Will download the latest TDB file... "
cd "${BACKUPSQL}"
wget "https://github.com/TrinityCore/TrinityCore/downloads/${LATESTTDB}" 2>/dev/null && echo " Done!" || echo "Failed!"
echo -n "Will uncompress the latest TDB file "
unrar e ${LATESTTDB} 2>/dev/null && echo " Done!" || echo "Failed!"
else
# Latest clean world
echo "TDB file is up to date OK"
fi
TDB="`find "${BACKUPSQL}" -type f -name TDB_*.sql | tail -n 1`"
if [ ! -f "${TDB}" ]; then
echo "TDB file not found, cannot update databases! Failed!"
exit 1
else
echo "TDB file used for updating: `basename ${TDB}`"
fi
echo -n "Importing latest full world... "
mysql ${MYSQLWORLD} < ${TDB} > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
# World patches
if [ ! -d "${HOME}/TrinityCore/sql/updates/world" ]; then
echo "No updates for world database Done"
else
cd "${HOME}/TrinityCore/sql/updates/world"
echo -n "Updating world with official patches... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
ls | egrep "\.sql$" | while read i; do echo "Applying patch ${i}"; mysql ${MYSQLWORLD} < ${i}; done && echo "Done!" || echo "Failed!"
else
ls | egrep "\.sql$" | while read i; do mysql ${MYSQLWORLD} < ${i}; done > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
# Custom world patches
if [ -z "${CUSTOMSQL}" ]; then
echo "No custom path for updates for database OK"
elif [ -d "${CUSTOMSQL}" ]; then
cd "${CUSTOMSQL}"
echo -n "Updating world with custom patches... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
ls | egrep "\.sql$" | while read i; do echo "Applying patch ${i}"; mysql ${MYSQLWORLD} < ${i}; done && echo "Done!" || echo "Failed!"
else
ls | egrep "\.sql$" | while read i; do mysql ${MYSQLWORLD} < ${i}; done > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
# Character patches
if [ ! -d "${HOME}/TrinityCore/sql/updates/characters" ]; then
echo "No updates for character database Done"
else
cd "${HOME}/TrinityCore/sql/updates/characters"
echo -n "Updating characters with official patches... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
ls | egrep "\.sql$" | while read i; do echo "Applying patch ${i}"; mysql ${MYSQLCHAR} < ${i}; done && echo "Done!" || echo "Failed!"
else
ls | egrep "\.sql$" | while read i; do mysql ${MYSQLCHAR} < ${i}; done > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
# Auth patches
if [ ! -d "${HOME}/TrinityCore/sql/updates/auth" ]; then
echo "No updates for auth database Done"
else
cd "${HOME}/TrinityCore/sql/updates/auth"
echo -n "Updating auth with official patches... "
if [ "${VERBOSE}" -eq "1" ]; then
echo
ls | egrep "\.sql$" | while read i; do echo "Applying patch ${i}"; mysql ${MYSQLAUTH} < ${i}; done && echo "Done!" || echo "Failed!"
else
ls | egrep "\.sql$" | while read i; do mysql ${MYSQLAUTH} < ${i}; done > /dev/null 2>&1 && echo " Done!" || echo "Failed!"
fi
fi
fi
}
#######################################################################################
# Backup "world", "auth" and "characters" databases
#######################################################################################
backupdb(){
echo "--------------------------------------------------------------------------------"
echo -n "Backup databases? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
dbconstrings
echo -n "Will backup the world database... "
mysqldump ${MYSQLWORLD} | gzip -9 > "${BACKUPSQL}/`date +%Y-%m-%d_%H%M`_world.sql.gz" && echo " Done!" || echo "Failed!"
echo -n "Will backup the characters database... "
mysqldump ${MYSQLCHAR} | gzip -9 > "${BACKUPSQL}/`date +%Y-%m-%d_%H%M`_characters.sql.gz" && echo " Done!" || echo "Failed!"
echo -n "Will backup the auth database... "
mysqldump ${MYSQLAUTH} | gzip -9 > "${BACKUPSQL}/`date +%Y-%m-%d_%H%M`_auth.sql.gz" && echo " Done!" || echo "Failed!"
fi
}
#######################################################################################
# Delete obsolete data
#######################################################################################
deletedbbackups(){
echo "--------------------------------------------------------------------------------"
echo -n "Delete old database backups? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
SQLTOBEDELETED="`find "${BACKUPSQL}" -mtime +${BACKUPAGE} -name *_world.sql.gz | egrep "[[:alnum:]]" | head -n -1`"
SQLTOBEDELETED="${SQLTOBEDELETED}\n`find "${BACKUPSQL}" -mtime +${BACKUPAGE} -name *_characters.sql.gz | egrep "[[:alnum:]]" | head -n -1`"
SQLTOBEDELETED="${SQLTOBEDELETED}\n`find "${BACKUPSQL}" -mtime +${BACKUPAGE} -name *_auth.sql.gz | egrep "[[:alnum:]]" | head -n -1`"
SQLTOBEDELETED="${SQLTOBEDELETED}\n`find "${BACKUPSQL}" -name TDB_*.sql | egrep "[[:alnum:]]" | head -n -1`"
if echo "${SQLTOBEDELETED}" | egrep -q "[[:alnum:]]"; then
echo "This will delete the following files:"
echo "--------------------------------------------------------------------------------"
echo "${SQLTOBEDELETED}"
echo -n "Delete these files? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
rm -f `echo ${SQLTOBEDELETED} | xargs`
fi
else
echo "No files found for deletion"
fi
fi
}
deletemapbackups(){
echo "--------------------------------------------------------------------------------"
echo -n "Delete old map backups? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
MAPSTOBEDELETED="`find ${HOME}/server/data/ -maxdepth 1 -type d -name vmaps-backup* | head -n -1`"
MAPSTOBEDELETED="${MAPSTOBEDELETED}\n`find ${HOME}/server/data/ -maxdepth 1 -type d -name maps-backup* | head -n -1`"
MAPSTOBEDELETED="${MAPSTOBEDELETED}\n`find ${HOME}/server/data/ -maxdepth 1 -type d -name dbc-backup* | head -n -1`"
if echo "${MAPSTOBEDELETED}" | egrep -q "[[:alnum:]]"; then
echo "This will delete the following files:"
echo "--------------------------------------------------------------------------------"
echo "${MAPSTOBEDELETED}"
echo -n "Delete these files? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
rm -rf `echo ${MAPSTOBEDELETED} | xargs`
fi
else
echo "No files found for deletion"
fi
fi
}
#######################################################################################
# Update maps/vmaps
#######################################################################################
updatemaps(){
# If they are already up to date or not...
MAPTOOLTIME="`ls --time-style='+%s' -l ${HOME}/server/bin/*map* | tail -n 1 | awk {'print \$(NF-1)'}`"
MAPTIME="`ls --time-style='+%s' -l ${HOME}/server/data/ | egrep "(v?maps|dbc)$" | tail -n 1 | awk {'print \$(NF-1)'}`"
echo "--------------------------------------------------------------------------------"
if [ "${MAPTOOLTIME}" -gt "${MAPTIME}" ]; then
echo "The map-tools have been updated, maps should be recreated "
else
echo "The maps are already up to date "
fi
echo -n "Update maps and vmaps? "
yesquitskip
if [ "${ANSWER}" = "y" ]; then
cd ${CLIENT} || ( echo "Game client not found at ${CLIENT}, exiting!"; exit 1 )
# The folders shouldn't be there
rm -rf dbc maps
# Extract maps
echo "${HOME}/server/bin/mapextractor"
${HOME}/server/bin/mapextractor
# Backup the existing maps
mv ${HOME}/server/data/maps ${HOME}/server/data/maps-backup.`date +%Y-%m-%d`
mv ${HOME}/server/data/dbc ${HOME}/server/data/dbc-backup.`date +%Y-%m-%d`
# Move the new maps to the server
mv dbc maps ${HOME}/server/data/
# Clean up
rm -rf vmaps Buildings
# Extract vmaps
${HOME}/server/bin/vmap4extractor
# Create vmaps
mkdir vmaps
${HOME}/server/bin/vmap4assembler Buildings vmaps
# Delete old backups
rm -rf ${HOME}/server/data/vmaps-backup.*
# Backup the existing vmaps
mv ${HOME}/server/data/vmaps ${HOME}/server/data/vmaps-backup.`date +%Y-%m-%d`
# Move the new vmaps to the server
mv vmaps ${HOME}/server/data/
# Cleanup
rm -rf Buildings
fi
}
endscreen(){
echo "--------------------------------------------------------------------------------"
echo "Script is done"
echo "--------------------------------------------------------------------------------"
}
# Let's get going
startscreen
addpath
downloadsource
compilecode
installtc
backupdb
deletedbbackups
updatedb
updatemaps
deletemapbackups
endscreen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment