FROM phusion/baseimage:latest
MAINTAINER Felix Böhm "felix@owncloud.com"

ENV HOME /root
ENV DEBIAN_FRONTEND noninteractive

RUN echo 'deb http://download.opensuse.org/repositories/isv:/ownCloud:/community:/7.0/xUbuntu_14.04/ /' >> /etc/apt/sources.list.d/php5-libsmbclient.list
RUN apt-get -y update && apt-get -y install \
    apache2 \
    libapache2-mod-php5 \
    php5-gd \
    php5-json \
    php5-sqlite \
    php5-curl \
    php5-intl \
    php5-mcrypt \
    php5-imagick \
    bzip2 \
    unzip \
    wget \ 
    smbclient \
    libsmbclient \
    libsmbclient-dev

RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

# Change version file to disable the build cache
ADD version version

# RUN wget --user=owncloud --password=owncloud42 http://download.owncloud.com/internal/7.0.3RC1/owncloud-enterprise.zip
# RUN mv owncloud-enterprise.zip /var/www
# RUN cd /var/www && unzip owncloud-enterprise.zip
# RUN cd /var/www && rm owncloud-enterprise.zip

RUN wget --user=owncloud --password=owncloud42 http://download.owncloud.com/internal/owncloud-daily-enterprise-stable7.tar.bz2
RUN mv owncloud-daily-enterprise-stable7.tar.bz2 /var/www
RUN cd /var/www && tar xf owncloud-daily-enterprise-stable7.tar.bz2
RUN cd /var/www && rm owncloud-daily-enterprise-stable7.tar.bz2

RUN mv /var/www/owncloud/config/ee.config.php /var/www/owncloud/config/ee.config.orig
ADD ./autoconfig.php /var/www/owncloud/config/autoconfig.php
ADD ./ee.config.php /var/www/owncloud/config/ee.config.php
RUN chown -R www-data:www-data /var/www/owncloud

RUN echo export HOME=/var/www >> /etc/apache2/envvars

ADD ./001-owncloud.conf /etc/apache2/sites-available/
RUN rm -f /etc/apache2/sites-enabled/000*
RUN ln -s /etc/apache2/sites-available/001-owncloud.conf /etc/apache2/sites-enabled/
RUN a2enmod rewrite

ADD rc.local /etc/rc.local
RUN chown root:root /etc/rc.local

ADD init_volume.sh /etc/my_init.d/init_volume.sh
RUN chmod +x /etc/my_init.d/init_volume.sh

# RUN apt-get -y --force-yes install php5-libsmbclient
# RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# forward port to the outside world
EXPOSE 80

CMD ["/sbin/my_init"]