#!/bin/sh ERROR=0 # shellcheck disable=2154 # 2154 irrelevant because the ENV variable should come from container invokation if [ "${SSH_USER}" = "" ] ; then echo You must set the SSH_USER environment variable ERROR=1 fi # shellcheck disable=2154 # 2154 irrelevant because the ENV variable should come from container invokation # shellcheck disable=2153 # 2153 irrelevant because SSH_HOST is the correct ENV variable if [ "${SSH_HOST}" = "" ] ; then echo You must set the SSH_HOST environment variable ERROR=1 fi # shellcheck disable=2154 # 2154 irrelevant because the ENV variable should come from container invokation if [ "${REMOTE_HOST}" = "" ] ; then echo You must set the REMOTE_HOST environment variable ERROR=1 fi # shellcheck disable=2154 # 2154 irrelevant because the ENV variable should come from container invokation if [ "${REMOTE_PORT}" = "" ] ; then echo You must set the REMOTE_PORT environment variable ERROR=1 fi # shellcheck disable=2154 # 2154 irrelevant because the ENV variable should come from container invokation 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