Skip to content

Instantly share code, notes, and snippets.

@CansecoDev
Created November 22, 2018 00:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CansecoDev/2ff99b1ea1f51f7527bde67b6a1cf5ae to your computer and use it in GitHub Desktop.
Save CansecoDev/2ff99b1ea1f51f7527bde67b6a1cf5ae to your computer and use it in GitHub Desktop.
VMaNGOS deploy script for Ubuntu 16.04
#!/bin/bash
#============================================================================
#title :vmangos.sh
#description :VMaNGOS deploy script for Ubuntu 16.04
#author :canseco.me
#date :20181122
#version :0.8.1
#============================================================================
## Utilities
function mark()
{
export $1=`pwd`;
}
function ipaddr()
{
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
}
function netmask()
{
ifconfig | grep `ipaddr` | cut -d ':' -f 4
}
## I am root
function root()
{
if [ "$EUID" -ne 0 ]
then return 1
else return 0
fi
}
## Distribution release number
function dist()
{
lsb_release -r | cut -f2
}
## Server internet connectivity
function online()
{
if ping -q -c 1 -W 1 google.com > /dev/null; then
return 0
else
return 1
fi
}
## Manage arguments
## to-do
## --help
## --version {tested|last|hash}
## --address
## --patch
## --client
## --user-add
## --restart
## --console
## Select allowed client version
## to-do
## Select server patch
## to-do
## Update system
function update()
{
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
apt-get -qy update &&
apt-get -qy -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade &&
apt-get -qy --with-new-pkgs upgrade &&
apt-get -qy autoclean &&
apt-get -qy autoremove
}
## Install dependencies
function dependencies()
{
apt-get -qy update &&
#apt-get -qy install gcc g++ automake git-core autoconf make cmake patch libmysql++-dev libtool libssl-dev grep binutils zlibc libc6 libbz2-dev git libreadline-dev libboost-all-dev libncurses-dev libmysqlclient-dev build-essential subversion libace-dev libtbb-dev &&
apt-get -qy install gcc g++ automake git-core autoconf make cmake patch libmysql++-dev libtool libssl-dev grep binutils zlibc libc6 libbz2-dev git libreadline-dev libboost-all-dev libncurses-dev libmysqlclient-dev build-essential subversion libace-dev libtbb-dev libaio1 libaio-dev p7zip-full unrar &&
apt-get -qy autoclean &&
apt-get -qy autoremove
update
}
## Install MySQL 5.5.62
function mysqlinstall()
{
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
groupadd mysql
useradd -g mysql mysql
tar xvC /usr/local -zf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
rm mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
mv /usr/local/mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
mark preSQL
cd /usr/local/mysql
#apt-get -qy install libaio1 libaio-dev
#update
./scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql.server
update-rc.d -f mysql.server defaults
/etc/init.d/mysql.server start
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
bin/mysqladmin -u root password 'mangos'
cd $preSQL
sed -i.bak 's/^\(max_allowed_packet = \).*/\1256M/' /etc/my.cnf
/etc/init.d/mysql.server restart
}
## Clone tested version
function clonelast()
{
git clone https://github.com/vmangos/core.git vmangos/core
cd vmangos/core
git reset --hard acaa54ae9da242657474dee544f1f8382dbd5c39
cd ../..
git clone https://github.com/brotalnia/database vmangos/db
cd vmangos/db
git reset --hard f195eb2ae8dd760553e5eb5fe11239bf10f351da
cd ../..
}
## Clone specific version
## to-do
## Clone last version
## to-do
# DB structure
function dbsetup()
{
echo -e "CREATE DATABASE \`realmd\`;
CREATE DATABASE \`mangos\`;
CREATE DATABASE \`characters\`;
CREATE DATABASE \`logs\`;
CREATE USER 'mangos'@'localhost' IDENTIFIED BY 'mangos';
GRANT USAGE ON *.* TO 'mangos'@'localhost';
GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON \`realmd\`.* TO 'mangos'@'localhost';
GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON \`mangos\`.* TO 'mangos'@'localhost';
GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON \`characters\`.* TO 'mangos'@'localhost';
GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON \`logs\`.* TO 'mangos'@'localhost';
FLUSH PRIVILEGES;
" > structure.sql
mysql -u root -pmangos < structure.sql
rm structure.sql
}
## DB Feed
function dbfeed()
{
#apt-get -qy install p7zip-full
#update
7z x vmangos/db/world_full_26_august_2018.7z
mysql -u mangos -pmangos --database=mangos < world_full_26_august_2018.sql
rm world_full_26_august_2018.sql
mysql -u mangos -pmangos --database=characters < vmangos/core/sql/characters.sql
mysql -u mangos -pmangos --database=logs < vmangos/core/sql/logs.sql
mysql -u mangos -pmangos --database=realmd < vmangos/core/sql/logon.sql
echo -e "INSERT INTO \`realmd\`.\`realmlist\` (\`name\`, \`address\`, \`localAddress\`, \`localSubnetMask\`, \`realmbuilds\`) VALUES ('VMaNGOS', '`ipaddr`', '`ipaddr`', '`netmask`', '5875 6005 6141');
" > db.sql
mysql -u mangos -pmangos --database=realmd < db.sql
rm db.sql
cd vmangos/core/sql/migrations
./merge.sh
mysql -u mangos -pmangos --database=mangos < world_db_updates.sql
rm world_db_updates.sql
cd ../../../..
}
## Set-up mangos user
function userskel()
{
groupadd mangos
useradd -g mangos mangos
}
## Compile and pray
function compile()
{
cd vmangos/core
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/mangos/ ..
make -j4
cd ../../..
}
## Deploy server files
function deploy()
{
mkdir -p /opt/mangos/etc
cd vmangos/core/build
cp src/mangosd/mangosd* /opt/mangos/
cp /opt/mangos/mangosd.conf.dist /opt/mangos/etc/mangosd.conf
cp src/realmd/realmd /opt/mangos/
cp ../src/realmd/realmd.conf.dist.in /opt/mangos/
cp /opt/mangos/realmd.conf.dist.in /opt/mangos/etc/realmd.conf
## download maps to /opt/mangos
chown -R mangos:mangos /opt/mangos
cd ../../..
}
## Maps for 1.12.1
function maps()
{
echo Thanks for using this script, but it is unfinished
echo Move your maps into /opt/mangos
echo Open two terminals and run first ./realmd then ./mangosd
# to-do
}
## Maps for 1.10.2
## to-do
## Maps for 1.9.4
## to-do
## Init scripts
## to-do
## First run wake up
## to-do
## mangosd start
## to-do
## mangosd stop
## to-do
## mangosd restart
## to-do
## realmd start
## to-do
## realmd stop
## to-do
## realmd restart
## to-do
## Add GM account
## to-do
## User add
## to-do
function proceed()
{
update
dependencies
mysqlinstall
clonelast
dbsetup
dbfeed
userskel
compile
deploy
maps
}
function init()
{
if root
then
if online
then
if [[ `dist` == "16.04" ]]
then
proceed
else
echo This only runs in Ubuntu 16.04
exit 39
fi
else
echo This only runs with an internet connection
exit 38
fi
else
echo This only runs as root\ \ \ \ \ \(sudo su\)
exit 37
fi
}
init
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment