Index: src/scripts/remote_access.sh |
diff --git a/src/scripts/remote_access.sh b/src/scripts/remote_access.sh |
index 8b1a733340fc00303369a67e69b799ef4c5a6fc9..43a64ad1875e8b64fc8bc33f540f84bdfe0820de 100644 |
--- a/src/scripts/remote_access.sh |
+++ b/src/scripts/remote_access.sh |
@@ -25,6 +25,9 @@ function remote_sh_allow_changed_host_key() { |
function set_up_remote_access() { |
if [ -z "$SSH_AGENT_PID" ]; then |
eval $(ssh-agent) |
+ OWN_SSH_AGENT=1 |
+ else |
+ OWN_SSH_AGENT=0 |
fi |
cp $FLAGS_private_key $TMP_PRIVATE_KEY |
chmod 0400 $TMP_PRIVATE_KEY |
@@ -36,6 +39,17 @@ function set_up_remote_access() { |
echo "Connection OK" |
} |
+function cleanup_remote_access() { |
+ # Call this function from the exit trap of the main script. |
+ # Iff we started ssh-agent, be nice and clean it up. |
+ # Note, only works if called from the main script - no subshells. |
+ if [[ 1 -eq ${OWN_SSH_AGENT} ]] |
+ then |
+ kill ${SSH_AGENT_PID} 2>/dev/null |
+ unset SSH_AGENT_PID SSH_AUTH_SOCK |
+ fi |
+} |
+ |
function remote_access_init() { |
TMP_PRIVATE_KEY=$TMP/private_key |
TMP_KNOWN_HOSTS=$TMP/known_hosts |