sshroot: better handling of getting keys
authorAlex Dehnert <adehnert@mit.edu>
Fri, 25 Jun 2010 07:51:16 +0000 (03:51 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Fri, 25 Jun 2010 07:51:16 +0000 (03:51 -0400)
* Rename with-keys to with-agent to better reflect what it does
* Make a new with-keys that does the same thing as with-agent, except
  that it passes $keys to keychain so that those keys are actually
  unlocked
* Divide between using with-keys and with-agent more-or-less
  reasonably

sshroot

diff --git a/sshroot b/sshroot
index bac553444711b88ae85fc6c8b4e9722230c260cf..6a0c4b5f6e8d906e1d572c75e54a7e3a2b78adf5 100755 (executable)
--- a/sshroot
+++ b/sshroot
@@ -9,6 +9,13 @@ hostopt=""
 keys=~/.ssh/id_rsa_root
 
 function with-keys
+{
+    unset SSH_AUTH_SOCK SSH_AGENT_PID
+    eval $(keychain --eval --host "$hostopt-root" $keys)
+    exec "$@"
+}
+
+function with-agent
 {
     unset SSH_AUTH_SOCK SSH_AGENT_PID
     eval $(keychain --eval --host "$hostopt-root")
@@ -21,17 +28,17 @@ shift
 case "$command" in
     init)
         echo "Loading default keys (lifetime $lifetime)..."
-        with-keys ssh-add -t $lifetime "$@" $keys
+        with-agent ssh-add -t $lifetime "$@" $keys
         ;;
     add)
         echo "Loading keys (lifetime $lifetime):" "$@"
-        with-keys ssh-add -t $lifetime "$@"
+        with-agent ssh-add -t $lifetime "$@"
         ;;
     list)
-        with-keys ssh-add -l
+        with-agent ssh-add -l
         ;;
     destroy)
-        with-keys ssh-add -D
+        with-agent ssh-add -D
         ;;
     shell)
         with-keys $SHELL
@@ -50,7 +57,7 @@ case "$command" in
             echo "       $0 [cmd]" >&2
         else
             echo Executing: "$command" "$@"
-            with-keys "$command" "$@"
+            with-agent "$command" "$@"
         fi
         ;;
 esac