From 73d2440ad4107b07505bbd24baafdb718b9753ff Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 8 Oct 2020 07:25:59 +0000 Subject: [PATCH] Add wrapper script for selecting the right deployment key See https://www.webfactory.de/blog/using-multiple-ssh-deploy-keys-with-github. --- wrapper/ssh-deploy-key-wrapper.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 wrapper/ssh-deploy-key-wrapper.sh diff --git a/wrapper/ssh-deploy-key-wrapper.sh b/wrapper/ssh-deploy-key-wrapper.sh new file mode 100644 index 0000000..06da0db --- /dev/null +++ b/wrapper/ssh-deploy-key-wrapper.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# The last argument is the command to be executed on the remote end, which is something +# like "git-upload-pack 'webfactory/ssh-agent.git'". We need the repo path only, so we +# loop over this last argument to get the last part of if. +for last in ${!#}; do :; done + +# Don't use "exec" to run "ssh" below; then the trap won't work. +key_file=$(mktemp -u) +trap "rm -f $key_file" EXIT + +eval last=$last + +# Try to pick the right key +ssh-add -L | grep --word-regexp --max-count=1 $last > $key_file + +ssh -i $key_file "$@" \ No newline at end of file