diff options
author | tv <tv@krebsco.de> | 2025-03-06 13:10:10 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2025-03-06 13:10:10 +0100 |
commit | 15f9ffab3a27750e69152009fe721b2e1828a8a3 (patch) | |
tree | a0513cddf44ff99ce87e81341bce04fdaf804eb9 | |
parent | 6758bf29930ab8d4e7369abaa4ed57b510d9c7a8 (diff) |
with-ssh: init
-rwxr-xr-x | pkgs/shell/with-ssh | 37 |
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 |