.sh
Shell
(text/x-sh)
#!/bin/sh
SSH_ORIGINAL_COMMAND=${SSH_ORIGINAL_COMMAND}

USERNAME=$1

# If SSH_ORIGINAL_COMMAND is unset, or empty, this was not invoked by ssh ForceCommand, kill now.
# If USERNAME is unset, this was not invoked by ssh ForceCommand, kill now.
if [ -z ${SSH_ORIGINAL_COMMAND+x} ] 2>/dev/null ||
  [ -n ${SSH_ORIGINAL_COMMAND} ] 2>/dev/null ||
  [ -z ${USERNAME+x} ] 2>/dev/null; then
  printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
  printf '%s\n' "provide interactive shell access."
  exit 128
fi

USERNAME=$1
RES_JSON=$(/usr/bin/ssh_command_node "${USERNAME}")
EXIT=$?

echo "result => (${EXIT})\n-----------\n\n" >> /home/git/ssh_commands.log

COMMAND=$(echo "$RES_JSON" | jq -r '.command')
AUTH_MODE=$(echo "$RES_JSON" | jq -r '.authMode')
GIT_REPO_DIR=$(echo "$RES_JSON" | jq -r '.gitRepositoryDir')

echo "AUTH_MODE: ${AUTH_MODE}" >> /home/git/ssh_commands.log
echo "GIT_REPO_DIR: ${GIT_REPO_DIR}" >> /home/git/ssh_commands.log
echo "ssh_command_node stdout: ${RES_JSON}" >> /home/git/ssh_commands.log
echo "ssh_command_node exit code: ${EXIT}" >> /home/git/ssh_commands.log

if [ "$EXIT" = "0" ]; then
  $COMMAND $GIT_REPO_DIR;
  exit $?
else
  echo "Forbidden access.\n"
  exit 1
fi