SSHct: added init.sh script

This commit is contained in:
Andrey Kartashov 2018-07-21 00:50:48 +07:00
parent 9af4f8e3a7
commit b3d48b0bee
3 changed files with 34 additions and 6 deletions

View file

@ -12,14 +12,16 @@ ENV CTLOCALE ru_RU.UTF-8
ENV PUBKEY none ENV PUBKEY none
RUN apt-get update -y && \ RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openssh-server bash tmux curl sudo less vim \ openssh-server bash tmux curl sudo less vim gnupg ca-certificates \
dialog locales man bash-completion wget apt-file telnet \ dialog locales man bash-completion wget apt-file telnet \
dnsutils git pwgen python bc unzip graphviz whois mysql-client golang-1.8 dnsutils git pwgen python bc unzip graphviz whois mysql-client golang-1.8
ADD sshd_config /etc/ssh/sshd_config ADD sshd_config /etc/ssh/sshd_config
ADD entrypoint.sh /bin/entrypoint ADD entrypoint.sh /bin/entrypoint
RUN chmod +x /bin/entrypoint RUN chmod +x /bin/entrypoint
ADD init.sh /bin/init.sh
RUN chmod +x /bin/init.sh
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
RUN echo '%sudo ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers RUN echo '%sudo ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers

View file

@ -26,10 +26,8 @@ if [ "$PUBKEY" != "none" ]; then
chmod 600 /home/$CTUSER/.ssh/authorized_keys chmod 600 /home/$CTUSER/.ssh/authorized_keys
fi fi
# Install additional packages in background # Run init script in background
if [ -f /home/.packages ]; then tmux new-session -d -s init '/bin/init.sh'
tmux new-session -d -s aptget 'cat /home/.packages | xargs --max-args=1 apt-get install -y'
fi
# start ssh daemon # start ssh daemon
exec /usr/sbin/sshd -Def /etc/ssh/sshd_config exec /usr/sbin/sshd -Def /etc/ssh/sshd_config

28
SSHct/init.sh Normal file
View file

@ -0,0 +1,28 @@
#!/bin/sh
exec >>/home/.init.log 2>&1
echo ====================== INIT START
date
# Install additional packages
echo ====== Installing additional packages
if [ -f /home/.packages ]; then
cat /home/.packages | xargs --max-args=1 apt-get install -y
fi
# Run custom scripts /home/.scripts/*.sh
if [ -d /home/.scripts ]; then
find /home/.scripts -name '*.sh' | while read s; do
if [ -x "$s" ]; then # if script is executable
echo ====== $(date)
echo Running $s
$s <&- # run it with closed stdin, so it does not consume `find` output
else
echo ====== $(date)
echo Skipping non-executable $s
fi
done
fi
echo ====================== INIT END