Files
Cloud-Tour-to-Libo/deploy/dbeaver-gateway/entrypoint.sh
T

43 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -eu
access_dir=/var/lib/travel-kg/dbeaver-access
host_key_dir=/etc/ssh/host-keys
mkdir -p "${access_dir}" "${host_key_dir}" /run/sshd
touch "${access_dir}/authorized_keys"
chown -R 10001:10001 "${access_dir}"
chmod 0700 "${access_dir}"
chmod 0600 "${access_dir}/authorized_keys"
if [ ! -s "${host_key_dir}/ssh_host_ed25519_key" ]; then
ssh-keygen -q -t ed25519 -N '' -f "${host_key_dir}/ssh_host_ed25519_key"
fi
if [ ! -s "${host_key_dir}/ssh_host_rsa_key" ]; then
ssh-keygen -q -t rsa -b 3072 -N '' -f "${host_key_dir}/ssh_host_rsa_key"
fi
chmod 0600 "${host_key_dir}"/ssh_host_*_key
ssh-keygen -y -f "${host_key_dir}/ssh_host_ed25519_key" > "${access_dir}/ssh_host_ed25519_key.pub"
chown 10001:10001 "${access_dir}/ssh_host_ed25519_key.pub"
chmod 0644 "${access_dir}/ssh_host_ed25519_key.pub"
socat TCP-LISTEN:3307,bind=127.0.0.1,reuseaddr,fork TCP:mysql:3306 &
socat_pid=$!
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config &
sshd_pid=$!
shutdown() {
kill "${socat_pid}" "${sshd_pid}" 2>/dev/null || true
wait "${socat_pid}" "${sshd_pid}" 2>/dev/null || true
exit 0
}
trap shutdown HUP INT TERM
while kill -0 "${socat_pid}" 2>/dev/null && kill -0 "${sshd_pid}" 2>/dev/null; do
sleep 2
done
kill "${socat_pid}" "${sshd_pid}" 2>/dev/null || true
wait "${socat_pid}" "${sshd_pid}" 2>/dev/null || true
exit 1