#!/usr/bin/env bash

command -v php > /dev/null || {
	echo "can't find PHP binary" >&2
	exit 1
}

echo "Downloading Composer..."
curl -sS https://getcomposer.org/installer | php

echo "Installing dependencies using Composer..."
php composer.phar install

echo "Downloading PHPUnit..."
curl -sS https://phar.phpunit.de/phpunit.phar > phpunit.phar

echo "Downloading Behat..."
curl -sS http://behat.org/downloads/behat.phar > behat.phar

echo "Creating symlink for the wp command..."
for dir in /usr/bin /usr/local/bin; do
	if [ -d $dir ]; then
		sudo ln -sf $(pwd)/bin/wp $dir/wp
		break
	fi
done

echo "Installing bash completion file..."
for dir in /etc/bash_completion.d /usr/local/etc/bash_completion.d; do
	if [ -d $dir ]; then
		sudo ln -sf $(pwd)/utils/wp-completion.bash $dir/wp
		break
	fi
done
