docker-sshtunnel/entrypoint.sh

51 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
ERROR=0
if [ "${SSH_USER}" = "" ] ; then
echo You must set the SSH_USER environment variable
ERROR=1
fi
if [ "${SSH_HOST}" = "" ] ; then
echo You must set the SSH_HOST environment variable
ERROR=1
fi
if [ "${REMOTE_HOST}" = "" ] ; then
echo You must set the REMOTE_HOST environment variable
ERROR=1
fi
if [ "${REMOTE_PORT}" = "" ] ; then
echo You must set the REMOTE_PORT environment variable
ERROR=1
fi
if [ "${LOCAL_PORT}" = "" ] ; then
echo You must set the LOCAL_PORT environment variable
ERROR=1
fi
SSH_PORT=${SSH_PORT:-22}
SSH_IDENTITY_PATH=${SSH_IDENTITY_PATH:-/id_rsa}
if [ ! -r "${SSH_IDENTITY_PATH}" ] ; then
echo "The specified identity file (${SSH_IDENTITY_PATH}) is not readable"
ERROR=1
fi
if [ "${ERROR}" = "1" ] ; then
echo "Quitting"
exit 1
fi
while true ; do
ssh \
-p ${SSH_PORT} -i ${SSH_IDENTITY_PATH} \
-o StrictHostKeyChecking=no -N \
-L 0.0.0.0:${LOCAL_PORT}:${REMOTE_HOST}:${REMOTE_PORT} \
${SSH_USER}@${SSH_HOST}
echo "Connection closed. Waiting 5 seconds before retry."
sleep 5s
done