Skip to content

Commit d123082

Browse files
authored
add script to fetch canonical data syncer (#984)
1 parent 83ab572 commit d123082

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ bin/configlet
77
bin/configlet.exe
88
bin/exercise
99
bin/exercise.exe
10+
bin/canonical_data_syncer
11+
bin/canonical_data_syncer.exe
1012
exercises/*/Cargo.lock

bin/fetch-canonical_data_syncer.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
readonly LATEST='https://api.github.com/repos/exercism/canonical-data-syncer/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' ;;
19+
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+
if [ -z "${GITHUB_TOKEN}" ]
29+
then
30+
HEADER=''
31+
else
32+
HEADER="authorization: Bearer ${GITHUB_TOKEN}"
33+
fi
34+
35+
FILENAME="canonical_data_syncer-${OS}-${ARCH}.${EXT}"
36+
37+
get_url () {
38+
curl --header "$HEADER" -s "$LATEST" |
39+
awk -v filename=$FILENAME '$1 ~ /browser_download_url/ && $2 ~ filename { print $2 }' |
40+
tr -d '"'
41+
}
42+
43+
URL=$(get_url)
44+
45+
case "$EXT" in
46+
(*zip)
47+
curl --header "$HEADER" -s --location "$URL" -o bin/latest-canonical_data_syncer.zip
48+
unzip bin/latest-canonical_data_syncer.zip -d bin/
49+
rm bin/latest-canonical_data_syncer.zip
50+
;;
51+
(*) curl --header "$HEADER" -s --location "$URL" | tar xz -C bin/ ;;
52+
esac

0 commit comments

Comments
 (0)