# os with ssh
# images
FROM ubuntu:20.04 

ENV DEBIAN_FRONTEND=noninteractive
# package procedure(update&upgrade&install)
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y vim net-tools zip unzip apt-utils iputils-ping wget tar curl language-pack-ko openssh-server openjdk-17-jdk maven mariadb-server python3 python3-venv python3-pip && \
    apt-get install -y libfuse2 libglu1-mesa ibwebkit2gtk-4.0-dev
    #아래 쪽은 prusaSlicer를 위한 library임
# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config

# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# env
RUN echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> /etc/profile && \
    echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile && \
    echo "export LANG=ko_KR.UTF-8" >> /etc/profile && \
    echo "export VENV_HOME=/home/gds/printer/venv/" >> /etc/profile && \
    echo "export PATH=$PATH:$VENV_HOME/bin" >> /etc/profile

#run script folder and copy script
RUN mkdir /service_script
COPY start_service.sh /service_script
COPY setting.sql /service_script
RUN chmod +x /service_script/start_service.sh
COPY PrusaSlicer /usr/bin
RUN chmod a+x /usr/bin/PrusaSlicer

# install nextcloud
RUN apt install -y nginx
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php -y
RUN apt update -y
RUN apt-get install -y \
    php7.4 \
    php7.4-fpm \
    php7.4-mysql \
    php7.4-gd \
    php7.4-curl \
    php7.4-xml \
    php7.4-zip \
    php7.4-mbstring \
    php7.4-bcmath \
    php7.4-gmp \
    php7.4-imagick \
    php7.4-intl
RUN ln -fs /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
    dpkg-reconfigure --frontend noninteractive tzdata

WORKDIR /mnt
RUN mkdir nextcloud
RUN wget https://github.com/nextcloud/server/archive/refs/tags/v23.0.12.zip && \
    unzip v23.0.12.zip -d /mnt/nextcloud && \
    rm -rf v23.0.12.zip && \
    chown -R www-data:www-data nextcloud && \
    chmod -R 755 nextcloud

#package clean unused
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Expose port(SSH,NGINX,DB,FLASK,EMBED WAS)
EXPOSE 22 80 3000 3306 8080 8090 8060 8071

# Run SSH,NGINX,DB,FLASK,EMBED WAS
CMD ["/service_script/start_service.sh"]
