Skip to content

Commit

Permalink
f-jason: change launch order for sshagent
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 13, 2023
1 parent ebb4046 commit 9f9a9af
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions stack/base/before-notebook.d/10_prepare-home-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ if [[ ! -f /home/${NB_USER}/.bashrc ]]; then
cp /etc/skel/.bashrc /home/${NB_USER}/.bashrc
fi

# Set sshagent by source load-singlesshagent.sh script
# append the command text of source to .bashrc if the script /opt/bin/load-singlesshagen.sh is present
# and the command text is not already present in .bashrc
header="# Load singlesshagent on shell startup."
if [[ -f /opt/bin/load-singlesshagent.sh ]] && ! grep -q "${header}" /home/${NB_USER}/.bashrc; then
cat >> "/home/${NB_USER}/.bashrc" <<- EOF
${header}
if [ -f /opt/bin/load-singlesshagent.sh ]; then
source /opt/bin/load-singlesshagent.sh
fi
EOF
fi

if [[ ! -f /home/${NB_USER}/.profile ]]; then
cp /etc/skel/.profile /home/${NB_USER}/.profile
fi
Expand All @@ -40,12 +26,23 @@ fi
mkdir -p --mode=0700 /home/${NB_USER}/.ssh && \
touch /home/${NB_USER}/.ssh/known_hosts


if [[ ! -f /home/${NB_USER}/.ssh/id_rsa ]]; then
# Generate ssh key that works with `paramiko`
# See: https://aiida.readthedocs.io/projects/aiida-core/en/latest/get_started/computers.html#remote-computer-requirements
ssh-keygen -f /home/${NB_USER}/.ssh/id_rsa -t rsa -b 4096 -m PEM -N ''
fi

# Start the ssh-agent.
eval `ssh-agent`
# Set sshagent by source load-singlesshagent.sh script
# append the command text of source to .bashrc if the script /opt/bin/load-singlesshagen.sh is present
# and the command text is not already present in .bashrc
header="# Load singlesshagent on shell startup."
if [[ -f /opt/bin/load-singlesshagent.sh ]] && ! grep -q "${header}" /home/${NB_USER}/.bashrc; then
cat >> "/home/${NB_USER}/.bashrc" <<- EOF
${header}
if [ -f /opt/bin/load-singlesshagent.sh ]; then
source /opt/bin/load-singlesshagent.sh
ssh-add /home/${NB_USER}/.ssh/id_rsa 2> /dev/null
fi
EOF
fi

0 comments on commit 9f9a9af

Please sign in to comment.