Skip to content

Instantly share code, notes, and snippets.

@sasin91
Created March 26, 2016 13:29
Show Gist options
  • Save sasin91/70342fe48dd0950e6159 to your computer and use it in GitHub Desktop.
Save sasin91/70342fe48dd0950e6159 to your computer and use it in GitHub Desktop.
TrinityCore Installer bash script
#! /bin/bash
# Since bash is following a Procedural execution, defining functions first is required.
runInstaller ()
{
ValidateAndInstallDependencies
valiteUserAndEnterHome
cloneRepoAndEnterDirectory
setupDatabase
compileCore
writeRestarter
}
ValidateAndInstallDependencies ()
{
MariaDB=mariadb-server mariadb-client libmariadbclient-dev libmariadbclient18
MySQL=mysql-server mysql-client libmysqlclient-dev
CoreDependendies="
libmysql++-dev
grep
build-essential autoconf libtool gcc g++ make cmake
git-core wget
p7zip-full
libncurses5-dev zlib1g-dev libbz2-dev
openssl libssl-dev
libreadline6-dev
libboost-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-iostreams-dev
"
apt -y install $CoreDependendies $MariaDB
}
valiteUserAndEnterHome () {
# Check if User TrinityCore exists, if Not the create it.
User=TrinityCore
if !getent passwd $User =~ '^[0-9]+$'; then
useradd -m $User
fi
# Become $User and go Home
su $User
cd ~
}
cloneRepoAndEnterDirectory () {
RepoName=Core
Branch=3.3.5
GitRepo="https://github.com/TrinityCore/TrinityCore.git --branch=$Branch"
# Validate we have GIT installed
git --version
GIT_IS_AVAILABLE=$?
if [ ! $GIT_IS_AVAILABLE -eq 0 ]; then
echo "GIT not found.. Attempting to install."
apt install git
fi
git clone $GitRepo $RepoName
cd $RepoName
}
compileCore ()
{
BuildDirectory=/home/lotd/$RepoName/build
if [ ! -d "$BuildDirectory" ]; then
mkdir $BuildDirectory
fi
cd $BuildDirectory
InstallPath=/opt/$User
CMakeArgs="-DTOOLS=1 -DCMAKE_INSTALL_PREFIX="$InstallPath
cmake ../ $CMakeArgs
# @TODO: check if CMake returns good
MakeJobs=grep -c ^processor /proc/cpuinfo + 1
make -j$MakeJobs
sudo make install
}
setupDatabase()
{
# /home/TrinityCore/Core/sql/base
cd ~/$RepoName/sql/base
# @TODO: Find a method of retrieving DB name from
# pullAndExtractData method
# then append _full_ after TDB at start.
WorldDBName=TDB_full_world_335.60_2015_11_07
pullAndExtractDatabase
echo -n "Enter your database password and press [ENTER]: "
read password
# Could make an array and a for loop instead.. oh well..
mysql -uroot -p$password -e "CREATE DATABASE TrinityCore_auth"
mysql -uroot -p$password -e "CREATE DATABASE TrinityCore_characters"
mysql -uroot -p$password -e "CREATE DATABASE TrinityCore_world"
mysql -uroot -p$password TrinityCore_auth < auth_database.sql
mysql -uroot -p$password TrinityCore_characters < characters_database.sql
mysql -uroot -p$password TrinityCore_world < $WorldDBName.sql
}
pullAndExtractDatabase()
{
WorldDBName=TDB_full_335.60_2015_11_07
if [ ! -f $WorldDBName.7z ]; then
# @TODO: find method to validate DB is latest available.
URL=https://github.com/TrinityCore/TrinityCore/releases/download/TDB335.60/$WorldDBName.7z
wget $URL
fi
if [ -f $WorldDBName.7z ]; then
7z x $WorldDBName.7z
fi
}
writeRestarter ()
{
touch $InstallPath/restarter.sh
echo "
#! /bin/bash
while true; do
./worldserver
wait
done
" > $InstallPath/restarter.sh
$InstallPath/wrapper.sh
echo "
#! /bin/bash
screen -dmS "TrinityCore_world" ./restarter.sh
" > $InstallPath/wrapper.sh
chmod +x $InstallPath/wrapper.sh
chmod +x $InstallPath/restarter.sh
}
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
else
runInstaller
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment