diff --git a/src/commands/install.yml b/src/commands/install.yml index c6c8b3e..2839da3 100755 --- a/src/commands/install.yml +++ b/src/commands/install.yml @@ -61,14 +61,20 @@ steps: echo -e "${OK_COLOR}==> Creating directories${NO_COLOR}" $SUDO mkdir -p /usr/local/secrethub/bin - # Retrieve latest version - if [ -n "${SECRETHUB_CLI_VERSION}" ]; then + if [ "${SECRETHUB_CLI_VERSION:-latest}" != "latest" ]; then VERSION=v${SECRETHUB_CLI_VERSION} else + # Retrieve latest version echo -e "${OK_COLOR}==> Retrieving latest version${NO_COLOR}" VERSION=$(curl --silent "https://api.github.com/repos/secrethub/secrethub-cli/releases/latest" | grep tag_name | awk -F\" '{ print $4 }') fi + # Exit if version is already installed + if command -v secrethub >/dev/null 2>&1 && secrethub --version 2>&1 | cut -d "," -f 1 | grep -q "$(echo $VERSION | cut -c 2-)$"; then + echo -e "${OK_COLOR}==> Version ${VERSION} is already installed${NO_COLOR}" + exit 0 + fi + echo -e "${OK_COLOR}==> Downloading version ${VERSION}${NO_COLOR}" ARCHIVE_NAME=secrethub-$VERSION-$OS-$ARCH LINK_TAR=https://github.com/secrethub/secrethub-cli/releases/download/$VERSION/$ARCHIVE_NAME.tar.gz