2016-07-21 13:48:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-05-26 19:15:07 +00:00
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2017-07-06 12:18:45 +00:00
|
|
|
function downloadVaultUserToken {
|
|
|
|
os=$(uname | awk '{print tolower($0)}')
|
|
|
|
curl -sSLfo ${HOME}/bin/vault-user-token \
|
|
|
|
https://github.com/Luzifer/vault-user-token/releases/download/${VAULT_USER_TOKEN_VERSION}/vault-user-token_${os}_amd64
|
|
|
|
chmod 0755 ${HOME}/bin/vault-user-token
|
|
|
|
}
|
|
|
|
|
2017-05-26 19:15:07 +00:00
|
|
|
source ${HOME}/.config/vault-user-token
|
|
|
|
|
2016-07-21 13:48:49 +00:00
|
|
|
if ! (vault token-lookup 1>/dev/null 2>&1); then
|
2017-05-26 19:15:07 +00:00
|
|
|
echo "Vault is not authenticated, trying to authenticate... "
|
|
|
|
|
2017-07-06 12:18:45 +00:00
|
|
|
[ -f ${HOME}/bin/vault-user-token ] || downloadVaultUserToken
|
|
|
|
( test "$(${HOME}/bin/vault-user-token --version)" == "vault-user-token ${VAULT_USER_TOKEN_VERSION}" ) || downloadVaultUserToken
|
2017-05-26 19:15:07 +00:00
|
|
|
|
|
|
|
${HOME}/bin/vault-user-token &
|
2017-05-26 22:09:02 +00:00
|
|
|
VUT=$!
|
|
|
|
|
2017-05-26 21:58:37 +00:00
|
|
|
echo "Waiting for token to become available"
|
|
|
|
while ! [ -f ${HOME}/.vault-token ]; do
|
|
|
|
# Give the program a moment to get a token
|
|
|
|
echo -n .
|
|
|
|
sleep 0.5
|
|
|
|
|
2017-05-26 22:09:02 +00:00
|
|
|
if ! ( kill -0 $VUT ); then
|
2017-05-26 21:58:37 +00:00
|
|
|
echo "vault-user-token exitted, giving up."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo
|
2017-05-26 19:15:07 +00:00
|
|
|
|
|
|
|
if ! (vault token-lookup 1>/dev/null 2>&1); then
|
|
|
|
echo "Vault authentication failed finally"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-07-21 13:48:49 +00:00
|
|
|
fi
|