FROM ubuntu:20.04

# Install common dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update && \
    apt-get -y install sudo \ 
    apt-utils \
    build-essential \
    openssl \
    clang \
    graphviz-dev \
    git \
    autoconf \
    libgnutls28-dev \
    libssl-dev \
    llvm \
    python3-pip \
    nano \
    net-tools \
    vim \
    gdb \
    wget \
    strace \
    libcap-dev \
    tmux

# Add a new user ubuntu, pass: ubuntu
RUN groupadd ubuntu && \
    useradd -rm -d /home/ubuntu -s /bin/bash -g ubuntu -G sudo -u 1000 ubuntu -p "$(openssl passwd -1 ubuntu)"

# Use ubuntu as default username
USER ubuntu
WORKDIR /home/ubuntu

# Set up aflnet-client
RUN git clone https://github.com/aflnet/aflnet.git && \
    cd aflnet && \
    make clean all && \
    cd llvm_mode && make

ENV WORKDIR="/home/ubuntu/experiments"
ENV AFLNET="/home/ubuntu/aflnet"
ENV PATH="${PATH}:${AFLNET}:/home/ubuntu/.local/bin:${WORKDIR}"

RUN mkdir $WORKDIR

COPY --chown=ubuntu:ubuntu reproduce.patch ${WORKDIR}/reproduce.patch

# Download and compile Live555
RUN cd $WORKDIR && \
    wget https://src.rrz.uni-hamburg.de/files/src/live555/live.2023.05.10.tar.gz && \
    tar -zxvf live.2023.05.10.tar.gz && \
    cd live && \
    patch -p1 < ${WORKDIR}/reproduce.patch && \
    ./genMakefiles linux && \
    make clean all || make all

# Copy multimedia files for reproducing the bug
RUN cd ${WORKDIR}/live/testProgs && \
    cp ${AFLNET}/tutorials/live555/sample_media_sources/*.* ./

COPY --chown=ubuntu:ubuntu uar-setup-client-request ${WORKDIR}/uar-setup-client-request