working
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# SSH authorized keys
|
||||
# ------------------------------------------------------------
|
||||
|
||||
cp /mounted-authorized-keys /home/operator/.ssh/authorized_keys
|
||||
|
||||
@@ -7,6 +13,76 @@ chown -R operator:operator /home/operator/.ssh
|
||||
chmod 700 /home/operator/.ssh
|
||||
chmod 600 /home/operator/.ssh/authorized_keys
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 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
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 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"
|
||||
Reference in New Issue
Block a user