summaryrefslogtreecommitdiff
path: root/.bashrc
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-11-16 06:04:04 +0000
committerMike Crute <mike@crute.us>2020-11-16 06:04:04 +0000
commit1833964946766caa38d1f133b9fbeb472586fb61 (patch)
tree7f3412d8a268c085a6826280fc1b4a67763640b7 /.bashrc
parentca8f009af238852657117873e2536396b15641c9 (diff)
downloaddotfiles-1833964946766caa38d1f133b9fbeb472586fb61.tar.bz2
dotfiles-1833964946766caa38d1f133b9fbeb472586fb61.tar.xz
dotfiles-1833964946766caa38d1f133b9fbeb472586fb61.zip
Add ugly ssh agent check
Diffstat (limited to '.bashrc')
-rw-r--r--.bashrc20
1 files changed, 16 insertions, 4 deletions
diff --git a/.bashrc b/.bashrc
index 15c54fd..9908503 100644
--- a/.bashrc
+++ b/.bashrc
@@ -577,6 +577,17 @@ function tm
577} 577}
578func_export tm 578func_export tm
579 579
580# An ugly check to test for ssh agent liveness. Normally ssh-add should return
581# 2 to indicate that it can't talk to the agent but in older versions of Ubutu
582# the command returns 1 and some text on stderr about not being able to connect
583# to the agent (even though the man page says this should not happen). Thus
584# this ugly hack of a check function.
585function _ssh_agent_is_running
586{
587 output=$(ssh-add 2>&1)
588 [[ $? -ne 2 && ! "$output" =~ "communication with agent failed" ]]
589}
590
580# Start or resume an ssh agent and add keys if needed 591# Start or resume an ssh agent and add keys if needed
581# The -d argument will add keys if needed 592# The -d argument will add keys if needed
582function get_ssh_agent 593function get_ssh_agent
@@ -616,8 +627,7 @@ function get_ssh_agent
616 # probably out of date with our environment file, update it so that 627 # probably out of date with our environment file, update it so that
617 # other sessions in other shells that may not be connected to this 628 # other sessions in other shells that may not be connected to this
618 # X11 session use the same agent. 629 # X11 session use the same agent.
619 ssh-add -l &>/dev/null 630 if _ssh_agent_is_running; then
620 if [[ $? -ne 2 ]]; then
621 echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;" > "$agent_out" 631 echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;" > "$agent_out"
622 echo "SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;" >> "$agent_out" 632 echo "SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;" >> "$agent_out"
623 echo "echo Agent pid ${SSH_AGENT_PID};" >> "$agent_out" 633 echo "echo Agent pid ${SSH_AGENT_PID};" >> "$agent_out"
@@ -628,8 +638,7 @@ function get_ssh_agent
628 # If the agent still isn't connected after sourcing our local agent 638 # If the agent still isn't connected after sourcing our local agent
629 # state file then it probably isn't running at all. Start a new 639 # state file then it probably isn't running at all. Start a new
630 # agent and update the state file. 640 # agent and update the state file.
631 ssh-add -l &>/dev/null 641 if ! _ssh_agent_is_running && [[ -n "$start_agent" ]]; then
632 if [[ $? -eq 2 && -n "$start_agent" ]]; then
633 eval $(ssh-agent | tee "$agent_out") &>/dev/null 642 eval $(ssh-agent | tee "$agent_out") &>/dev/null
634 fi 643 fi
635 644
@@ -727,3 +736,6 @@ done
727 736
728[[ -r ~/.homebrew_github_api_token ]] && export HOMEBREW_GITHUB_API_TOKEN=$(cat ~/.homebrew_github_api_token) 737[[ -r ~/.homebrew_github_api_token ]] && export HOMEBREW_GITHUB_API_TOKEN=$(cat ~/.homebrew_github_api_token)
729[[ -f ~/.bashrc_local ]] && source ~/.bashrc_local 738[[ -f ~/.bashrc_local ]] && source ~/.bashrc_local
739
740# Make sure we can talk to the SSH agent if one is running
741get_ssh_agent