Skip to content

Instantly share code, notes, and snippets.

@Schmoozerd
Last active December 15, 2015 07:19
Show Gist options
  • Save Schmoozerd/5223011 to your computer and use it in GitHub Desktop.
Save Schmoozerd/5223011 to your computer and use it in GitHub Desktop.
Bootstrap script to install cmangos
# Copyright (C) 2012 CMaNGOS project
#
#!/bin/sh
#
# This script will help to create directories and download the required content for CMaNGOS installation
# It is designed to be used with beginners and help automate installation
#
# Some variables that will be asked by the script
CLIENT="wotlk"
CORE_REPO=""
SD2_REPO=""
INSTALL_PATH="."
OS="win"
DATABASE=""
DB_USER="root"
#CLIENT_FOLDER="" TODO, help with data extraction?!
# Some constants
SRC_CORE_CATA="git://github.com/cmangos/mangos-cata.git"
SRC_CORE_WOTLK="git://github.com/cmangos/mangos-wotlk.git"
SRC_CORE_TBC="git://github.com/cmangos/mangos-tbc.git"
SRC_CORE_CLASSIC="git://github.com/cmangos/mangos-classic.git"
SRC_SD2_CATA="git://github.com/scriptdev2/scriptdev2-cata.git"
SRC_SD2_WOTLK="git://github.com/scriptdev2/scriptdev2-wotlk.git"
SRC_SD2_TBC="git://github.com/scriptdev2/scriptdev2-tbc.git"
SRC_SD2_CLASSIC="git://github.com/scriptdev2/scriptdev2-classic.git"
DB_ACID="git://github.com/scriptdev2/acid.git"
DB_SVN_UDB="https://unifieddb.svn.sourceforge.net/svnroot/unifieddb"
DB_SVN_YTDB="http://svn2.assembla.com/svn/ytdbase/"
DB_SVN_PSMDB="http://subversion.assembla.com/svn/psmdb_wotlk/"
DB_SVN_TBCDB="https://tbc-db.svn.sourceforge.net/svnroot/tbc-db"
# Startup
clear
echo "******************************************************************************"
echo
echo " Welcome to CMaNGOS bootstrap helper script"
echo
echo "******************************************************************************"
echo
echo "Please also consider our installation instructions"
echo "These can be found at:"
echo " https://github.com/cmangos/mangos-wotlk/wiki/Installation-Instructions"
echo
echo "This script will help you downloading the required data to install CMaNGOS"
echo
# ? - Client
echo "For which client do you want to download cmangos? (Default WotLK)"
echo "Supported are Classic, TBC, WotLK and Cata"
echo
read -p"Client: " line
echo
if [ "$line" != "" ]; then CLIENT=`echo $line | tr -s '[:upper:]' '[:lower:]'`; fi
case "$CLIENT" in
cata)
CORE_REPO=$SRC_CORE_CATA
SD2_REPO=$SRC_SD2_CATA
;;
wotlk)
CORE_REPO=$SRC_CORE_WOTLK
SD2_REPO=$SRC_SD2_WOTLK
;;
tbc)
CORE_REPO=$SRC_CORE_TBC
SD2_REPO=$SRC_SD2_TBC
;;
classic)
CORE_REPO=$SRC_CORE_CLASSIC
SD2_REPO=$SRC_SD2_CLASSIC
;;
*)
echo "ERROR: Unknown client $line"
echo "You must enter either Classic, TBC, WotLK or Cata. Aborting.."
exit 1
esac
# ? - OS
# TODO - There may be ways to get this automated, but this appears more likely to fail
echo "Please enter on which operating system you are"
echo "Content must be: win or linux"
echo
read -p"OS: " line
echo
OS=`echo $line | tr -s '[:upper:]' '[:lower:]'`
case "$OS" in
win|windows)
OS="win"
;;
linux)
OS="linux"
;;
*)
echo "WARNING: Only Windows and Linux are supported in the moment"
esac
# ? - Path
echo "Please enter the base path into which you want to install CMaNGOS"
echo "Suggested is:"
echo " for Windows: \"C:\CMaNGOS\""
echo " for Linux&al: \"~/CMaNGOS\""
echo " \".\" for the current directory - if you have already created a base folder"
echo " (be aware of created subfolders)"
echo
echo "This script will create this path. Be sure to only enter a sane value!"
echo
read -r -p"Installation Path: " line
echo
if [ "$line" = "" -o "$line" = "." ]; then
INSTALL_PATH="."
else
if [ -d "$line" ]; then
echo "ERROR: This directory already exists. Aborting.."
exit 1
fi
# Change C:, D: to /c, /d and \ to /
INSTALL_PATH=$(echo ${line} | sed -e 's/^C:/\/c/g' -e 's/^D:/\/d/g' -e 's/\\/\//g')
mkdir -p "$INSTALL_PATH"
fi
cd "$INSTALL_PATH"
INSTALL_PATH=`pwd`
# Clone repositories
echo "Attempting to clone the repositories, this will take some time!"
echo "Just wait until it is finished :) "
git clone $CORE_REPO mangos
[[ $? != 0 ]] && exit 1
echo
echo "Cloned the core repository, now cloning SD2"
echo
cd mangos/src/bindings
git clone $SD2_REPO ScriptDev2
[[ $? != 0 ]] && exit 1
echo
echo "ScriptDev2 cloned, now cloning ACID"
echo
cd "$INSTALL_PATH"
#TODO - directly clone proper branch?
git clone $DB_ACID acid
[[ $? != 0 ]] && exit 1
echo
echo "All Repositories from Github are cloned"
echo
if [ "$CLIENT" != "wotlk" ]; then
echo "Switching branch in acid to reflect client version"
echo
cd acid
git checkout -b $CLIENT origin/$CLIENT
cd ..
fi
echo "Please press [RETURN] when you are ready to continue"
read -p"Press to continue.. " line
# Create folders
clear
echo "This script will now create some default folders"
echo
cd "$INSTALL_PATH"
mkdir "run"
if [ "$OS" = "linux" ]; then
mkdir "build"
fi
echo "You now have these folders:"
echo "$INSTALL_PATH/mangos"
echo " this folder contains the repositories of CMaNGOS and ScriptDev2"
echo "$INSTALL_PATH/acid"
echo " this folder contains the ACID repository (scripting for trash mobs)"
echo
echo "$INSTALL_PATH/run"
echo " this folder is intended to store the executables of your configuration."
echo " you will need to execture the files mangosd and realmd so that you will be able to connect to your folder"
echo " also you will need to edit the configuration files there and store the extracted data in there"
echo
if [ "$OS" = "linux" ]; then
echo "$INSTALL_PATH/build"
echo " this folder is intended to store the files created for building."
echo " you will go into this folder if you need to rebuild your sources"
echo
elif [ "$OS" = "win" ]; then
cp "$INSTALL_PATH/mangos/src/mangosd/mangosd.conf.dist.in" "$INSTALL_PATH/run/mangosd.conf"
cp "$INSTALL_PATH/mangos/src/realmd/realmd.conf.dist.in" "$INSTALL_PATH/run/mangosd.conf"
cp "$INSTALL_PATH/mangos/src/bindings/ScriptDev2/scriptdev2.conf.dist.in" "$INSTALL_PATH/run/scriptdev2.conf"
cp "$INSTALL_PATH/mangos/src/game/AuctionHouseBot/ahbot.conf.dist.in" "$INSTALL_PATH/run/ahbot.conf"
fi
echo "$INSTALL_PATH/ <Database Name>"
echo " If you chose to download a database, a folder for this will be added here as well"
echo " If you download your database manually, we still suggest to place it into a subfolder of"
echo " $INSTALL_PATH - so that it can be found nicely"
echo
echo "Press [RETURN] when you are ready to continue"
read -p"Press to continue.. " line
echo
# Patch CMake file for SD2 on linux
if [ "$OS" = "linux" ]; then
echo "We need to patch a CMake file for SD2 to be compiled automatically"
echo
cd "$INSTALL_PATH"
cd mangos
git am src/bindings/ScriptDev2/patches/MaNGOS-11167-ScriptDev2.patch
[[ $? != 0 ]] && exit 1
cd ..
fi
# ? - Initial database setup
clear
echo "Do you want to create some basic initial database setup?"
echo "This will add the user \"mangos\" with the password \"mangos\""
echo "as well as these default databases:"
echo " mangos -- holds the information about the world"
echo " realmd -- holds the information about accounts"
echo " characters -- holds the information about characters"
echo " scriptdev2 -- holds the information of ScriptDev2"
echo
echo "ATTENTION! This is no secure user/pass combination!"
echo "Use this only for testing purposes on a system where mysql-access is restricted to localhost only!"
echo
echo "Also to be able to create this mangos user, you will need a user with the rights to do so."
echo
echo "Do you want to get the basic default database setup? (y/n)"
read -p"Default DB-setup(y/n): " line
echo
if [ "$line" = "y" ]; then
echo "Please enter your database-user (usually root)"
read line
if [ "$line" != "" ]; then DB_USER=$line; fi
echo
echo "Create now DB-User \"mangos\" with password \"mangos\""
echo " with access to the created databases mangos, realmd, characters and scriptdev2"
cd "$INSTALL_PATH/mangos/sql"
mysql -u"$DB_USER" -p < create_mysql.sql
mysql -umangos -pmangos characters < characters.sql
mysql -umangos -pmangos mangos < mangos.sql
mysql -umangos -pmangos realmd < realmd.sql
cd "$INSTALL_PATH/mangos/src/bindings/ScriptDev2/sql"
mysql -u"$DB_USER" -p < scriptdev2_create_database.sql
mysql -umangos -pmangos scriptdev2 < scriptdev2_create_structure_mysql.sql
mysql -umangos -pmangos scriptdev2 < scriptdev2_script_full.sql
cd "$INSTALL_PATH"
echo "Press [RETURN] to continue"
read -p"Press to continue.. " line
fi
# ? - Database
clear
echo "Which database do you want to download? (Press ENTER to skip database download)"
case "$CLIENT" in
cata)
#TODO
;;
wotlk)
echo "For WotLK you have several options for databases to use:"
echo "Please chose one of:"
echo " UDB - http://udb.no-ip.org/index.php"
echo " YTDB - http://ytdb.ru/"
echo " PSMDB - http://project-silvermoon.forumotion.com/"
echo
;;
tbc)
echo "For TBC you can use TBCDB"
echo
;;
classic)
#TODO
;;
esac
echo "Please enter your choice:"
read -p"Selected Database: " line
echo
DATABASE=`echo $line | tr -s '[:upper:]' '[:lower:]'`
echo
# Helper to display a dialogue for downloading svn manually
function manual_svn {
echo "You need to manually checkout $1 with a SVN client like TortoiseSVN"
echo
echo "The URL you need to enter is $2"
if [ "$OS" = "win" ]; then
echo "You can copy&paste from here by clicking on the top-left corner,"
echo "select edit and then \"mark\""
fi
echo
echo "Press [RETURN] when you have cloned the $1 database"
echo "Please make sure to clone it into a subfolder of $INSTALL_PATH"
echo "If you don't want to clone right now, or want to clone to another place,"
echo "Then just press return"
read -p"Press to continue.. " line
}
# Function to create a standardized config file for the DB to use
function create_dbconfig {
if [ -e "$1" ]; then
echo "You have already a config file for your DB setup. This file will not be overwritten!"
echo
fi
cat > "$1" << EOF
####################################################################################################
# This is the config file for the InstallFull_DB script
#
# You need to insert
# DATABASE: Your database
# USERNAME: Your username
# PASSWORD: Your password
# CORE_PATH: Your path to core's directory (OPTIONAL: Use if you want to apply remaining core updates automatically)
# ACID_PATH: Your path to a git-clone of ACID (OPTIONAL: Use it if you want to install recent downloaded acid)
# SD2_UPDATES: If you want to disable adding ScriptDev2 updates (Has only meaning if CORE_PATH above is set
# MYSQL: Your mysql command (usually mysql)
#
####################################################################################################
## Define the database in which you want to add clean UDB
DATABASE="mangos"
## Define your username
USERNAME="mangos"
## Define your password (It is suggested to restrict read access to this file!)
PASSWORD="mangos"
## Define the path to your core's folder (This is optional)
## If set the core updates located under sql/updates from this mangos-directory will be added automatically
CORE_PATH="$INSTALL_PATH/mangos"
## Define the path to the folder into which you cloned ACID (This is optional)
## If set the file acid_wotlk.sql will be applied from this folder
ACID_PATH="$INSTALL_PATH/acid"
## Include ScriptDev2 updates? (If set, the SD2-Updates are expected to be located in the place defined at CORE_PATH)
## NOTE: They are only applied if CORE_PATH is set!
## Set to 0 if you want core updates BUT no SD2-updates
SD2_UPDATES="1"
## Define your mysql programm if this differs
MYSQL="mysql"
# Enjoy using the tool
EOF
}
case "$DATABASE" in
"")
echo "You did not specify any database. None will be downloaded by this programm"
;;
"udb")
if [ "$OS" = "linux" ]; then
svn co "$DB_SVN_UDB"
else
manual_svn UDB "$DB_SVN_UDB"
fi
if [ -d "unifieddb/trunk" ]; then
cd unifieddb/trunk
create_dbconfig "InstallFullUDB.config"
echo "For automated UDB installation, we will attempt to start their installer script"
echo
echo "This will work out of the box IF you used default database creation."
echo "Is your database setup created for:"
echo " user: mangos"
echo " pass: mangos"
echo " world-database: mangos"
echo "These values will be filled in, if you used the standard creation. (y/n)"
read -p "Did you use default settings? " line
if [ "$line" != "y" ]; then
echo
echo "As you have not the default settings, be sure to manually edit the file"
echo "$INSTALL_PATH/unifieddb/trunk/InstallFullUDB.config"
echo
echo "Press y if you have edited the config file to correct settings"
read -p"Changed config? " line
if [ "$line" = "y" ]; then
sh InstallFullUDB.sh
fi
else
sh InstallFullUDB.sh
fi
echo
cd "$INSTALL_PATH"
fi
;;
"ytdb")
if [ "$OS" = "linux" ]; then
svn co "$DB_SVN_YTDB"
else
manual_svn YTDB "$DB_SVN_YTDB"
fi
;;
"psmdb")
if [ "$OS" = "linux" ]; then
svn co "$DB_SVN_PSMDB"
else
manual_svn PSMDB "$DB_SVN_PSMDB"
fi
;;
"tbcdb")
if [ "$OS" = "linux" ]; then
svn co "$DB_SVN_TBCDB"
else
manual_svn TBCDB "$DB_SVN_TBCDB"
fi
;;
#TODO DBs for other clients
*)
echo "ERROR: You did specify an unsupported database provider!"
echo
esac
## Compiling
# Run CMake and make
if [ "$OS" = "linux" ]; then
echo
echo "This script will now initiate the CMake process"
echo
cd "$INSTALL_PATH"
cd build
cmake ../mangos -DCMAKE_INSTALL_PREFIX=../run -DDEBUG=1
echo
echo "Start compile and install"
echo "Do not be alarmed about warnings!"
echo
echo "Press [RETURN] when you are ready to start"
read -p"Press to start " line
echo
make && make install
echo
echo
echo "The files have now been created to $INSTALL_PATH/run"
echo
# Instructions for VC compile
elif [ "$OS" = "win" ]; then
echo
echo "To compile CMaNGOS use your explorer to switch to the directory"
echo "mangos\win"
echo "There you double-click onto the fitting \"Microsoft Visual Studio Solution\" file."
echo " mangosdVC90 - for VC 2008"
echo " mangosdVC100 - for VC 2010"
echo " mangosdVC110 - for VC 2012"
echo "Then you click \"Build\" and then \"Build Solution\""
echo
echo "Building will take a while. Do not be alarmed by warnings"
echo
echo "Then you should compile ScriptDev2"
echo "For this open the mangos/src/bindings/ScriptDev2 folder int he explorer"
echo "and double-click on the file"
echo " scriptVC90 - for VC 2008"
echo " scriptVC100 - for VC 2010"
echo " scriptVC110 - for VC 2012"
echo "and then start the build"
echo
echo
echo "The created files will be added to mangos\bin folder"
echo
echo "Press y if you have compiled your sources and want to copy"
echo "the files to your run folder"
echo
echo "After you extracted the data (maps, vmaps, mmaps) from the client"
echo "You must be able to start your server software"
echo "by starting the executables \"mangosd\" and \"realmd\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment