#!/bin/bash
#
# This script fires up a two-server IRC network and runs the test framework
#

# Exit on error:
set -e

# Verbose:
set -x

# Install packages
if [[ "$OSTYPE" == "darwin"* ]]; then
	brew install git || true
	brew install python || true
	gem install bundler || true
	gem install rake || true
	gem install rspec || true
else
	sudo apt-get install git python rake -y
	sudo gem install bundler
fi

# Install 'ircfly'
git clone https://github.com/unrealircd/ircfly.git
cd ircfly
bundle install
bundle exec rake build
if [[ "$OSTYPE" == "darwin"* ]]; then
	bundle exec rake install
else
	sudo rake install
fi
cd ..

# Install 'unrealircd-tests'
git clone https://github.com/unrealircd/unrealircd-tests.git
cd unrealircd-tests
bundle install
mv config.yaml.example config.yaml

# Start the IRC servers
cp ircdconfig/* ~/unrealircd/conf/
cd ~/unrealircd
bin/unrealircd -f irc1.conf
bin/unrealircd -f irc2.conf
cd -

# Back in unrealircd-tests, run the tests!
if [[ "$OSTYPE" == "darwin"* ]]; then
	bundle exec rake
else
	rake
fi
