Files
promenade/tools/g2/lib/ssh.sh
Mark Burnett 986016cb9c Gate: Use ShellCheck to lint scripts
This linting is currently limited to scripts in the new gate.

Change-Id: Id4906af0c8dc1e4b77eb0909d432ba8b6e32f5c4
2017-10-31 10:38:23 -05:00

47 lines
1.0 KiB
Bash

rsync_cmd() {
rsync -e "ssh -F ${SSH_CONFIG_DIR}/config" "${@}"
}
ssh_cmd() {
if [[ ${GATE_DEBUG} = "1" ]]; then
ssh -F "${SSH_CONFIG_DIR}/config" -v "${@}"
else
ssh -F "${SSH_CONFIG_DIR}/config" "${@}"
fi
}
ssh_config_declare() {
log Validating SSH config exists
if [ ! -s "${SSH_CONFIG_DIR}/config" ]; then
log Creating SSH config
env -i \
"SSH_CONFIG_DIR=${SSH_CONFIG_DIR}" \
envsubst < "${TEMPLATE_DIR}/ssh-config.sub" > "${SSH_CONFIG_DIR}/config"
fi
}
ssh_keypair_declare() {
log Validating SSH keypair exists
if [ ! -s "${SSH_CONFIG_DIR}/id_rsa" ]; then
log Generating SSH keypair
ssh-keygen -N '' -f "${SSH_CONFIG_DIR}/id_rsa" &>> "${LOG_FILE}"
fi
}
ssh_load_pubkey() {
cat "${SSH_CONFIG_DIR}/id_rsa.pub"
}
ssh_setup_declare() {
mkdir -p "${SSH_CONFIG_DIR}"
ssh_keypair_declare
ssh_config_declare
}
ssh_wait() {
NAME=${1}
while ! ssh_cmd "${NAME}" /bin/true; do
sleep 0.5
done
}