sshagent 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #### My (demuredemeanor) sub source ssh-agent script
  2. # Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
  3. # https://notabug.org/demure/dotfiles/
  4. # legacy repo http://github.com/demure/dotfiles
  5. # vim:set syntax=sh:
  6. # Add check for key exists first
  7. # Add check -> Y/N for ssh_env existing? might not need, if using __ssh_agent right
  8. ### SSH Agent ### {{{
  9. function __ssh_agent() {
  10. local SSH_ENV="$HOME/.ssh/environment"
  11. local U_CHECK="$(logname)"
  12. logname &>/dev/null
  13. local F_CHECK="$?"
  14. function __start_agent {
  15. echo "Initialising new SSH agent..."
  16. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  17. echo succeeded
  18. chmod 600 "${SSH_ENV}"
  19. . "${SSH_ENV}" > /dev/null
  20. /usr/bin/ssh-add;
  21. }
  22. ## Source SSH settings, if applicable
  23. if [ ${F_CHECK} == 0 ] && { [ "${U_CHECK}" == "${USER}" ] || [ "${U_CHECK}" == "logname: no login name" ] ;}; then
  24. if [ -f "${SSH_ENV}" ]; then
  25. . "${SSH_ENV}" > /dev/null
  26. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  27. __start_agent;
  28. }
  29. else
  30. __start_agent;
  31. fi
  32. fi
  33. }
  34. ### End SSH Agent ### }}}