cfg/bin/ssh-key-host
Knut Ahlers 5eca0b1c1d
Add ssh-wrapper
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-11-27 12:51:11 +01:00

40 lines
701 B
Bash
Executable file

#!/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}" "$@"