Skip to content

Commit

Permalink
Merge pull request #41 from CircleCI-Public/updater
Browse files Browse the repository at this point in the history
Add a script to automate the download and install.
  • Loading branch information
marcomorain authored Aug 3, 2018
2 parents 733dbae + 90b63c0 commit 8ba342f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ jobs:
- save_cache:
key: v2-goreleaser-{{ checksum "~/goreleaser_amd64.deb" }}
paths: [~/goreleaser_amd64.deb]
shellcheck:
docker:
- image: nlknguyen/alpine-shellcheck:v0.4.6
steps:
- checkout
- run:
name: Check Scripts
command: |
find . -type f -name '*.sh' -not -path './vendor/*' > /tmp/files.txt
echo "Checking $(cat /tmp/files.txt | wc -l ) files"
cat /tmp/files.txt | xargs -t shellcheck --external-sources
workflows:
version: 2
ci:
jobs:
- shellcheck
- test
- coverage
- lint
Expand All @@ -86,6 +98,7 @@ workflows:
- test
- coverage
- lint
- shellcheck
filters:
branches:
only: master
42 changes: 42 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail

RELEASE_URL="https://api.github.com/repos/CircleCI-Public/circleci-cli/releases/latest"
DEST="/usr/local/bin/circleci"

# Run the script in a temporary directory that we know is empty.
SCRATCH=$(mktemp -d)
cd "$SCRATCH"

function finish {
# Delete the working directory when the install was successful.
rm -r "$SCRATCH"
}

function error {
echo "An error occured installing the tool."
echo "The contents of the directory $SCRATCH have been left in place to help to debug the issue."
}

trap finish EXIT
trap error ERR

echo "Finding latest release."
curl --retry 3 --fail --location --silent --output release.json "$RELEASE_URL"

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

echo -n 'Downloading CircleCI '
grep tag_name release.json | sed -E "$STRIP_JSON_STRING"

grep browser_download_url release.json | sed -E "$STRIP_JSON_STRING" > tarball_urls.txt
grep -i "$(uname)" tarball_urls.txt | xargs curl --retry 3 --fail --location --output circleci.tgz

tar zxvf circleci.tgz --strip 1

echo "Installing to $DEST"
mv circleci $DEST
chmod +x $DEST
command -v circleci

0 comments on commit 8ba342f

Please sign in to comment.