Skip to content

Commit

Permalink
Merge pull request #406 from elreydetoda/patch-1
Browse files Browse the repository at this point in the history
minor optimizations
  • Loading branch information
marcomorain authored May 11, 2020
2 parents 4372c84 + 110a856 commit 4d96a7e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ set -o errexit
echo "Starting installation."

# GitHub's URL for the latest release, will redirect.
LATEST_URL="https://github.com/CircleCI-Public/circleci-cli/releases/latest/"
GITHUB_BASE_URL="https://github.com/CircleCI-Public/circleci-cli"
LATEST_URL="${GITHUB_BASE_URL}/releases/latest/"
DESTDIR="${DESTDIR:-/usr/local/bin}"

if [ -z "$VERSION" ]; then
VERSION=$(curl -sLI -o /dev/null -w '%{url_effective}' $LATEST_URL | cut -d "v" -f 2)
VERSION=$(curl -sLI -o /dev/null -w '%{url_effective}' "$LATEST_URL" | cut -d "v" -f 2)
fi

echo "Installing CircleCI CLI v${VERSION}"
Expand All @@ -34,23 +35,26 @@ function error {
trap error ERR

# Determine release filename. This can be expanded with CPU arch in the future.
if [ "$(uname)" == "Linux" ]; then
OS="linux"
elif [ "$(uname)" == "Darwin" ]; then
OS="darwin"
else
echo "This operating system is not supported."
exit 1
fi

RELEASE_URL="https://github.com/CircleCI-Public/circleci-cli/releases/download/v${VERSION}/circleci-cli_${VERSION}_${OS}_amd64.tar.gz"
case "$(uname)" in
Linux)
OS='linux'
;;
Darwin)
OS='darwin'
;;
*)
echo "This operating system is not supported."
exit 1
;;
esac

RELEASE_URL="${GITHUB_BASE_URL}/releases/download/v${VERSION}/circleci-cli_${VERSION}_${OS}_amd64.tar.gz"

# Download & unpack the release tarball.
curl -sL --retry 3 "${RELEASE_URL}" | tar zx --strip 1

echo "Installing to $DESTDIR"
mv circleci "$DESTDIR"
chmod +x "$DESTDIR/circleci"
install circleci "$DESTDIR"

command -v circleci

Expand Down

0 comments on commit 4d96a7e

Please sign in to comment.