From ded39f9d4fbab01c3e471abc8bd96a5438e65a9f Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Mon, 2 Oct 2023 11:43:19 +0200 Subject: [PATCH] f-jason: change launch order for sshagent --- .../10_prepare-home-config.sh | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/stack/base/before-notebook.d/10_prepare-home-config.sh b/stack/base/before-notebook.d/10_prepare-home-config.sh index 5c7eea9e..567d6659 100644 --- a/stack/base/before-notebook.d/10_prepare-home-config.sh +++ b/stack/base/before-notebook.d/10_prepare-home-config.sh @@ -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 @@ -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