mirror of
https://github.com/luzifer-docker/sftp-share.git
synced 2024-11-09 11:40:02 +00:00
Beautify startup
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
75a463a81c
commit
78dbd3690c
2 changed files with 24 additions and 8 deletions
|
@ -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"]
|
||||
|
|
29
start.sh
29
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
|
||||
|
|
Loading…
Reference in a new issue