#!/bin/sh
cd `dirname -- $0`
DIR=`pwd`

cd docker

cat > Dockerfile <<DOCKER
FROM debian:jessie
RUN apt-get update
RUN apt-get install -y clang cmake make ccache flex bison libboost-all-dev libssl-dev git-core cgdb subversion vim
RUN groupadd -g `id -g` icinga
RUN useradd -m -u `id -u` -g icinga icinga
WORKDIR /home/icinga
USER icinga
RUN mkdir gdb_printers && cd gdb_printers && svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
RUN git clone https://github.com/ruediger/Boost-Pretty-Printer
RUN mkdir build
ENV HOME /home/icinga
RUN ln -s icinga2/tools/docker/docker/build debug
DOCKER

docker.io build -t icinga2 --rm .

if [ "$1" != "-i" ]; then
	command="/home/icinga/debug"
else
	command="/bin/bash"
fi

mkdir -p ~/.ccache
mkdir -p $DIR/.build
mkdir -p $DIR/config

docker.io run -u `id -u` -v $DIR/..:/home/icinga/icinga2 -v $DIR/.build:/home/icinga/icinga2-build -v ~/.ccache:/home/icinga/.ccache -v $DIR/config:/home/icinga/icinga2-config -t -i --rm icinga2 $command
