From 78dbd3690c372240f624bc5a33b423970249d272 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 8 Feb 2018 15:03:18 +0100 Subject: [PATCH] Beautify startup Signed-off-by: Knut Ahlers --- Dockerfile | 3 +-- start.sh | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6840b86..e6e9b7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,5 +21,4 @@ ADD sshd_config /etc/ssh/sshd_config VOLUME ["/data", "/ssh"] EXPOSE 22 -ENTRYPOINT ["/usr/local/bin/dumb-init"] -CMD ["/usr/local/bin/start.sh"] +ENTRYPOINT ["/usr/local/bin/start.sh"] diff --git a/start.sh b/start.sh index ecacd67..ef719f5 100755 --- a/start.sh +++ b/start.sh @@ -1,21 +1,38 @@ -#!/bin/bash +#!/usr/local/bin/dumb-init /bin/bash set -euo pipefail +COLOR_CYAN="\033[0;36m" +COLOR_PLAIN="\033[0m" + +function info { + echo -e "${COLOR_CYAN}$@${COLOR_PLAIN}" +} + +function step { + info "[$(date +%H:%M:%S)] $@" +} + +step "Checking SSH host keys..." for type in rsa dsa ecdsa ed25519; do if ! [ -e "/ssh/ssh_host_${type}_key" ]; then - echo "/ssh/ssh_host_${type}_key not found, generating..." - ssh-keygen -f "/ssh/ssh_host_${type}_key" -N '' -t ${type} + info "Generating /ssh/ssh_host_${type}_key..." + ssh-keygen -f "/ssh/ssh_host_${type}_key" -N '' -t ${type} 2>&1 >/dev/null fi ln -sf "/ssh/ssh_host_${type}_key" "/etc/ssh/ssh_host_${type}_key" done -if ( id ${USER} ); then - echo "INFO: User ${USER} already exists" +step "Checking user for existence..." +if ( id ${USER} 2>/dev/null ); then + info "INFO: User ${USER} already exists" else - echo "INFO: User ${USER} does not exists, we create it" + info "INFO: User ${USER} does not exists, we create it" ENC_PASS=$(echo ${PASS} | openssl passwd -1 -stdin) useradd -d /data -m -p ${ENC_PASS} -u ${USER_UID} -s /bin/sh ${USER} + echo + info "User \"${USER}\" created with password \"${PASS}\"." + echo fi +step "Running SSHd..." exec /usr/sbin/sshd -D