2018-11-27 11:51:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
source ${HOME}/bin/script_framework.sh
|
|
|
|
|
|
|
|
function usage() {
|
2022-10-24 11:02:05 +00:00
|
|
|
fail "Missing parameters. Usage: $(basename $0) [-k <key>] [-p <port>] -- <host> [ssh-param ...]"
|
2018-11-27 11:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KEY_NAME="loki"
|
|
|
|
PORT="22"
|
|
|
|
|
|
|
|
while getopts ":k:p:" o; do
|
2022-10-24 11:02:05 +00:00
|
|
|
case "${o}" in
|
|
|
|
k)
|
|
|
|
KEY_NAME="${OPTARG}"
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
PORT="${OPTARG}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
2018-11-27 11:51:11 +00:00
|
|
|
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"
|
2022-10-24 11:02:05 +00:00
|
|
|
exec env TERM=xterm-color ssh -p ${PORT} "${HOST}" "$@"
|