Last active
December 15, 2015 07:39
-
-
Save DasBlub/5225067 to your computer and use it in GitHub Desktop.
bootstrap for CMaNGOS
needs testing!
TODO:
- add DBs for classic & cata
- test!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# helper functions | |
############################################################################### | |
# usage: check_dependency PROGRAM | |
function check_dependency { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 1 ] ; then | |
return 1 | |
fi | |
which $1 > /dev/null | |
if [ $? -ne 0 ] ; then | |
echo "$1 is missing but required by the selected config options! Unable to continue!" | |
exit 1 | |
fi | |
return 0 | |
} | |
############################################################################### | |
# usage: read_dflt VAR_NAME PROMPT_TEXT DFLT_VAL | |
function read_dflt { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 3 ] ; then | |
return 1 | |
fi | |
read -p "$2 [$3]: " $1 | |
if [ -z "${!1}" ] ; then | |
eval "$1=\"$3\"" | |
fi | |
return 0 | |
} | |
############################################################################### | |
# usage: read_option VAR_NAME PROMPT_TEXT ALLOWED_OPTIONS DFLT_OPTION | |
function read_option { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 3 -a $# -ne 4 ] ; then | |
return 1 | |
fi | |
optlist="[$(echo "$3" | sed 's#|#/#g')]" | |
if [ $# -eq 4 ] then | |
optlist="[$(echo "$3" | sed 's#|#/#g' | sed "s/$4/`echo "$4" | tr '[:lower:]' '[:upper:]'`/gi")]" | |
fi | |
while true ; do | |
if [ $# -eq 4 ] ; then | |
read_dflt $1 "$2 $optlist" "$4" | |
else | |
read -p "$2 $optlist: " $1 | |
fi | |
# convert to lower case | |
eval "$1=`echo ${!1} | tr '[:upper:]' '[:lower:]'`" | |
# check if the selected option is supported | |
if [ -z `echo "${!1}" | grep -E "^($3)$"` ] ; then | |
echo "Unsupported option: "${!1}"" | |
else | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
############################################################################### | |
# usage: read_dir VAR_NAME PROMPT_TEXT DFLT_VAL MUST_EXIST | |
function read_dir { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 3 -a $# -ne 4 ] ; then | |
return 1 | |
fi | |
while true ; do | |
read_dflt "$1" "$2" "$3" | |
# exists and is a directory | |
if [ -d "${!1}" ] ; then | |
return 0 | |
# exists but is not a directory | |
elif [ -e "${!1}" -a ! -d "${!1}" ] ; then | |
echo "${!1} exists but is not a directory!" | |
# does not exist and MUST_EXIST is specified | |
elif [ ! -e "${!1}" -a -n "$4" ] ; then | |
echo "${!1} does not exist!" | |
# does not exist and MUST_EXIST is not specified | |
elif [ ! -e "${!1}" ] ; then | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
# usage: read_repository VAR_NAME REPO_NAME DFLT_PROTOCOL DFLT_URL DFLT_BRANCH | |
############################################################################### | |
function read_repository { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -lt 2 -o $# -gt 5 ] ; then | |
return 1 | |
fi | |
read_option repo_protocol "Please enter the protocol for the $2 repository" "git|svn" "$3" | |
read_dflt repo_url "Please enter the URL for the $2 repository" "$4" | |
if [ "$repo_protocol" = "git" ] ; then | |
read_dflt repo_branch "Please enter the branch for the $2 repository" "$5" | |
else | |
repo_branch="" | |
fi | |
eval "$1=(\"$repo_protocol\" \"$repo_url\" \"$repo_branch\")" | |
return 0 | |
} | |
# usage: print_repo REPO_NAME PROTOCOL URL BRANCH | |
############################################################################### | |
function print_repo { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 3 -a $# -ne 4 ] ; then | |
return 1 | |
fi | |
echo "Repository for $1:" | |
echo "Protocol: $2" | |
echo "Download URL: $3" | |
if [ "$2" = "git" ] ; then | |
echo "Branch: $4" | |
fi | |
echo | |
} | |
# usage: __download_git_repo URL BRANCH DIR | |
# INTERNAL! DO NOT CALL DIRECTLY! Call download_repo instead! | |
############################################################################### | |
function __download_git_repo { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 2 -a $# -ne 3 ] ; then | |
return 1 | |
fi | |
git clone "$1" $3 | |
pushd $3 > /dev/null | |
# check out branch and track the remote branch if it is not the current branch (usually master) | |
if [ "$2" != "`git rev-parse --abbrev-ref HEAD`" ] ; then | |
git checkout -b "$2" "origin/$2" | |
fi | |
popd > /dev/null | |
return 0 | |
} | |
# usage: __download_svn_repo URL DIR | |
# INTERNAL! DO NOT CALL DIRECTLY! Call download_repo instead! | |
############################################################################### | |
function __download_svn_repo { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -ne 1 -a $# -ne 2 ] ; then | |
return 1 | |
fi | |
svn co "$1" $2 | |
return 0 | |
} | |
# usage: download_repo PROTOCOL URL BRANCH DIR | |
############################################################################### | |
function download_repo { | |
# make sure that we're being called with the correct amount of parameters! (see usage) | |
if [ $# -lt 2 -o $# -gt 4 ] ; then | |
return 1 | |
fi | |
case $1 in | |
git) __download_git_repo "$2" "$3" "$4" | |
;; | |
svn) __download_svn_repo "$2" "$3" | |
;; | |
*) echo "The protocol $1 has not yet been implemented! Only git and svn are supported!"; return 2 | |
;; | |
esac | |
return 0 | |
} | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# configuration part | |
echo "This script will help you set up CMaNGOS." | |
# ask this at the beginning, but it'll only be used later on to show advanced options | |
read_option adv_options "Do you want to use the advanced boostrap options?" "y|n" "n" | |
# this will be used to determine the repositories being used | |
read_option client_version "Which version of CMaNGOS do you want to install?" "classic|tbc|wotlk|cata" | |
# get the download location | |
read_dir download_path "Where do you want to download the files? A subdirectory 'mangos-${client_version}' will be created for you." "." | |
# get the core repository (default to CMaNGOS repo) | |
core_repo=("git" "git://github.com/cmangos/mangos-${client_version}.git" "master") | |
if [ "$adv_options" = "y" ] ; then # allow the user to override the repository path | |
read_repository core_repo "core" ${core_repo[@]} | |
fi | |
# get the script repository (default to ScriptDev2 repo) | |
has_script_repo="y" | |
script_repo=("git" "git://github.com/scriptdev2/scriptdev2-${client_version}.git" "master") | |
script_repo_name="ScriptDev2" # used to identify the folder in src/bindings/ | |
# HACK: the SD2 repository for wotlk does not use the same naming scheme... | |
if [ "$client_version" = "wotlk" ] ; then | |
script_repo[1]="git://github.com/scriptdev2/scriptdev2.git" | |
fi | |
if [ "$adv_options" = "y" ] ; then # allow the user to override the repository path | |
read_option has_script_repo "Download a script repository?" "y|n" "y" | |
if [ "$has_script_repo" = "y" ] ; then | |
read_dflt script_repo_name "Please specify the name of the script library. This name will be used to identify the folder in src/bindings/" $script_repo_name | |
read_repository script_repo "script" ${script_repo[@]} | |
fi | |
fi | |
# get the ACID repository | |
has_acid_repo="y" | |
acid_repo=("git" "git://github.com/scriptdev2/acid.git" "$client_version") | |
if [ "$adv_options" = "y" ] ; then # allow the user to override the repository path | |
read_option has_acid_repo "Download an ACID repository?" "y|n" "y" | |
if [ "$has_acid_repo" = "y" ] ; then | |
read_repository acid_repo "ACID" ${acid_repo[@]} | |
fi | |
fi | |
# get the DB | |
read_option has_db_repo "Download a database?" "y|n" "y" | |
db_repo= | |
if [ "$has_db_repo" = "y" ] ; then | |
db_versions="" | |
case $client_version in | |
classic) # TODO | |
;; | |
tbc) db_versions="tbcdb" | |
;; | |
wotlk) db_versions="udb|ytdb|psmdb" | |
;; | |
cata) # TODO | |
;; | |
esac | |
read_option db_repo_name "Which DB do you want to download?" "$db_versions|other" "other" | |
case "$db_repo_name" in | |
udb) db_repo=("svn" "https://unifieddb.svn.sourceforge.net/svnroot/unifieddb" "") | |
;; | |
ytdb) db_repo=("svn" "http://svn2.assembla.com/svn/ytdbase/" "") | |
;; | |
psmdb) db_repo=("svn" "http://subversion.assembla.com/svn/psmdb_wotlk/" "") | |
;; | |
tbcdb) db_repo=("svn" "https://tbc-db.svn.sourceforge.net/svnroot/tbc-db" "") | |
;; | |
esac | |
if [ "$adv_options" = "y" -o "$db_repo_name" = "other" ] ; then # allow the user to override the repository path | |
read_repository db_repo "Database" ${db_repo[@]} | |
fi | |
fi | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# confirmation part | |
echo "Please confirm the following settings:" | |
# path | |
echo "All files will be downloaded to $download_path" | |
# core | |
print_repo "core repository" ${core_repo[@]} | |
# script | |
if [ "$has_script_repo" = "y" ] ; then | |
print_repo "script repository $script_repo_name" ${script_repo[@]} | |
else | |
echo "Not using a script repository!" | |
fi | |
# ACID | |
if [ "$has_acid_repo" = "y" ] ; then | |
print_repo "ACID repository" ${acid_repo[@]} | |
else | |
echo "Not using an ACID repository!" | |
fi | |
# DB | |
if [ "$has_db_repo" = "y" ] ; then | |
print_repo "DB repository" ${db_repo[@]} | |
else | |
echo "Not using a database repository!" | |
fi | |
read_option settings_ok "Are those settings ok?" "y|n" | |
if [ "$settings_ok" != "y" ] ; then | |
echo "Exiting script on user request! Nothing has been changed" | |
exit 1 | |
fi | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# check dependencies | |
if [ ${core_repo[0]} = "git" -o ${script_repo[0]} = "git" -o ${acid_repo[0]} = "git" -o ${db_repo[0]} = "git" ] ; then | |
check_dependency git | |
fi | |
if [ ${core_repo[0]} = "svn" -o ${script_repo[0]} = "svn" -o ${acid_repo[0]} = "svn" -o ${db_repo[0]} = "svn" ] ; then | |
check_dependency svn | |
fi | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# download part | |
# create download path and switch to it | |
mkdir -p $download_path | |
pushd $download_path 1>/dev/null | |
echo "Please wait while the files are being downloaded..." | |
echo "Downloading the core" | |
download_repo ${core_repo[@]} "mangos-${client_version}" | |
if [ "$has_script_repo" = "y" ] ; then | |
echo "Downloading the script library" | |
download_repo ${script_repo[@]} "mangos-${client_version}/src/bindings/$script_repo_name" | |
fi | |
if [ "$has_acid_repo" = "y" ] ; then | |
echo "Downloading ACID" | |
download_repo ${acid_repo[@]} "ACID" | |
fi | |
if [ "$has_db_repo" = "y" ] ; then | |
echo "Downloading the DB" | |
download_repo ${db_repo[@]} "DB" | |
fi | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# set up the DB | |
read_option do_db "Do you want to install the DB now? Note: only MySQL is supported by this process!" "y|n" "y" | |
if [ "$do_db" = "y" ] ; then | |
check_dependency mysql | |
echo "Please enter the the DB user to be used by this setup script. This is NOT the DB user used by the server!" | |
read_dflt db_host "Host" "localhost" | |
read_dflt adm_db_user "User" "root" | |
read -p "Password (hidden): " -s adm_db_pw | |
run_mysql="mysql -u$adm_db_user -p$adm_db_pw $db_host" | |
# check if the user wants to create the user or if the user already exist | |
read_option db_user_exists "Does the DB user you want to use for the server already exist?" "y|n" "n" | |
if [ "$db_user_exists" = "n" ] ; then | |
read_dflt db_user_name "Please enter the name of the DB user to be created" "mangos" | |
read -p "Password (hidden): " -s db_user_pw | |
$run_mysql <<EOF | |
CREATE USER '$db_user_name'@'localhost' IDENTIFIED BY '$db_user_pw'; | |
EOF | |
fi | |
# check if the user wants to create the db or they already exist | |
create_db="y" | |
if [ "$adv_options" = "y" ] ; then | |
read_option create_db "Create the databases 'mangos', 'characters', 'realmd' and optionally 'scriptdev2' (only when using SD2) and grant access to the $db_user_name user?" "y|n" "$create_db" | |
fi | |
if [ "$create_db" = "y" ] ; then | |
mangos_db_name=mangos | |
characters_db_name=characters | |
realmd_db_name=realmd | |
if [ "$adv_options" = "y" ] ; then # allow the user to define other db names | |
read_dflt mangos_db_name "Please specify the name for the mangos DB" "$mangos_db_name" | |
read_dflt characters_db_name "Please specify the name for the mangos DB" "$characters_db_name" | |
read_dflt realmd_db_name "Please specify the name for the mangos DB" "$realmd_db_name" | |
fi | |
script_db_name="" | |
if [ "$has_script_repo" = "y" ] ; then | |
if [ "$script_repo_name" = "ScriptDev2" ] ; then | |
script_db_name=scriptdev2 | |
fi | |
if [ "$adv_options" = "y" -o -z "$script_db_name" ] ; then # allow the user to define other db names | |
read_dflt script_db_name "Please specify the name for the script DB" "$script_db_name" | |
fi | |
fi | |
# create DBs | |
for tmp_db_name in $mangos_db_name $characters_db_name $realmd_db_name $script_db_name ; do | |
$run_mysql <<EOF | |
CREATE DATABASE ${tmp_db_name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; | |
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES ON ${tmp_db_name}.* TO '$db_user_name'@'localhost'; | |
EOF | |
done | |
fi | |
# create DB content | |
$run_mysql $mangos_db_name < mangos-${client_version}/sql/mangos.sql | |
$run_mysql $characters_db_name < mangos-${client_version}/sql/characters.sql | |
$run_mysql $realmd_db_name < mangos-${client_version}/sql/realmd.sql | |
if [ "$script_repo_name" = "ScriptDev2" ] ; then | |
$run_mysql $script_db_name < mangos-${client_version}/src/bindings/ScriptDev2/sql/scriptdev2_create_structure_mysql.sql | |
$run_mysql $script_db_name < mangos-${client_version}/src/bindings/ScriptDev2/sql/scriptdev2_script_full.sql | |
fi | |
if [ "$has_db_repo" = "y" ] ; then | |
echo "** You need to manually install your world DB according to their specific installation instructions. You may find your DB here: $download_path/DB" | |
fi | |
fi | |
############################################################################### | |
############################################################################### | |
############################################################################### | |
# the end | |
echo "***********************" | |
echo "The installation has finished. You now need to compile the server." | |
echo "Do you want to use CMake for this? If you are on Windows, it is currently recommended to use the native Visual Studio files delivered in the win/ subdirectory from CMaNGOS and the script library" | |
read_option do_cmake "Run CMake now with default parameters?" "y|n" "n" | |
if [ "$do_cmake" = "y" ] ; then | |
check_dependency cmake | |
mkdir run | |
mkdir build | |
pushd build > /dev/null | |
cmake ../mangos-${client_version}/ -DCMAKE_INSTALL_PREFIX=../run | |
read_option do_make "Should this script also run make to compile the server?" "y|n" "y" | |
if [ "$do_make" = "y" ] ; then | |
check_dependency make | |
make && make install | |
fi | |
popd | |
else | |
"Please either use the Visual Studio files or run cmake manually" | |
fi | |
# go back to the original directory | |
popd 1>/dev/null | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment