Better sshroot script
[user/alex/software/my-snippets.git] / sshroot
diff --git a/sshroot b/sshroot
index 75b1f9861a15d7e621302333c47ded6f4d18987c..bac553444711b88ae85fc6c8b4e9722230c260cf 100755 (executable)
--- a/sshroot
+++ b/sshroot
@@ -15,35 +15,42 @@ function with-keys
     exec "$@"
 }
 
-case $1 in
+command="$1"
+shift
+
+case "$command" in
     init)
-        shift;
-        unset SSH_AUTH_SOCK SSH_AGENT_PID
-        echo exec keychain --host "$hostopt-root" $keys
+        echo "Loading default keys (lifetime $lifetime)..."
+        with-keys ssh-add -t $lifetime "$@" $keys
         ;;
     add)
+        echo "Loading keys (lifetime $lifetime):" "$@"
         with-keys ssh-add -t $lifetime "$@"
         ;;
+    list)
+        with-keys ssh-add -l
+        ;;
     destroy)
         with-keys ssh-add -D
         ;;
     shell)
-        HOSTNAME="`hostname` (sshroot)" with-keys $SHELL
+        with-keys $SHELL
         ;;
     ssh)
-        shift
         with-keys ssh -l root "$@"
         ;;
     *)
-        if [ $# = 0 ]; then
+        if [ -z "$command" ]; then
             echo "Usage: $0 init" >&2
             echo "       $0 add" >&2
+            echo "       $0 list" >&2
             echo "       $0 destroy" >&2
             echo "       $0 shell" >&2
             echo "       $0 ssh [args]" >&2
             echo "       $0 [cmd]" >&2
         else
-            with-keys "$@"
+            echo Executing: "$command" "$@"
+            with-keys "$command" "$@"
         fi
         ;;
 esac