From e3d5a59dcab323b40b836ce4f965080eca407319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 17 Aug 2021 10:49:49 +0200 Subject: bashrc : cleaner ssh-agent script --- bashrc | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/bashrc b/bashrc index ee1ee18..228f49c 100644 --- a/bashrc +++ b/bashrc @@ -134,26 +134,14 @@ function xtract() { } # SSH -SSH_ENV=${HOME}/.ssh/environment -function start_agent { - /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV} - chmod 600 ${SSH_ENV} - . ${SSH_ENV} > /dev/null - # /usr/bin/ssh-add $(ls ~/.ssh/*.pub | sed 's/\.pub.*//g' | tr '\n' ' ') -} -if [ -e "${SSH_ENV}" ] +ssh-add -l &>/dev/null +if [ $? -ne 0 ] then - . ${SSH_ENV} > /dev/null - ps ux | grep ssh-agent$ | grep ${SSH_AGENT_PID} >/dev/null || { - # kill old agents - PIDS=`pidof ssh-agent` - if [ ! -z "${PIDS}" ]; then - for PID in ${PIDS}; do - kill ${PID} 2>/dev/null - done - fi - start_agent; - } -else - start_agent + [ -r ~/.ssh/agent ] && eval "$(<~/.ssh/agent)" >/dev/null + ssh-add -l &>/dev/null + if [ $? -ne 0 ] + then + (umask 066; ssh-agent > ~/.ssh/agent) + eval "$(<~/.ssh/agent)" >/dev/null + fi fi -- cgit v1.1-2-g2b99