#!/bin/sh

export SSHPORT=2200

if [ -f /etc/svc-runner/adm.d/sshd.yaml ] ; then
  SSHPORT=$(sed 's/^\s*port *= *//p;d' /tmp/svc-runner-sshd-info)
  if [ -z "$SSHPORT" ] ; then
    echo "FATAL: Found /tmp/svc-runner-sshd-info but unable to detect ssh port"
    exit 1
  fi
else
  echo "WARNING: No file /tmp/svc-runner-sshd-info, assuming default ssh port 2200"
fi

echo "INFO: ssh-ing to 127.0.0.1:${SSHPORT}"
ssh -p $SSHPORT 127.0.0.1
# 'localhost' can be tricky

RC=$?
if [ "$RC" != "0" ] ; then
  echo "ERROR: ssh to 127.0.0.1:${SSHPORT} seem to have failed with bad exit code ${RC}, please check /etc/svc-runner/sshd.d/authorized_keys."
#else
#  echo "INFO: Back from ssh to 127.0.0.1:${SSHPORT} with good exit code."
fi

exit $RC

