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 2, 2023
1 parent 49af780 commit 0a15973
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 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,22 @@ 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
fi
EOF
fi

0 comments on commit 0a15973

Please sign in to comment.