review suggestions

pull/140/head
Muhammad Atif Ali 1 year ago
parent 741ac76a79
commit fa95715f96

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env bash
# Convert all templated variables to shell variables # Convert all templated variables to shell variables
INSTALL_VERSION=${INSTALL_VERSION} INSTALL_VERSION=${INSTALL_VERSION}
@ -31,57 +31,65 @@ unzip() {
fi fi
} }
# Fetch the latest version of Vault if INSTALL_VERSION is 'latest' install() {
if [ "$${INSTALL_VERSION}" = "latest" ]; then # Fetch the latest version of Vault if INSTALL_VERSION is 'latest'
LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -oP 'vault/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1) if [ "$${INSTALL_VERSION}" = "latest" ]; then
printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}" LATEST_VERSION=$(curl -s https://releases.hashicorp.com/vault/ | grep -oP 'vault/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1)
if [ -z "$${LATEST_VERSION}" ]; then printf "Latest version of Vault is %s.\n\n" "$${LATEST_VERSION}"
printf "Failed to determine the latest Vault version.\n" if [ -z "$${LATEST_VERSION}" ]; then
exit 1 printf "Failed to determine the latest Vault version.\n"
return 1
fi
INSTALL_VERSION=$${LATEST_VERSION}
fi fi
VERSION=$${LATEST_VERSION}
fi
# Check if the vault CLI is installed and has the correct version # Check if the vault CLI is installed and has the correct version
installation_needed=1 installation_needed=1
if command -v vault > /dev/null 2>&1; then if command -v vault > /dev/null 2>&1; then
CURRENT_VERSION=$(vault version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') CURRENT_VERSION=$(vault version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [ "$${CURRENT_VERSION}" = "$${INSTALL_VERSION}" ]; then if [ "$${CURRENT_VERSION}" = "$${INSTALL_VERSION}" ]; then
printf "Vault version %s is already installed and up-to-date.\n\n" "$${CURRENT_VERSION}" printf "Vault version %s is already installed and up-to-date.\n\n" "$${CURRENT_VERSION}"
installation_needed=0 installation_needed=0
fi
fi fi
fi
if [ $${installation_needed} -eq 1 ]; then if [ $${installation_needed} -eq 1 ]; then
# Download and install Vault # Download and install Vault
if [ -z "$${CURRENT_VERSION}" ]; then if [ -z "$${CURRENT_VERSION}" ]; then
printf "Installing Vault CLI ...\n\n" printf "Installing Vault CLI ...\n\n"
else else
printf "Upgrading Vault CLI from version %s to %s ...\n\n" "$${CURRENT_VERSION}" "$${VERSION}" printf "Upgrading Vault CLI from version %s to %s ...\n\n" "$${CURRENT_VERSION}" "${INSTALL_VERSION}"
fi fi
fetch vault.zip "https://releases.hashicorp.com/vault/$${VERSION}/vault_$${VERSION}_linux_amd64.zip" fetch vault.zip "https://releases.hashicorp.com/vault/$${INSTALL_VERSION}/vault_$${INSTALL_VERSION}_linux_amd64.zip"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
printf "Failed to download Vault.\n" printf "Failed to download Vault.\n"
exit 1 return 1
fi fi
unzip vault.zip if ! unzip_safe vault.zip; then
if [ $? -ne 0 ]; then printf "Failed to unzip Vault.\n"
printf "Failed to unzip Vault.\n" return 1
exit 1 fi
fi rm vault.zip
rm vault.zip if sudo mv vault /usr/local/bin/vault 2> /dev/null; then
if sudo mv vault /usr/local/bin/vault 2> /dev/null; then printf "Vault installed successfully!\n\n"
printf "Vault installed successfully!\n\n" else
else mkdir -p ~/.local/bin
mkdir -p ~/.local/bin if ! mv vault ~/.local/bin/vault; then
mv vault ~/.local/bin/vault printf "Failed to move Vault to local bin.\n"
if [ ! -f ~/.local/bin/vault ]; then return 1
printf "Failed to move Vault to local bin.\n" fi
exit 1 printf "Please add ~/.local/bin to your PATH to use vault CLI.\n"
fi fi
printf "Please add ~/.local/bin to your PATH to use vault CLI.\n"
fi fi
}
TMP=$(mktemp -d)
pushd "${TMP}" > /dev/null
if ! install; then
printf "Installation failed\n"
fi fi
popd > /dev/null
rm -rf "${TMP}"
# Authenticate with Vault # Authenticate with Vault
printf "🔑 Authenticating with Vault ...\n\n" printf "🔑 Authenticating with Vault ...\n\n"

Loading…
Cancel
Save