-
Notifications
You must be signed in to change notification settings - Fork 3
/
y-bin-dependency-download
executable file
·74 lines (67 loc) · 2.05 KB
/
y-bin-dependency-download
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
#!/bin/sh
[ -z "$DEBUGDEBUG" ] || set -x
set -e
YBIN="$(dirname $0)"
SHA256SUM="sha256sum"
[ -n "$bin_tar_path" ] || bin_tar_path=$bin_tgz_path
bin_tar_extract=$bin_tar_path
[ -n "$bin_tar_compression" ] || bin_tar_compression=z
platform="$(uname -s)"
case "$platform" in
Darwin )
url=$Darwin_url
sha256=$Darwin_sha256
SHA256SUM="shasum -a 256"
;;
Linux )
url=$Linux_url
sha256=$Linux_sha256
case "$bin_tar_path" in
*/*/*) ;;
*/*)
set -o noglob
bin_tar_extract="--wildcards */$(basename $bin_tar_path)"
;;
*) ;;
esac
;;
* )
echo "Unsupported platform $platform" && exit 1
;;
esac
[ ! -z "$bin_version" ] || bin_version=$sha256
bin_uniq=y-$bin_name-$bin_version-bin
bin_file=$YBIN/$bin_uniq
bin_link=$YBIN/$bin_name
[ -f $bin_file ] || {
[ -z "$YSTACK_BIN_DOWNLOAD_CACHE" ] || bin_cache="$YSTACK_BIN_DOWNLOAD_CACHE/$bin_uniq"
[ -z "$bin_cache" ] || [ ! -f "$bin_cache" ] || url="file://$bin_cache"
echo "Missing $bin_name binary. Downloading a known version from $url ..." 1>&2
case "$url" in
*.tar.gz) ;;
*.gz) bin_file=$bin_file.gz ;;
esac
curl -o $bin_file -L -f $url
if ! echo "$sha256 $bin_file" | $SHA256SUM -c - 1>&2; then $SHA256SUM $bin_file && rm $bin_file && exit 1; fi
if [ ! -z "$bin_tar_path" ]; then
tmp=$(mktemp -d)
(cd $tmp; tar -xv${bin_tar_compression}f $bin_file --strip-components=$(echo $bin_tar_path | awk -F'/' '{print NF-1}') $bin_tar_extract) \
|| (cd $tmp; tar -tv${bin_tar_compression}f $bin_file; exit 1)
mv "$tmp/$(basename $bin_tar_path)" $bin_file
fi
if [ ! -z "$bin_zip_path" ]; then
tmp=$(mktemp -d)
(cd $tmp; unzip $bin_file)
mv "$tmp/$bin_zip_path" $bin_file
fi
case "$url" in
*.tar.gz) ;;
*.gz) gunzip $bin_file && bin_file=$(echo $bin_file | sed 's/\.gz$//g') ;;
esac
[ -z "$bin_cache" ] || [ -f "$bin_cache" ] || cp -v $bin_file $bin_cache 1>&2
chmod a+x $bin_file
}
if [ "$(readlink $bin_link)" != "$bin_file" ]; then
[ -L $bin_link ] && rm $bin_link
ln -s $bin_file $bin_link
fi