FROM phusion/baseimage:0.11

RUN DEBIAN_FRONTEND=noninteractive apt-get update -q -y && apt-get upgrade -q -y
RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install vim net-tools iputils-ping telnet
RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install openvpn
RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install curl build-essential git autoconf libtool pkg-config apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install libtalloc-dev libpcsclite-dev libgnutls28-dev

# libosmocore
RUN cd /root && git clone git://git.osmocom.org/libosmocore.git \
    && cd libosmocore \
    && git checkout 7ab5fc1f3b373fadc644448442b985c12597f8f0 \
    && autoreconf -i \
    && ./configure && make && make install \
    && ldconfig \
    && cd ..

# Osmocom-BB
RUN cd /root && git clone git://git.osmocom.org/osmocom-bb.git \
    && cd osmocom-bb/src \
    && git checkout 9fd173b179b3be252c8146fcca0f433106661ef9 \
    && make virtphy && make layer23

# Copy configs
ADD configs/openvpn /etc/openvpn/

RUN mkdir -p /root/.osmocom/bb
ADD configs/osmocombb/mobile.cfg /root/.osmocom/bb/

# Copy startup script
ADD misc/runphones.sh /runphones.sh
RUN chmod 755 /runphones.sh

CMD ["/runphones.sh"]


#To start stuff manually:
#mknod /dev/net/tun c 10 200
#/usr/sbin/openvpn --cd /etc/openvpn/ --config gsm.conf
#/root/osmocom-bb/src/host/virt_phy/src/virtphy -s /tmp/osmocom_l2.one
#/root/osmocom-bb/src/host/virt_phy/src/virtphy -s /tmp/osmocom_l2.two
#/root/osmocom-bb/src/host/layer23/src/mobile/mobile
#telnet localhost 4247
