From b483e8215fbce8cf68c50d53b680d2da12ac1ddd Mon Sep 17 00:00:00 2001 From: Floris van der Grinten Date: Thu, 30 Apr 2020 16:28:32 +0200 Subject: [PATCH] Check if version is already installed --- src/commands/install.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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