FROM tiryoh/ros-desktop-vnc:noetic
 
ENV DEBCONF_NOWARNINGS=yes
ENV DEBIAN_FRONTEND noninteractive
ENV ROS_PYTHON_VERSION 3
ENV ROS_DISTRO=noetic
SHELL ["/bin/bash", "-c"]


EXPOSE 22 
EXPOSE 10940
EXPOSE 2368/udp
EXPOSE 8308/udp


RUN sed -i 's@archive.ubuntu.com@ftp.jaist.ac.jp/pub/Linux@g' /etc/apt/sources.list

 
RUN apt-get autoclean -y && \
    apt-get clean all -y && \
    apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
    build-essential \
    dkms \
    openssh-server && \
    apt-get -y clean && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir /var/run/sshd && \
    echo 'root:ubuntu' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication/PasswordAuthentication/' /etc/ssh/sshd_config && \
    sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd 


RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install --no-install-recommends -y \
    python3-pip \
    python3-testresources \
    gedit \
    ros-noetic-rosserial \
    ros-noetic-rosserial-arduino \
    ros-noetic-urg-node \
    ros-noetic-joy \
    ros-noetic-teleop-twist-joy \
    ros-noetic-robot-pose-ekf \
    ros-noetic-tf2-sensor-msgs \
    ros-noetic-move-base-msgs \
    libsdl1.2-dev \
    libsdl-image1.2-dev \
    libpcap-dev 
    
   
RUN mkdir -p /home/ubuntu/catkin_ws/src && \
    /bin/bash -c "source /opt/ros/noetic/setup.bash ; cd /home/ubuntu/catkin_ws/src ; catkin_init_workspace" && \
    /bin/bash -c "source /opt/ros/noetic/setup.bash ; cd /home/ubuntu/catkin_ws ; catkin build" && \
    echo "source /home/ubuntu/catkin_ws/devel/setup.bash" >> ~/.bashrc && \
    echo "export ROS_WORKSPACE=/home/ubuntu/catkin_ws" >> ~/.bashrc && \
    echo "alias cm='cd ~/catkin_ws;catkin build'" >> ~/.bashrc && \
    echo "alias cs='cd ~/catkin_ws/src'" >> ~/.bashrc && \
    echo "alias cw='cd ~/catkin_ws'" >> ~/.bashrc


RUN apt-get update && \
    apt-get upgrade -y && \
    cd /home/ubuntu/catkin_ws && \
    catkin clean -y && \
    source /opt/ros/noetic/setup.bash && \
    catkin build && \
    chown -R $USER:$USER $HOME && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*


COPY src /home/ubuntu/catkin_ws/src


RUN pip3 install --upgrade --no-cache-dir pip && \
    pip3 install --no-cache-dir \
    pymodbus \
    numpy-quaternion && \
    python3 -m pip install --upgrade pip && \
    python3 -m pip install --upgrade Pillow && \
    pip install ruamel.yaml && \
    cd /home/ubuntu/catkin_ws/src/ZLAC8015D_python && \
    python3 setup.py install && \
    usermod -a -G dialout $USER


COPY ./startup.sh /startup.sh

COPY ./config/70-sensors.rules /etc/udev/rules.d/70-sensors.rules
