sshroot: use set -e
authorAlex Dehnert <adehnert@mit.edu>
Sat, 15 Dec 2012 13:20:57 +0000 (08:20 -0500)
committerAlex Dehnert <adehnert@mit.edu>
Sat, 15 Dec 2012 13:20:57 +0000 (08:20 -0500)
Also, set -e doesn't cause failures when passing the output of a subshell
directly to eval, so use an intermediate variable instead.

sshroot

diff --git a/sshroot b/sshroot
index 845a04ac249c4c9cefca2027a8bdbad14f25ce39..740b5ef6c38722f993d5cb5b22444b56920dfce9 100755 (executable)
--- a/sshroot
+++ b/sshroot
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -e
 
 # lifetime, in minutes
 lifetime=15
@@ -38,7 +38,8 @@ keychain_host="$hostopt-$keysuffix"
 function with-keys
 {
     unset SSH_AUTH_SOCK SSH_AGENT_PID
-    eval $(keychain --timeout "$lifetime" --eval --host "$keychain_host" $keys)
+    vars=$(keychain --timeout "$lifetime" --eval --host "$keychain_host" $keys)
+    eval "$vars"
     export SSHROOT=1
     exec "$@"
 }
@@ -46,7 +47,8 @@ function with-keys
 function with-agent
 {
     unset SSH_AUTH_SOCK SSH_AGENT_PID
-    eval $(keychain --timeout "$lifetime" --eval --host "$keychain_host")
+    vars=$(keychain --timeout "$lifetime" --eval --host "$keychain_host")
+    eval "$vars"
     export SSHROOT=1
     echo with-agent: Running: "$@"
     exec "$@"