Skip to content

Commit

Permalink
Remove Python dependency from install script. (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech authored Mar 12, 2019
1 parent 2d6d548 commit 82d3083
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ By default, the `circleci` app will be installed to the ``/usr/local/bin`` direc
curl -fLSs https://circle.ci/cli | DESTDIR=/opt/bin bash
```

You can also set a specific version of the CLI to install with the `VERSION` environment variable:

```
curl -fLSs https://circle.ci/cli | VERSION=0.1.5222 sudo bash
```


#### Homebrew

Expand Down
43 changes: 28 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/usr/bin/env bash

# Install the CircleCI CLI tool.
# https://github.com/circleci-public/circleci-cli
# https://github.com/CircleCI-Public/circleci-cli
#
# Dependencies: curl, cut
#
# The version to install and the binary location can be passed in via VERSION and DESTDIR respectively.
#

set -o errexit
set -o nounset

echo Installing CircleCI CLI
echo "Starting installation."

RELEASE_URL="https://api.github.com/repos/CircleCI-Public/circleci-cli/releases/latest"
# GitHub's URL for the latest release, will redirect.
LATEST_URL="https://github.com/CircleCI-Public/circleci-cli/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)
fi

echo "Installing CircleCI CLI v${VERSION}"

# Run the script in a temporary directory that we know is empty.
SCRATCH=$(mktemp -d || mktemp -d -t 'tmp')
cd "$SCRATCH"
Expand All @@ -21,19 +33,20 @@ function error {

trap error ERR

echo "Finding latest release."
curl --retry 3 --fail --location --silent --output release.json "$RELEASE_URL"
python -m json.tool release.json > formatted_release.json

STRIP_JSON_STRING='s/.*"([^"]+)".*/\1/'

echo -n 'Downloading CircleCI '
grep tag_name formatted_release.json | sed -E "$STRIP_JSON_STRING"
# 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

grep browser_download_url formatted_release.json | sed -E "$STRIP_JSON_STRING" > tarball_urls.txt
grep -i "$(uname)" tarball_urls.txt | xargs curl --silent --retry 3 --fail --location --output circleci.tgz
RELEASE_URL="https://github.com/CircleCI-Public/circleci-cli/releases/download/v${VERSION}/circleci-cli_${VERSION}_${OS}_amd64.tar.gz"

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

echo "Installing to $DESTDIR"
mv circleci "$DESTDIR"
Expand Down

0 comments on commit 82d3083

Please sign in to comment.