This repository has been archived on 2023-05-08. You can view files and clone it, but cannot push or open issues or pull requests.
tf-debian-vm/files/get_cert.sh

18 lines
444 B
Bash
Raw Permalink Normal View History

2023-04-05 14:48:38 +00:00
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
2023-04-25 15:50:02 +00:00
eval "$(jq -r '@sh "PUBKEY=\(.pubkey) HOST=\(.host) CAHOST=\(.cahost) CASCRIPT=\(.cascript) CAKEY=\(.cakey)"')"
2023-04-05 14:48:38 +00:00
# TODO: Can this be done more eye-pleasingly?
2023-04-21 19:25:33 +00:00
set +e
2023-04-25 16:51:58 +00:00
CERT=$(ssh -o ConnectTimeout=3 -o ConnectionAttempts=1 root@$CAHOST '"'"$CASCRIPT"'" host "'"$CAKEY"'" "'"$PUBKEY"'" "'"$HOST"'".dmz')
2023-04-21 19:25:33 +00:00
retval=$?
set -e
if [ retval -neq 0 ]; then
CERT=""
fi
2023-04-05 14:48:38 +00:00
jq -n --arg cert "$CERT" '{"cert":$cert}'