-
Notifications
You must be signed in to change notification settings - Fork 176
/
vendor_download.sh
executable file
·149 lines (123 loc) · 4.31 KB
/
vendor_download.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
#
# Requires environment variables:
# GITHUB_TOKEN A token with access to the fossas/themis repository
#
# Requires binary dependencies in $PATH:
# jq Parse and manipulate json structures.
# curl Download data over HTTP(s)
# sed Modify executable names
# xz compress the license index
#
set -e
if [ -z "$GITHUB_TOKEN" ]; then
echo "Provide your GITHUB_TOKEN in the environment"
exit 1
fi
echo "curl version"
echo "------------"
curl --version
echo ""
echo "jq version"
echo "----------"
jq --version
echo ""
rm -f vendor-bins/*
mkdir -p vendor-bins
ASSET_POSTFIX=""
THEMIS_ASSET_POSTFIX=""
LERNIE_ASSET_POSTFIX=""
case "$(uname -s)" in
Darwin)
case "$(uname -m)" in
arm64)
ASSET_POSTFIX="darwin-arm64"
LERNIE_ASSET_POSTFIX="aarch64-macos"
THEMIS_ASSET_POSTFIX="darwin-arm64"
;;
*)
ASSET_POSTFIX="darwin-amd64"
LERNIE_ASSET_POSTFIX="x86_64-macos"
THEMIS_ASSET_POSTFIX="darwin-amd64"
;;
esac
;;
Linux)
case "$(uname -m)" in
aarch64)
ASSET_POSTFIX="linux"
THEMIS_ASSET_POSTFIX="linux-arm64"
LERNIE_ASSET_POSTFIX="aarch64-linux"
;;
*)
ASSET_POSTFIX="linux"
THEMIS_ASSET_POSTFIX="linux-amd64"
LERNIE_ASSET_POSTFIX="x86_64-linux"
;;
esac
;;
*)
echo "Warn: Assuming $(uname -s) is Windows"
ASSET_POSTFIX="windows.exe"
THEMIS_ASSET_POSTFIX="windows-amd64"
LERNIE_ASSET_POSTFIX="x86_64-windows.exe"
;;
esac
# Download latest release of Themis and its index
echo "Downloading asset information from latest tag for architecture '$ASSET_POSTFIX'"
echo "Downloading themis binary from latest release"
THEMIS_RELEASE_JSON=vendor-bins/themis-release.json
curl -sSL \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
https://api.github.com/repos/fossas/themis/releases/latest > $THEMIS_RELEASE_JSON
THEMIS_TAG=$(jq -cr ".name" $THEMIS_RELEASE_JSON)
echo "Using themis release: $THEMIS_TAG"
FILTER=".name == \"themis-cli-$THEMIS_ASSET_POSTFIX\""
jq -c ".assets | map({url: .url, name: .name}) | map(select($FILTER)) | .[]" $THEMIS_RELEASE_JSON | while read -r ASSET; do
URL="$(echo "$ASSET" | jq -c -r '.url')"
NAME="$(echo "$ASSET" | jq -c -r '.name')"
OUTPUT="$(echo vendor-bins/"$NAME" | sed 's/-'$THEMIS_ASSET_POSTFIX'$//')"
echo "Downloading '$NAME' to '$OUTPUT'"
curl -sL -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/octet-stream" -s "$URL" > "$OUTPUT"
done
echo "Themis download successful"
FILTER=".name == \"index.gob\""
jq -c ".assets | map({url: .url, name: .name}) | map(select($FILTER)) | .[]" $THEMIS_RELEASE_JSON | while read -r ASSET; do
URL="$(echo "$ASSET" | jq -c -r '.url')"
NAME="$(echo "$ASSET" | jq -c -r '.name')"
OUTPUT="vendor-bins/$NAME"
echo "Downloading '$NAME' to '$OUTPUT'"
curl -sL -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/octet-stream" -s "$URL" > "$OUTPUT"
done
echo "themis index downloaded"
rm $THEMIS_RELEASE_JSON
echo
# Download latest release of Lernie
echo "Downloading lernie binary from latest release"
LERNIE_RELEASE_JSON=vendor-bins/lernie-release.json
curl -sSL \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
https://api.github.com/repos/fossas/lernie/releases/latest > $LERNIE_RELEASE_JSON
LERNIE_TAG=$(jq -cr ".name" $LERNIE_RELEASE_JSON)
# Strip the leading 'v' off of the tag
LERNIE_VERSION="${LERNIE_TAG/#v/}"
FILTER=".name == \"lernie-$LERNIE_VERSION-$LERNIE_ASSET_POSTFIX\""
jq -c ".assets | map({url: .url, name: .name}) | map(select($FILTER)) | .[]" $LERNIE_RELEASE_JSON | while read -r ASSET; do
URL="$(echo "$ASSET" | jq -c -r '.url')"
NAME="$(echo "$ASSET" | jq -c -r '.name')"
OUTPUT="$(echo vendor-bins/"$NAME" | sed 's/-'"$LERNIE_VERSION"'-'$LERNIE_ASSET_POSTFIX'$//')"
echo "Downloading '$NAME' to '$OUTPUT'"
curl -sL -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/octet-stream" -s "$URL" > "$OUTPUT"
done
echo "Lernie download successful"
rm $LERNIE_RELEASE_JSON
# Finished downloading
echo
echo "Marking binaries executable"
chmod +x vendor-bins/*
echo "Compressing index.gob"
xz vendor-bins/index.gob
echo "Vendored binaries are ready for use"
ls -lh vendor-bins/