FROM ubuntu:16.04
RUN apt update && apt install -y build-essential sudo ocaml automake autoconf libtool wget python libssl-dev git protobuf-compiler libprotobuf-dev cmake curl libcurl4-openssl-dev lsb-release debhelper unzip nano kmod nasm vim
WORKDIR /pir/

RUN git clone https://github.com/intel/linux-sgx.git
WORKDIR linux-sgx
RUN git checkout sgx_2.1.3
RUN ./download_prebuilt.sh #Apparently need to run this even if we use opensource libraries - issue #363
RUN make 
RUN make sdk_install_pkg
RUN make psw_install_pkg
WORKDIR linux/installer/bin
RUN echo -e "no\n/opt/intel" | ./sgx_linux_x64_sdk_*.bin
RUN echo -e "no\n/opt/intel" | ./sgx_linux_x64_psw_*.bin

WORKDIR /pir/
COPY ZT.tar.gz /pir/
RUN tar -xf ZT.tar.gz
RUN cp start-aesmd /usr/local/sbin/

RUN git clone https://github.com/openssl/openssl.git OpenSSL_1.1.1d && \
	cd OpenSSL_1.1.1d && git checkout tags/OpenSSL_1_1_1d && \
	cd ../ && tar -cf OpenSSL_1.1.1d.tar.gz OpenSSL_1.1.1d/

#Setting up SGXSSL with the version of OpenSSL that we downloaded in the previous step.
RUN git clone https://github.com/intel/intel-sgx-ssl.git && \
	cd intel-sgx-ssl && git checkout tags/lin_2.5_1.1.1d && \
	cp ../OpenSSL_1.1.1d.tar.gz ./openssl_source/  && \
	cd Linux &&  make && make install

RUN cp /opt/intel/sgxssl/lib64/* /opt/intel/sgxsdk/lib64/
RUN git clone https://github.com/sshsshy/ZeroTrace.git
RUN cd ZeroTrace && make clean && make
