Add ssh-wrapper

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-11-27 12:51:11 +01:00
parent 87b3761c89
commit 5eca0b1c1d
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

40
bin/ssh-key-host Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
set -euo pipefail
source ${HOME}/bin/script_framework.sh
function usage() {
fail "Missing parameters. Usage: $(basename $0) [-k <key>] [-p <port>] -- <host> [ssh-param ...]"
}
KEY_NAME="loki"
PORT="22"
while getopts ":k:p:" o; do
case "${o}" in
k)
KEY_NAME="${OPTARG}"
;;
p)
PORT="${OPTARG}"
;;
*)
usage
;;
esac
done
shift $((OPTIND - 1))
[ $# -lt 1 ] && usage
HOST=${1}
shift
step "Waiting for host to have port ${PORT} opened"
waitfor --log-level=warn -- "nmap -p ${PORT} -Pn -oG - $(echo "${HOST}" | cut -d '@' -f 2) | grep -q ${PORT}/open/tcp"
step "Loading key ${KEY_NAME}"
vault-sshadd "${KEY_NAME}"
step "Executing ssh"
exec ssh -p ${PORT} "${HOST}" "$@"