Files
GPU-Node/ssh/entrypoint.sh
2026-10-11 10:11:42 +04:00

87 lines
1.9 KiB
Bash

#!/bin/sh
set -eu
# ------------------------------------------------------------
# Configuration
# ------------------------------------------------------------
HOST_PROJECT_PATH="${HOST_PROJECT_PATH:-}"
SSH_ROLE="${SSH_ROLE:-}"
SSH_PORT="${SSH_PORT:-22}"
if [ -z "$HOST_PROJECT_PATH" ]; then
echo "ERROR: HOST_PROJECT_PATH is not set." >&2
exit 1
fi
if [ -z "$SSH_ROLE" ]; then
echo "ERROR: SSH_ROLE is not set." >&2
exit 1
fi
case "$SSH_ROLE" in
main)
EXPECTED_PORT="22"
;;
companion)
EXPECTED_PORT="2222"
;;
*)
echo "ERROR: unknown SSH_ROLE: $SSH_ROLE" >&2
echo "Expected: main or companion" >&2
exit 1
;;
esac
# ------------------------------------------------------------
# SSH authorized keys
# ------------------------------------------------------------
cp /project/ssh/authorized_keys /home/operator/.ssh/authorized_keys
chown -R operator:operator /home/operator/.ssh
chmod 700 /home/operator/.ssh
chmod 600 /home/operator/.ssh/authorized_keys
# ------------------------------------------------------------
# Interactive shell environment
# ------------------------------------------------------------
cat > /etc/profile.d/gpu-node.sh <<EOF
export HOST_PROJECT_PATH='$HOST_PROJECT_PATH'
export SSH_ROLE='$SSH_ROLE'
export SSH_PORT='$SSH_PORT'
EOF
chmod 644 /etc/profile.d/gpu-node.sh
# ------------------------------------------------------------
# Export for processes started by sshd
# ------------------------------------------------------------
export HOST_PROJECT_PATH
export SSH_ROLE
export SSH_PORT
echo "SSH role: $SSH_ROLE"
echo "Host project path: $HOST_PROJECT_PATH"
echo "SSH port: $SSH_PORT"
# ------------------------------------------------------------
# Start SSH
# ------------------------------------------------------------
exec /usr/sbin/sshd -D -e -p "$SSH_PORT"