summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpkgs/shell/with-ssh37
1 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/shell/with-ssh b/pkgs/shell/with-ssh
new file mode 100755
index 0000000..65459e2
--- /dev/null
+++ b/pkgs/shell/with-ssh
@@ -0,0 +1,37 @@
+#! /bin/sh
+#!buildShellBin prepend-path=openssh
+#
+# usage: with-ssh [--add[=KEY] ...] [COMMAND [ARGS ...]]
+#
+
+set -efu
+
+case ${WITH_SSH_STAGE-1} in
+ 1)
+ export WITH_SSH_STAGE=2
+ exec ssh-agent "$0" "$@"
+ ;;
+ 2)
+ if test $# = 0; then
+ set -- "$SHELL"
+ fi
+ case "$1" in
+ --add)
+ shift
+ ssh-add
+ exec "$0"
+ ;;
+ --add=*)
+ key=$1; shift
+ key=${key#--add=}
+ ssh-add "$key"
+ exec "$0" "$@"
+ ;;
+ *)
+ exec "$@"
+ esac
+ ;;
+ *)
+ echo "with-ssh: error: bad stage: $WITH_SSH_STAGE" >&2
+ exit 1
+esac