-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
54 lines (46 loc) · 1.43 KB
/
Copy pathinstall.sh
File metadata and controls
54 lines (46 loc) · 1.43 KB
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
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
#
# Install the Exercism CLI tool
# https://github.com/exercism/cli
#
# Dependencies: curl, cut
#
# Environment:
# - VERSION: The version to install [default: latest].
# - DESTDIR: The destination of the executable [default: /usr/local/bin/].
# - OS: [default: linux]
# - ARCH: [default: x86_64]
set -e
GITHUB_BASE_URL="https://github.com/exercism/cli"
LATEST_URL="${GITHUB_BASE_URL}/releases/latest/"
DESTDIR="${DESTDIR:-/usr/local/bin}"
OS="${OS:-linux}"
ARCH="${ARCH:-x86_64}"
apt_get_update()
{
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
}
export DEBIAN_FRONTEND=noninteractive
check_packages curl ca-certificates
if [[ -z "$VERSION" ]] || [[ "$VERSION" = "latest" ]]; then {
VERSION=$(curl -sLI -o /dev/null -w '%{url_effective}' "$LATEST_URL" | cut -d "v" -f 2)
} fi
echo "Installing exercism-cli: v${VERSION}"
RELEASE_URL="${GITHUB_BASE_URL}/releases/download/v${VERSION}/exercism-${VERSION}-${OS}-${ARCH}.tar.gz"
DOWNLOAD_DIR=$(mktemp -d || mktemp -d -t 'tmp')
pushd "$DOWNLOAD_DIR"
curl -sL --retry 3 "$RELEASE_URL" | tar -xz
echo "Installing to $DESTDIR"
install exercism "$DESTDIR"
popd
rm -r "$DOWNLOAD_DIR"