-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vendor load-singlesshagent.sh script #409
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8e5d79
Vendor load-singlesshagent.sh
danielhollas d9702d7
Enable aiidalab CLI autocompletion
danielhollas 42d9a34
Remove spurious message when ssh-agent is not running
danielhollas 378cfa8
Fix path
danielhollas ebb4046
bl22441 ->
danielhollas 9f9a9af
f-jason: change launch order for sshagent
unkcpz dad0f82
f-dd
unkcpz eefe86a
redirect 1 & 2 properly
unkcpz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Make sure you source this script rather than executing it | ||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]] | ||
then | ||
echo "You need to source this script, stopping." >&2 | ||
exit 1 | ||
fi | ||
|
||
# run as | ||
# source load-singlesshagent.sh -v | ||
# for verbose output | ||
|
||
load_singlesshagent() { | ||
local VERBOSE | ||
local SSH_ENV | ||
local SSH_ADD_OUTPUT | ||
local SSHADD_RETVAL | ||
local NUMKEYS | ||
|
||
VERBOSE=false | ||
if [ "$1" == "-v" ] | ||
then | ||
VERBOSE=true | ||
fi | ||
|
||
[ "$VERBOSE" == "true" ] && echo "Single SSH agent script [verbose mode]" >&2 | ||
SSH_ENV="$HOME/.ssh/agent-environment" | ||
# Source SSH settings, if applicable | ||
if [ -r "${SSH_ENV}" ]; then | ||
# don't show the output of this source command | ||
source "${SSH_ENV}" 1> /dev/null | ||
[ "$VERBOSE" == "true" ] && echo "- sourcing existing environment" >&2 | ||
else | ||
[ "$VERBOSE" == "true" ] && echo "- no existing environment to source" >&2 | ||
fi | ||
|
||
SSH_ADD_OUTPUT=`ssh-add -l 2> /dev/null` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unkcpz here's the small change to get rid of spurious errors.. Note that it is okay to redirect error to dev/null here since we check the return value of this |
||
# Needed, the later 'test' calls will replace this | ||
SSHADD_RETVAL="$?" | ||
# Error code: 0: there are keys; 1: there are no keys; 2: cannot contact agent | ||
if [ "$SSHADD_RETVAL" == "2" ] | ||
then | ||
[ "$VERBOSE" == "true" ] && echo " - unable to contact agent, creating a new one" >&2 | ||
(umask 066; ssh-agent > ${SSH_ENV}) | ||
source "${SSH_ENV}" 2> /dev/null | ||
elif [ "$SSHADD_RETVAL" == "1" ] | ||
then | ||
[ "$VERBOSE" == "true" ] && echo " - ssh-agent found (${SSH_AGENT_PID}), no keys (I might want to add keys here)" >&2 | ||
# run ssh-add to add the default generate key `id_rsa` to the agent | ||
ssh-add ~/.ssh/id_rsa 2> /dev/null | ||
elif [ "$SSHADD_RETVAL" == "0" ] | ||
then | ||
NUMKEYS=`echo "$SSH_ADD_OUTPUT" | wc -l` | ||
[ "$VERBOSE" == "true" ] && echo " - ssh-agent found (${SSH_AGENT_PID}) with $NUMKEYS keys" >&2 | ||
else | ||
[ "$VERBOSE" == "true" ] && echo " - ssh-add replied with return code $SSHADD_RETVAL - I don't know what to do..." >&2 | ||
fi | ||
|
||
[ "$VERBOSE" == "true" ] && echo "- Debugging, listing all ssh-agents for user $NB_USER:" | ||
[ "$VERBOSE" == "true" ] && ps -U "$NB_USER" | grep --color=no '[s]sh-agent' | ||
} | ||
|
||
# Run with the requested verbosity | ||
if [ "$1" == "-v" ] | ||
then | ||
load_singlesshagent -v | ||
else | ||
load_singlesshagent | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion, I think we should source the
load-singlesshagent.sh
script here. Otherwise I don't think the ssh-agent will be running when the container starts, since .bashrc is not evaluated AFAIK.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! I think the one of the ssh-agent mentioned in aiidalab/aiidalab-mfa-cscs#6 is from here!
I agree to source the
load-singlesshagent.sh
here. It avoids the duplicatessh-agent
I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, interesting. That would mean that it is started somewhere else before we get to this script. Maybe the Jupyter image that we use already starts it somewhere. In any case, source the script here is the right thing to do I think.