First of i have to say that most of this code comes from elegos scripts. I have changed it a bit to match the actual reality.
For this to work you need to create 3 files: doMake doInstall config
This is the code inside them:
config:
[SPOILER]#######################
########CONFIG#########
MODES
PATCH_MODE=1
PAUSE_MODE=1
DELETE_SOURCES=1
JOINSQL=1
JOBS=2
INSTALL_DIR=“/home/wow/server”
ETC_DIR=“/home/wow/server/etc”
HOME_DIR=“/home/wow”
PATCHES_DIR=“/home/wow/patches”
PATCHES_REPO=“https://github.com/thedevnull/thedevnull-patches.git”
PATCHES=“ahbot”
SOURCES_DIR=“/home/wow/sources”
SOURCES_REPO=“git://github.com/TrinityCore/TrinityCore.git”
#########END###########
#######################
[/SPOILER]
doMake:
#!/bin/bash
. conf
function pause(){
read -s -n 1 -p “”
}
The following functions convert the given date from and to Unix Epoch time (http://en.wikipedia.org/wiki/Unix_time)
I use them to convert a date to Unix time, add the days I want (in seconds) and convert back to YYYY-MM-DD date
date2stamp () {
date --utc --date “$1” +%s
}
stamp2date (){
date --utc --date “1970-01-01 $1 sec” “+%Y-%m-%d”
}
R=$1
if [ “$R” = “” ]; then
R=“0”
fi
step=1
numstep=5
if [ ${PATCH_MODE} = 1 ]; then
let numstep=$numstep+2
fi
if [ ${JOINSQL} = 1 ]; then
let numstep=$numstep+1
fi
CHECK CODE
clear
echo Total number of steps is $numstep
echo Current step is $step
pause
Grab the actual Commit Hash and Date.
if [ -e $SOURCES_DIR ]; then
cd ${SOURCES_DIR}
lasthash=$(git rev-list --max-count=1 HEAD)
lastdate=$(git log --pretty=format:“%ad” -1)
lastrev="CommitHash: “${lasthash}” DateTime: "${lastdate}
lastrevdate=$(git log --pretty=format:“%ad” --date=short -1)
cd $HOME_DIR
fi
Delete TrinityCore repo if DELETE_SOURCES is activated
if [ ${DELETE_SOURCES} = 1 ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to delete the Trinity repo. |”
echo “| (If you don’t want this, |”
echo “| change DELETE_SOURCES to 0 in config file) |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “| |”
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
rm -f -R $SOURCES_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Trinity repo deleted successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
Revert changes if directory $SOURCES_DIR exists.
if [ -e $SOURCES_DIR ]; then
echo " "
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to Revert changes done to the repo. |”
echo “| (If instead of reverting you want to pull a clean repo, |”
echo “| go to the config file and change DELETE_SOURCES to 1) |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
cd $SOURCES_DIR
git reset --hard
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Changes reverted successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
let step=$step+1
Delete Patches repo if DELETE_SOURCES is activated
if [ ${DELETE_SOURCES} = 1 ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Deleting the Patches repo. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
rm -f -R $PATCHES_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Patches repo deleted successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
Revert changes if directory $PATCHES_DIR exists.
if [ -e $PATCHES_DIR ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Reverting the Patches repo. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
cd $PATCHES_DIR
git reset --hard
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Patches repo reverted successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
let step=$step+1
Clone or update the local repo.
if [ ! -e $SOURCES_DIR ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Cloning TrinityCore repo. |”
echo “| (If you want to only update instead of cloning, |”
echo “| change DELETE_SOURCES to 0 in the config file) |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
git clone $SOURCES_REPO $SOURCES_DIR
cd $SOURCES_DIR
thishash=$(git rev-list --max-count=1 HEAD)
thisdate=$(git log --pretty=format:“%ad” -1)
thisrev="CommitHash: “${thishash}” DateTime: "${thisdate}
hash=$(git rev-list --max-count=1 HEAD)
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| TrinityCore repo cloned successfully. |”
echo “| |”
echo “| Last update: “${lasthash}” |”
echo "| Of: "${lastdate}
echo “| |”
echo “| This update: “${thishash}” |”
echo "| Of: "${thisdate}
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
else
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Updating TrinityCore repo. |”
echo “| (If you want clean sources instead of updating the existing ones, |”
echo “| change DELETE_SOURCES to 1 in the config file) |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
cd $SOURCES_DIR
git pull origin master
thishash=$(git rev-list --max-count=1 HEAD)
thisdate=$(git log --pretty=format:“%ad” -1)
thisrev="CommitHash: “${thishash}” DateTime: "${thisdate}
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| TrinityCore repo updated successfully. |”
echo “| |”
echo “| Last update: “${lasthash}” |”
echo "| Of: "${lastdate}
echo “| |”
echo “| This update: " ${thishash}” |"
echo "| Of: "${thisdate}
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
let step=$step+1
echo "Latest rev: "${lastrev} > $INSTALL_DIR/revision.log
echo "Actual rev: "${thisrev} >> $INSTALL_DIR/revision.log
if [ ${PATCH_MODE} = 1 ]; then
if [ ! -e $PATCHES_DIR ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Cloning Patches repo. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
git clone $PATCHES_REPO $PATCHES_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Patches repo cloned successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
else
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Updating Patches repo. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
cd $PATCHES_DIR
git pull origin master
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Patches repo updated successfully. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
let step=$step+1
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to apply patches to source code. |”
echo “| (If you don’t want to apply any patches |”
echo “| change PATCH_MODE to 0 in the config file) |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
for PATCH in $PATCHES; do
cd $PATCHES_DIR/$PATCH
LASTREV=ls -d *|tail -n 1
cd $SOURCES_DIR
git apply $PATCHES_DIR/$PATCH/$LASTREV/$PATCH.patch
done
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| Patches applied to source code. |”
echo “| Check for any error. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
let step=$step+1
Configure the build process
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to configure and build TrinityCore. |”
if [ ${PATCH_MODE} = 0 ]; then
echo “| (If you want to apply patches to the code, |”
echo “| change PATCH_MODE to 1 in config file |”
echo “| and enter the patch names to PATCHES variable, space seperated) |”
fi
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
cd ${SOURCES_DIR}
mkdir -p bin
cd bin
export CXXFLAGS=“-march=native -O3”
export CFLAGS=“-march=native -O3”
cmake …/ -DSCRIPTS=1 -DSERVERS=1 -DTOOLS=1 -DPREFIX=$INSTALL_DIR -DCONF_DIR=$ETC_DIR -DWITH_WARNINGS=1
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| TrinityCore configuration completed. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
let step=$step+1
Build the code
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to build TrinityCore. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
make -j${JOBS}
cd $HOME_DIR
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| TrinityCore build completed. |”
echo “| Check for any errors. |”
echo “| |”
echo “| You will find a revision.log file with the latest |”
echo “| and actual revision and is dates, if you need |”
echo “| to revert any changes. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
let step=$step+1
Produce the SQL Update files
if [ ${JOINSQL} = 1 ]; then
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Starting Step $step of $numstep. |”
echo “| Going to compile SQL files since last build. |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
The Counter variable will hold seconds in Unix Time. Adding 86400 seconds later on, we add 1 day to $getdate
Counter=0
I’m going to convert $lastrevdate to Unix Time so I can add days to it
lastrevdateUE=$(date2stamp $lastrevdate)
Adding one day to $getdateUE and converting it to YYYY-MM-DD date format to be assigned to $getdate
getdateUE=$(echo $lastrevdateUE+$Counter | bc)
getdate=$(stamp2date $getdateUE)
today=$(date -d “+2 day” +“%F”)
Right below is the original code to assign $getdate and add x number of days, that didn’t work for me. The $Counter used to be 1
getdate=$(date --date=“$lastrevdate” -d “+”$Counter" day" +“%F”)
rm $SOURCES_DIR/sql/updates/*.sql
while [ “$today” != “$getdate” ]
do
lastrevyear=$(echo $getdate | cut -c1-4)
lastrevmonth=$(echo $getdate | cut -c6-7)
lastrevday=$(echo $getdate | cut -c9-10)
since=$lastrevyear"“$lastrevmonth”"$lastrevday
cat $SOURCES_DIR/sql/updates/world/$since*.sql >> world_updates.sql
cat $SOURCES_DIR/sql/updates/characters/$since*.sql >> character_updates.sql
cat $SOURCES_DIR/sql/updates/auth_char/$since*.sql >> auth_updates.sql
let Counter=$Counter+86400
I’m adding 86400 seconds again (1 day) to $getdateUE (Unix Time) and then converting to YYYY-MM-DD
let getdateUE=$lastrevdateUE+$Counter
getdate=$(stamp2date $getdateUE)
done
rm -R $INSTALL_DIR/sql
mkdir $INSTALL_DIR/sql
mv *.sql $INSTALL_DIR/sql
clear
echo -e ‘\E[33;40m’
echo “±-----------------------------------------------------------------------------+”
echo “| Step $step of $numstep Completed. |”
echo “| The SQL files have been written to your installation folder |”
echo “| You need to execute them individually on each database. |”
echo “| |”
echo “| |”
if [ ${PAUSE_MODE} = 1 ]; then
echo “| Press a key to continue or CTRL+C to exit |”
echo “| (To disable pause, change PAUSE_MODE to 0 in the config file) |”
echo “| |”
fi
echo “±-----------------------------------------------------------------------------+”
tput sgr0
if [ ${PAUSE_MODE} = 1 ]; then
pause
fi
fi
doInstall:
[SPOILER]#!/bin/bash
. config
Move to compiled dir
cd ${SOURCES_DIR}/bin
Make the install
make install
[/SPOILER]
After you saved all files: chmod +x doMake doInstall
I think here all is ok. Tell me if something isn’t working well.
2011-05-05:
-
Removed version numbering from code.
-
Better user handling when in pause mode.
-
Added SQL parsing since the last update (this is a usefull update, the script tracks the changes since the last update and create the sql files with those changes only)
-
Separate all actions into 8 steps.
-
Added info and sugestions on what is it doing on each step.