forked from fossas/fossa-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vendor_download.sh
executable file
·125 lines (104 loc) · 3.84 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
#!/usr/bin/env bash
#
# Requires environment variables:
# GITHUB_TOKEN A token with access to the fossas/basis repository
#
# Requires binary dependencies in $PATH:
# jq Parse and manipulate json structures.
# curl Download data over HTTP(s)
# sed Modify syft tag
# xz compress the license index
# upx Compress binaries (optional)
#
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=""
BASIS_ASSET_POSTFIX=""
OS_WINDOWS=false
case "$(uname -s)" in
Darwin)
ASSET_POSTFIX="darwin"
BASIS_ASSET_POSTFIX="darwin-amd64"
;;
Linux)
ASSET_POSTFIX="linux"
BASIS_ASSET_POSTFIX="linux-amd64"
;;
*)
echo "Warn: Assuming $(uname -s) is Windows"
ASSET_POSTFIX="windows.exe"
BASIS_ASSET_POSTFIX="windows-amd64"
OS_WINDOWS=true
;;
esac
TAG="latest"
echo "Downloading asset information from latest tag for architecture '$ASSET_POSTFIX'"
WIGGINS_TAG="2022-01-19-a647d17"
echo "Downloading wiggins binary"
echo "Using wiggins release: $WIGGINS_TAG"
WIGGINS_RELEASE_JSON=vendor-bins/wiggins-release.json
curl -sSL \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
https://api.github.com/repos/fossas/basis/releases/tags/$WIGGINS_TAG > $WIGGINS_RELEASE_JSON
WIGGINS_TAG=$(jq -cr ".name" $WIGGINS_RELEASE_JSON)
FILTER=".name == \"scotland_yard-wiggins-$BASIS_ASSET_POSTFIX\""
jq -c ".assets | map({url: .url, name: .name}) | map(select($FILTER)) | .[]" $WIGGINS_RELEASE_JSON | while read ASSET; do
URL="$(echo $ASSET | jq -c -r '.url')"
NAME="$(echo $ASSET | jq -c -r '.name')"
OUTPUT="$(echo vendor-bins/$NAME | sed 's/scotland_yard-//' | sed 's/-'$BASIS_ASSET_POSTFIX'$//')"
echo "Downloading '$NAME' to '$OUTPUT'"
curl -sL -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/octet-stream" -s $URL > $OUTPUT
done
rm $WIGGINS_RELEASE_JSON
echo "Wiggins download successful"
echo
THEMIS_TAG="2023-01-05-d5a3fe2-1672962253"
echo "Downloading themis binary"
echo "Using themis release: $THEMIS_TAG"
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/basis/releases/tags/$THEMIS_TAG > $THEMIS_RELEASE_JSON
THEMIS_TAG=$(jq -cr ".name" $THEMIS_RELEASE_JSON)
FILTER=".name == \"themis-cli-$BASIS_ASSET_POSTFIX\""
jq -c ".assets | map({url: .url, name: .name}) | map(select($FILTER)) | .[]" $THEMIS_RELEASE_JSON | while read ASSET; do
URL="$(echo $ASSET | jq -c -r '.url')"
NAME="$(echo $ASSET | jq -c -r '.name')"
OUTPUT="$(echo vendor-bins/$NAME | sed 's/-'$BASIS_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 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
echo "Marking binaries executable"
chmod +x vendor-bins/*
echo "Compressing binaries"
xz vendor-bins/index.gob
find vendor-bins -type f -not -name '*.xz' | xargs upx || echo "WARN: 'upx' command not found, binaries will not be compressed"
echo "Vendored binaries are ready for use"
ls -lh vendor-bins/