#!/bin/bash
CONF_LINK=https://dl.dropboxusercontent.com/u/32823955/scripts/nginx_wiki.conf


echo 'Installing software'
sudo apt-get update > /dev/null
sudo apt-get install -y nginx php5 php5-cli php5-fpm php5-mysql mysql-client cloud-guest-utils > /dev/null

DNS_NAME=$(ec2metadata --public-hostname)

sudo rm /ect/nginx/sites-available/default
sudo rm /ect/nginx/sites-enabled/default
echo 'Getting mediawiki'
wget http://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.1.tar.gz
tar -xvzf mediawiki-*.tar.gz > /dev/null
sudo mkdir -p /var/www/html
sudo mv mediawiki-*/* /var/www/html
sudo rm /var/www/html/index.html

sudo sed -i "s/localhost/$DNS_NAME/g" /etc/nginx/sites-available/$DNS_NAME


sudo wget $CONF_LINK -O /etc/nginx/sites-available/$DNS_NAME
sudo ln -s /etc/nginx/sites-available/$DNS_NAME /etc/nginx/sites-enabled/$DNS_NAME
