forked from CircleCI-Public/circleci-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·45 lines (31 loc) · 1.28 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# Install the CircleCI CLI tool.
# https://github.com/circleci-public/circleci-cli
set -o errexit
set -o nounset
echo Installing CircleCI CLI
RELEASE_URL="https://api.github.com/repos/CircleCI-Public/circleci-cli/releases/latest"
DESTDIR="${DESTDIR:-/usr/local/bin}"
# Run the script in a temporary directory that we know is empty.
SCRATCH=$(mktemp -d)
cd "$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 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"
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
tar zxf circleci.tgz --strip 1
echo "Installing to $DESTDIR"
mv circleci "$DESTDIR"
chmod +x "$DESTDIR/circleci"
command -v circleci
# Delete the working directory when the install was successful.
rm -r "$SCRATCH"