#!/bin/sh

set -e

VERSION=2.2.0
RELEASE=precise
ARCH=amd64

BASE=$PWD

apt-get install -y git-core build-essential scons nginx libssl-dev

# Grab the source code.
git clone https://github.com/mongodb/mongo.git
cd mongo
git checkout r$VERSION

# Build it with SSL enabled and mostly statically.
mkdir $BASE/opt
scons install --64 --ssl --release --prefix=$BASE/opt/mongo

# Pack it up.
cd $BASE/opt
tar cjvf mongo-$VERSION-$RELEASE-$ARCH.tgz mongo/bin

# Publish it at nginx's root and enable autoindexing.
rm -rf /usr/share/nginx/www/*
cp mongo-*.tgz /usr/share/nginx/www
sed -i 's/index .*index.html.*/autoindex on;/' /etc/nginx/sites-available/default
