From 15f9ffab3a27750e69152009fe721b2e1828a8a3 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 6 Mar 2025 13:10:10 +0100 Subject: with-ssh: init --- pkgs/shell/with-ssh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 pkgs/shell/with-ssh 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 -- cgit v1.2.3