Ubuntu 14.04 server setup script
Posted: Tue Feb 09, 2016 10:06 pm
I think the majority of folks setting up servers are running Windows but there might be some people out there like myself that prefer linux. This script was written because I like breaking servers, not gonna lie. But Im also lazy and do not like manually reinstalling and configuring things. Basically this is the script I have been using for rebuilding my sandbox when ever I really break things. Its fairly simple and not written very well (sorry beginner at scripting) but it starting by installing all the basic system packages that are required to setup a functioning FFXI server right after the Ubuntu OS install completes. Just copy the below code into a bash script file, give it executable permissions and let it rip.
NOTE: This script assumes you know where you want to store your files (absolute path) and that you are wanting your server accessible from the outside world.
You will be prompted for:
- Your sudoer password (I do not suggest running as root but to each his own, you have been warned).
- The storage path(absolute path).
- The mySQL Root password (Created when the script installs mySQL).
- The desired SQL user name/password that the code will use.
- The name that you want to call your Database.
This script will also download and configure Lucious_Llama's AH scrubber viewtopic.php?f=16&t=2195 because that tool is pimp.
Lastly. .... it will create a file called "ffxi" in your /etc/init.d/ folder that can be used to Start/Stop/Restart everything (including the AH tool). Hopefully someone finds this useful.
Run preview:
NOTE: This script assumes you know where you want to store your files (absolute path) and that you are wanting your server accessible from the outside world.
You will be prompted for:
- Your sudoer password (I do not suggest running as root but to each his own, you have been warned).
- The storage path(absolute path).
- The mySQL Root password (Created when the script installs mySQL).
- The desired SQL user name/password that the code will use.
- The name that you want to call your Database.
This script will also download and configure Lucious_Llama's AH scrubber viewtopic.php?f=16&t=2195 because that tool is pimp.
Lastly. .... it will create a file called "ffxi" in your /etc/init.d/ folder that can be used to Start/Stop/Restart everything (including the AH tool). Hopefully someone finds this useful.
Run preview:
Code: Select all
dev01@sandbox:~$ vim server_setup.sh
dev01@sandbox:~$ chmod +x server_setup.sh
dev01@sandbox:~$ ./server_setup.sh
Where will FFXI be kept?
/home/dev01/ffxi
Creating folders.
Folder created.
Installing and configuring system requirements.
[sudo] password for dev01:
Toolchain test builds; see https://wiki.ubuntu.com/ToolChain
More info: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmp5xcdkxw_/secring.gpg' created
gpg: keyring `/tmp/tmp5xcdkxw_/pubring.gpg' created
gpg: requesting key BA9EF27F from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp5xcdkxw_/trustdb.gpg: trustdb created
gpg: key BA9EF27F: public key "Launchpad Toolchain builds" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
<Insert tons of Ubuntu repository updating stuff>
Fetching Server source code.
Cloning into '/home/dev01/ffxi'...
remote: Counting objects: 161172, done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 161172 (delta 189), reused 148 (delta 148), pack-reused 160932
Receiving objects: 100% (161172/161172), 155.57 MiB | 5.33 MiB/s, done.
Resolving deltas: 100% (115559/115559), done.
Checking connectivity... done.
Source code downloaded. Now compiling the code.Code compile complete.
<Insert tons of Code being compiled stuff>
Cloning into '/home/dev01/ffxi/auctionhouse'...
remote: Counting objects: 2456, done.
Receiving objects: 100% (2456/2456), 1.45 MiB | 0 bytes/s, done.
remote: Total 2456 (delta 0), reused 0 (delta 0), pack-reused 2456
Resolving deltas: 100% (1548/1548), done.
Checking connectivity... done.
Setting SQL Database.
Please enter the mySQL root password (The Password you sued when installing mySQL):
<password>
Please specify a SQL user name:
darkstar
Create a password for darkstar (WARNING: if you use special characters you will have to manually correct the configuration files):
<password>
Name your Database:
dspdb
dev01@sandbox:~$ /etc/init.d/ffxi start
Lobby has Started.
Game has Started.
Search has Started.
Auction House has Started.
dev01@sandbox:~$ screen -ls
There are screens on:
13705.auction (02/08/2016 07:58:57 PM) (Detached)
13703.search (02/08/2016 07:58:57 PM) (Detached)
13701.game (02/08/2016 07:58:57 PM) (Detached)
13699.lobby (02/08/2016 07:58:57 PM) (Detached)
4 Sockets in /var/run/screen/S-dev01.
dev01@sandbox:~$ /etc/init.d/ffxi stop
Lobby has been Shutdown.
Game has been Shutdown.
Search has been Shutdown.
Auction House has been Shutdown.
dev01@sandbox:~$ /etc/init.d/ffxi restart
Lobby has been Shutdown.
Game has been Shutdown.
Search has been Shutdown.
Auction House has been Shutdown.
Lobby has Started.
Game has Started.
Search has Started.
Auction House has Started.
Code: Select all
#!/bin/bash
# User ID
userID=$(id|awk '{print$1}'|cut -d "(" -f2|sed 's/)//')
groupID=$(id|awk '{print$2}'|cut -d "(" -f2|sed 's/)//')
# File Paths
echo 'Where will FFXI be kept? '
read serverCode
# IP Information
publicIP=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com)
# Verify Backup paths exist and create them if they do not.
echo 'Creating folders.'
mkdir $serverCode
echo 'Folder created.'
echo 'Installing and configuring system requirements. '
# installing System requirements
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y python-dev build-essential git mysql-server libmysqlclient-dev libluajit-5.1-dev libzmq3-dev autoconf pkg-config python-pip g++-5 screen
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
sudo pip install sqlalchemy pymysql beautifulsoup4 pyyaml
sudo rm /usr/bin/gcc /usr/bin/g++ /usr/bin/cpp
sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc
sudo ln -s /usr/bin/g++-5 /usr/bin/g++
sudo ln -s /usr/bin/cpp-5 /usr/bin/cpp
# Fetch new code from GIT
echo 'Fetching Server source code.'
git clone http://github.com/DarkstarProject/darkstar.git/ $serverCode/
echo 'Source code downloaded. Now compiling the code.'
# Recompile code
chmod +x $serverCode/autogen.sh
cd $serverCode; ./autogen.sh; ./configure --enable-debug=gdb; make
clear
echo 'Code compile complete.'
git clone https://github.com/AdamGagorik/pydarkstar $serverCode/auctionhouse/
echo 'Setting SQL Database.'
# Data Base Variables
echo 'Please enter the mySQL root password (The Password you sued when installing mySQL): '
read -s rootSqlPassword
echo 'Please specify a SQL user name: '
read dbUser
echo 'Create a password for '$dbUser' (WARNING: if you use special characters you will have to manually correct the configuration files): '
read -s dbPassword
echo 'Name your Database: '
read dbName
# Create Server Database and User
mysql -uroot -p$rootSqlPassword <<MYSQL_SCRIPT
CREATE DATABASE $dbName;
CREATE USER '$dbUser'@'localhost' IDENTIFIED BY '$dbPassword';
GRANT ALL PRIVILEGES ON $dbName .* TO '$dbUser'@'localhost';
FLUSH PRIVILEGES;
EXIT
MYSQL_SCRIPT
# Importing Databases into SQL
cd $serverCode/sql/; for f in $serverCode/sql/*.sql;do mysql $dbName -u $dbUser -p$dbPassword < $f;done
# Setting external IP in Database zone_settings
mysql -u$dbUser -p$dbPassword <<MYSQL_SCRIPT
USE $dbName;
UPDATE zone_settings SET zoneip = $publicIP;
EXIT
MYSQL_SCRIPT
# Updating configuration file
perl -pi -e 's/mysql_login: root/mysql_login: '$dbUser'/g' $serverCode/conf/login_darkstar.conf
perl -pi -e 's/mysql_password: root/mysql_password: '$dbPassword'/g' $serverCode/conf/login_darkstar.conf
perl -pi -e 's/mysql_database: dspdb/mysql_database: '$dbName'/g' $serverCode/conf/login_darkstar.conf
perl -pi -e 's/mysql_login: root/mysql_login: '$dbUser'/g' $serverCode/conf/map_darkstar.conf
perl -pi -e 's/mysql_password: root/mysql_password: '$dbPassword'/g' $serverCode/conf/map_darkstar.conf
perl -pi -e 's/mysql_database: dspdb/mysql_database: '$dbName'/g' $serverCode/conf/map_darkstar.conf
perl -pi -e 's/mysql_login: root/mysql_login: '$dbUser'/g' $serverCode/conf/search_server.conf
perl -pi -e 's/mysql_password: root/mysql_password: '$dbPassword'/g' $serverCode/conf/search_server.conf
perl -pi -e 's/mysql_database: dspdb/mysql_database: '$dbName'/g' $serverCode/conf/search_server.conf
perl -pi -e 's/ map_config.mysql_login = "root";/ map_config.mysql_login = "'$dbUser'";/g' $serverCode/src/map/map.cpp
perl -pi -e 's/ map_config.mysql_password = "root";/ map_config.mysql_password = "'$dbPassword'";/g' $serverCode/src/map/map.cpp
perl -pi -e 's/ map_config.mysql_database = "dspdb";/ map_config.mysql_database = "'$dbName'";/g' $serverCode/src/map/map.cpp
perl -pi -e 's/ search_config.mysql_login = "root";/ search_config.mysql_login = "'$dbUser'";/g' $serverCode/src/search/search.cpp
perl -pi -e 's/ search_config.mysql_password = "root";/ search_config.mysql_password = "'$dbPassword'";/g' $serverCode/src/search/search.cpp
perl -pi -e 's/ search_config.mysql_database = "dspdb";/ search_config.mysql_database = "'$dbName'";/g' $serverCode/src/search/search.cpp
perl -pi -e 's/database: dspdb/database: '$dbName'/g' $serverCode/auctionhouse/bin/config.yaml
perl -pi -e 's/username: root/username: '$dbUser'/g' $serverCode/auctionhouse/bin/config.yaml
perl -pi -e 's/password: \?\?\?\?/password: '$dbPassword'/g' $serverCode/auctionhouse/bin/config.yaml
# Populate AH
chmod +x $serverCode/auctionhouse/bin/*.py
$serverCode/auctionhouse/bin/./scrub.py
$serverCode/auctionhouse/bin/./refill.py
# Create Start/Stop/Restart script
sudo touch /etc/init.d/ffxi;sudo chown $userID:$groupID /etc/init.d/ffxi;sudo chmod 755 /etc/init.d/ffxi
echo -e "#!/bin/bash\nFF_DIR='"$serverCode"'\ncase \"\$1\" in\n start)\n cd \$FF_DIR/\n /usr/bin/screen -dmS lobby \$FF_DIR/dsconnect\n echo 'Lobby has Started.'\n /usr/bin/screen -dmS game \$FF_DIR/dsgame\n echo 'Game has Started.'\n /usr/bin/screen -dmS search \$FF_DIR/dssearch\n echo 'Search has Started.'\n cd \$FF_DIR/auctionhouse/bin/\n /usr/bin/screen -dmS auction \$FF_DIR/auctionhouse/bin/broker.py\n echo 'Auction House has Started.'\n ;;\n stop)\n /usr/bin/screen -XS lobby quit\n echo 'Lobby has been Shutdown.'\n /usr/bin/screen -XS game quit\n echo 'Game has been Shutdown.'\n /usr/bin/screen -XS search quit\n echo 'Search has been Shutdown.'\n /usr/bin/screen -XS auction quit\n echo 'Auction House has been Shutdown.'\n ;;\n restart)\n /usr/bin/screen -XS lobby quit\n echo 'Lobby has been Shutdown.'\n /usr/bin/screen -XS game quit\n echo 'Game has been Shutdown.'\n /usr/bin/screen -XS search quit\n echo 'Search has been Shutdown.'\n /usr/bin/screen -XS auction quit\n echo 'Auction House has been Shutdown.'\n sleep 30\n cd \$FF_DIR/\n /usr/bin/screen -dmS lobby \$FF_DIR/dsconnect\n echo 'Lobby has Started.'\n /usr/bin/screen -dmS game \$FF_DIR/dsgame\n echo 'Game has Started.'\n /usr/bin/screen -dmS search \$FF_DIR/dssearch\n echo 'Search has Started.'\n cd \$FF_DIR/auctionhouse/bin/\n /usr/bin/screen -dmS auction \$FF_DIR/auctionhouse/bin/broker.py\n echo 'Auction House has Started.'\n ;;\n *)\n echo \"Usage: FFXI-Server {start|stop|restart}\" >&2\n exit 3\n ;;\nesac" > /etc/init.d/ffxi