diff options
Diffstat (limited to '.local/bin/sshadd')
-rwxr-xr-x | .local/bin/sshadd | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/.local/bin/sshadd b/.local/bin/sshadd new file mode 100755 index 0000000..6fb3b18 --- /dev/null +++ b/.local/bin/sshadd @@ -0,0 +1,17 @@ +#!/bin/sh + +[ -z "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock" +msg=$(ssh-add -L 2>&1) +if [ "$msg" = 'Could not open a connection to authentication agent.' ] || + [ "$msg" = 'Error connecting to agent: No such file or directory' ] || + [ "$msg" = 'Error connecting to agent: Connection refused' ]; then + rm -f "${SSH_AUTH_SOCK}" + ssh-agent -a "${SSH_AUTH_SOCK}" > /dev/null +fi + +private_key="$1" +content="$(cat "$1.pub")" +if [ "$msg" = "The agent has no identities." ] || + [ "${msg#*$content}" = "$msg" ]; then + ssh-add "$private_key" +fi |