Skip to content

Commit

Permalink
support dynamic user config
Browse files Browse the repository at this point in the history
  • Loading branch information
gezp committed Aug 28, 2022
1 parent 2e04451 commit 2cc8a2f
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 44 deletions.
22 changes: 3 additions & 19 deletions ubuntu-desktop/18.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ MAINTAINER zhenpeng ge "https://github.com/gezp"

ENV DEBIAN_FRONTEND=noninteractive
ENV USER=ubuntu \
PASSWD=ubuntu \
PASSWORD=ubuntu \
UID=1000 \
GID=1000 \
TZ=Asia/Shanghai \
LANG=zh_CN.UTF-8 \
LC_ALL=zh_CN.UTF-8 \
LANGUAGE=zh_CN.UTF-8

## Add default user
RUN groupadd $USER && \
useradd --create-home --no-log-init -g $USER $USER && \
usermod -aG sudo $USER && \
echo "$PASSWD:$PASSWD" | chpasswd && \
chsh -s /bin/bash $USER && \
# Replace 1000 with your user/group id
usermod --uid $UID $USER && \
groupmod --gid $GID $USER

## Remove /etc/apt/sources.list.d/*
RUN rm -rf /etc/apt/sources.list.d/*

Expand Down Expand Up @@ -61,15 +51,9 @@ RUN mkdir /var/run/sshd && \
sed -i 's/#*PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config && \
sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd

## Set .bashrc
RUN echo "export PATH=/usr/NX/scripts/vgl:\$PATH" >> /home/$USER/.bashrc

## Copy config
COPY config/xfce4 /home/$USER/.config/xfce4
RUN chown -R $GID:$UID /home/$USER/.config
COPY docker_config /docker_config

EXPOSE 22 4000

COPY nxserver.sh /
RUN chmod +x /nxserver.sh
ENTRYPOINT ["/nxserver.sh"]
ENTRYPOINT ["/docker_config/startup.sh"]
24 changes: 4 additions & 20 deletions ubuntu-desktop/20.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ MAINTAINER zhenpeng ge "https://github.com/gezp"

ENV DEBIAN_FRONTEND=noninteractive
ENV USER=ubuntu \
PASSWD=ubuntu \
PASSWORD=ubuntu \
UID=1000 \
GID=1000 \
TZ=Asia/Shanghai \
LANG=zh_CN.UTF-8 \
LC_ALL=zh_CN.UTF-8 \
LANGUAGE=zh_CN.UTF-8

## Add default user
RUN groupadd $USER && \
useradd --create-home --no-log-init -g $USER $USER && \
usermod -aG sudo $USER && \
echo "$PASSWD:$PASSWD" | chpasswd && \
chsh -s /bin/bash $USER && \
# Replace 1000 with your user/group id
usermod --uid $UID $USER && \
groupmod --gid $GID $USER

## Remove /etc/apt/sources.list.d/*
RUN rm -rf /etc/apt/sources.list.d/*

Expand Down Expand Up @@ -55,21 +45,15 @@ RUN curl -fSL "https://www.nomachine.com/free/linux/64/deb" -o nomachine.deb &&\
sed -i "s|#EnableClipboard both|EnableClipboard both |g" /usr/NX/etc/server.cfg &&\
sed -i '/DefaultDesktopCommand/c\DefaultDesktopCommand "/usr/bin/startxfce4"' /usr/NX/etc/node.cfg

## Configure ssh
## Configure ssh
RUN mkdir /var/run/sshd && \
echo 'root:THEPASSWORDYOUCREATED' | chpasswd && \
sed -i 's/#*PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config && \
sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd

## Set .bashrc
RUN echo "export PATH=/usr/NX/scripts/vgl:\$PATH" >> /home/$USER/.bashrc

## Copy config
COPY config/xfce4 /home/$USER/.config/xfce4
RUN chown -R $GID:$UID /home/$USER/.config
COPY docker_config /docker_config

EXPOSE 22 4000

COPY nxserver.sh /
RUN chmod +x /nxserver.sh
ENTRYPOINT ["/nxserver.sh"]
ENTRYPOINT ["/docker_config/startup.sh"]
4 changes: 4 additions & 0 deletions ubuntu-desktop/docker_config/config_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# update .bashrc
echo "export PATH=/usr/NX/scripts/vgl:\$PATH" >> ~/.bashrc
24 changes: 24 additions & 0 deletions ubuntu-desktop/docker_config/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

## initialize environment
if [ ! -f "/docker_config/init" ]; then
# create user
groupadd -g $GID $USER
useradd --create-home --no-log-init -u $UID -g $GID $USER
usermod -aG sudo $USER
echo "$USER:$PASSWORD" | chpasswd
chsh -s /bin/bash $USER
# copy xfce4 config
mkdir /home/$USER/.config
cp -r /docker_config/xfce4 /home/$USER/.config
chown -R $UID:$GID /home/$USER/.config
# config user
su $USER -s /bin/bash /docker_config/config_user.sh
# update init flag
echo "ok" > /docker_config/init
fi

/usr/sbin/sshd
/etc/init.d/dbus start
/etc/NX/nxserver --startup
tail -f /usr/NX/var/log/nxserver.log
File renamed without changes.
5 changes: 0 additions & 5 deletions ubuntu-desktop/nxserver.sh

This file was deleted.

0 comments on commit 2cc8a2f

Please sign in to comment.