Skip to content

Commit ad36057

Browse files
ErikSchierboommirkoperillo
authored andcommitted
[v3] Update fetch-configlet script to work with configlet v3
1 parent 41fbf94 commit ad36057

1 file changed

Lines changed: 57 additions & 60 deletions

File tree

bin/fetch-configlet

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
1-
#!/bin/bash
2-
3-
LATEST=https://github.com/exercism/configlet/releases/latest
4-
5-
echo ">>> Fetching configlet..."
6-
echo
7-
echo "$ uname"
8-
uname
9-
10-
OS=$(
11-
case $(uname) in
12-
(Darwin*)
13-
echo "mac";;
14-
(Linux*)
15-
echo "linux";;
16-
(Windows*)
17-
echo "windows";;
18-
(MINGW*)
19-
echo "windows";;
20-
(*)
21-
echo "linux";;
22-
esac)
23-
24-
EXT=$(
25-
case $OS in
26-
(windows*)
27-
echo "zip";;
28-
(*)
29-
echo "tgz";;
30-
esac)
31-
32-
echo "$ uname -m"
33-
uname -m
34-
35-
ARCH=$(
36-
case $(uname -m) in
37-
(*64*)
38-
echo 64bit;;
39-
(*686*)
40-
echo 32bit;;
41-
(*386*)
42-
echo 32bit;;
43-
(*)
44-
echo 64bit;;
45-
esac)
46-
47-
48-
VERSION="$(curl --silent --head $LATEST | awk -v FS=/ 'BEGIN {IGNORECASE = 1} /Location:/{print $NF}' | tr -d '\r')"
49-
URL=https://github.com/exercism/configlet/releases/download/$VERSION/configlet-$OS-${ARCH}.$EXT
50-
51-
echo
52-
echo ">>> Downloading from ${URL}"
53-
54-
case $EXT in
55-
(*zip)
56-
curl -s --location $URL -o bin/latest-configlet.zip
57-
unzip bin/latest-configlet.zip -d bin/
58-
rm bin/latest-configlet.zip;;
59-
(*)
60-
curl -s --location $URL | tar xz -C bin/;;
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
readonly LATEST='https://api.github.com/repos/exercism/configlet/releases/latest'
6+
7+
case "$(uname)" in
8+
Darwin*) os='mac' ;;
9+
Linux*) os='linux' ;;
10+
Windows*) os='windows' ;;
11+
MINGW*) os='windows' ;;
12+
MSYS_NT-*) os='windows' ;;
13+
*) os='linux' ;;
14+
esac
15+
16+
case "${os}" in
17+
windows*) ext='zip' ;;
18+
*) ext='tgz' ;;
6119
esac
20+
21+
case "$(uname -m)" in
22+
*64*) arch='64bit' ;;
23+
*686*) arch='32bit' ;;
24+
*386*) arch='32bit' ;;
25+
*) arch='64bit' ;;
26+
esac
27+
28+
curlopts=(
29+
--silent
30+
--show-error
31+
--fail
32+
--location
33+
--retry 3
34+
)
35+
36+
if [[ -n "${GITHUB_TOKEN}" ]]; then
37+
curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}")
38+
fi
39+
40+
suffix="${os}-${arch}.${ext}"
41+
42+
get_download_url() {
43+
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" |
44+
grep "\"browser_download_url\": \".*/download/.*/configlet.*${suffix}\"$" |
45+
cut -d'"' -f4
46+
}
47+
48+
download_url="$(get_download_url)"
49+
output_dir="bin"
50+
output_path="${output_dir}/latest-configlet.${ext}"
51+
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
52+
53+
case "${ext}" in
54+
*zip) unzip "${output_path}" -d "${output_dir}" ;;
55+
*) tar xzf "${output_path}" -C "${output_dir}" ;;
56+
esac
57+
58+
rm -f "${output_path}"

0 commit comments

Comments
 (0)