From 0ea4d26b9230a38ab43eaeb95eddeff08bddd8b0 Mon Sep 17 00:00:00 2001
From: Moritz Beber <m.beber@jacobs-university.de>
Date: Wed, 11 Aug 2010 16:25:21 +0200
Subject: Removed some code redundancies.

---
 ...2009-09-03-working-with-key-passphrases.textile | 23 ++++++++++------------
 1 file changed, 10 insertions(+), 13 deletions(-)

(limited to '_posts/2009-09-03-working-with-key-passphrases.textile')

diff --git a/_posts/2009-09-03-working-with-key-passphrases.textile b/_posts/2009-09-03-working-with-key-passphrases.textile
index 12f74b6..13a2f92 100644
--- a/_posts/2009-09-03-working-with-key-passphrases.textile
+++ b/_posts/2009-09-03-working-with-key-passphrases.textile
@@ -47,11 +47,10 @@ function start_agent {
     chmod 600 $SSH_ENV
     . $SSH_ENV > /dev/null
     ssh-add
-}   
+}
 
-# check for running ssh-agent with proper $SSH_AGENT_PID
-ps -ef | grep $SSH_AGENT_PID | grep -v grep > /dev/null
-if [ $? -eq 0 ]; then
+# test for identities
+function test_identities {
     # test whether standard identities have been added to the agent already
     ssh-add -l | grep "The agent has no identities" > /dev/null
     if [ $? -eq 0 ]; then
@@ -61,21 +60,19 @@ if [ $? -eq 0 ]; then
             start_agent
         fi
     fi 
+}
+
+# check for running ssh-agent with proper $SSH_AGENT_PID
+ps -ef | grep $SSH_AGENT_PID | grep -v grep > /dev/null
+if [ $? -eq 0 ]; then
+    test_identities
 # if $SSH_AGENT_PID is not properly set, we might be able to load one from
 # $SSH_ENV
 else
     . $SSH_ENV > /dev/null
     ps -ef | grep $SSH_AGENT_PID | grep -v grep > /dev/null
     if [ $? -eq 0 ]; then
-        # test whether standard identities have been added to the agent already
-        ssh-add -l | grep "The agent has no identities" > /dev/null
-        if [ $? -eq 0 ]; then
-            ssh-add
-            # $SSH_AUTH_SOCK broken so we start a new proper agent
-            if [ $? -eq 2 ];then
-                start_agent
-            fi
-    fi 
+        test_identities
     else
         start_agent
     fi
-- 
cgit v1.3.1

