mirror of
https://github.com/luzifer-docker/sftp-share.git
synced 2024-12-20 14:01:16 +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"]
|
VOLUME ["/data", "/ssh"]
|
||||||
EXPOSE 22
|
EXPOSE 22
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/dumb-init"]
|
ENTRYPOINT ["/usr/local/bin/start.sh"]
|
||||||
CMD ["/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
|
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
|
for type in rsa dsa ecdsa ed25519; do
|
||||||
if ! [ -e "/ssh/ssh_host_${type}_key" ]; then
|
if ! [ -e "/ssh/ssh_host_${type}_key" ]; then
|
||||||
echo "/ssh/ssh_host_${type}_key not found, generating..."
|
info "Generating /ssh/ssh_host_${type}_key..."
|
||||||
ssh-keygen -f "/ssh/ssh_host_${type}_key" -N '' -t ${type}
|
ssh-keygen -f "/ssh/ssh_host_${type}_key" -N '' -t ${type} 2>&1 >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sf "/ssh/ssh_host_${type}_key" "/etc/ssh/ssh_host_${type}_key"
|
ln -sf "/ssh/ssh_host_${type}_key" "/etc/ssh/ssh_host_${type}_key"
|
||||||
done
|
done
|
||||||
|
|
||||||
if ( id ${USER} ); then
|
step "Checking user for existence..."
|
||||||
echo "INFO: User ${USER} already exists"
|
if ( id ${USER} 2>/dev/null ); then
|
||||||
|
info "INFO: User ${USER} already exists"
|
||||||
else
|
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)
|
ENC_PASS=$(echo ${PASS} | openssl passwd -1 -stdin)
|
||||||
useradd -d /data -m -p ${ENC_PASS} -u ${USER_UID} -s /bin/sh ${USER}
|
useradd -d /data -m -p ${ENC_PASS} -u ${USER_UID} -s /bin/sh ${USER}
|
||||||
|
echo
|
||||||
|
info "User \"${USER}\" created with password \"${PASS}\"."
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
step "Running SSHd..."
|
||||||
exec /usr/sbin/sshd -D
|
exec /usr/sbin/sshd -D
|
||||||
|
|
Loading…
Reference in a new issue