#Download base image
FROM ubuntu:latest

# Install and update software
RUN set -xe \
	&& apt-get update \
	&& apt-get upgrade -y \
	# SSHD install
	&& apt-get install --no-install-recommends -y openssh-server sudo \
	# Piscal reqs
	&& apt-get install make -y \
	&& apt-get install xutils-dev -y \
	&& apt-get install gfortran -y \
	&& apt-get install libopenmpi-dev -y \
	# utils
	&& apt-get install iproute2 -y \
	&& apt-get install vim -y \
	# cleanup
	&& apt-get autoclean -y \
	&& apt-get autoremove -y

# configure sshd, copied from wataken44/ubuntu-latest-sshd
RUN set -xe \
    && groupadd launcher \
    && useradd -g launcher -G sudo -m -s /bin/bash launcher \
    && echo 'launcher:launcher' | chpasswd

RUN set -xe \
    && sed -i -e 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config \
    && sed -i -e 's/UsePAM yes/UsePAM no/g' /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 set -xe \
    && chown -R launcher:launcher /home/launcher 

# fix for SSHD - "Missing privilege separation directory: /run/sshd"
RUN set -xe \
    && mkdir /run/sshd

##### add user l2g
# RUN set -xe \
#     && groupadd l2g \
#     && useradd -g l2g -G sudo -m -s /bin/bash l2g \
#     && echo 'l2g:pwdpwd' | chpasswd
# RUN set -xe \
#     && chown -R l2g:l2g /home/l2g 
# RUN set -xe \
# 	&& apt-get install nano
#####

ADD piscal-manager /srv
ADD leafres/testrun/piscal /srv
#RUN chmod R +x /srv/*.sh
WORKDIR /srv

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
