@cryptotaxi247 / kubo / commits / 5f624efe7

fix up dist_get script

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Apr 28, 2016 at 10:54 UTC 5f624efe734c4d77231bcce63f8c9baff19d39f2
1 file changed +24 -23
bin/dist_get
+24 -23
@@ -19,24 +19,21 @@ download() {
19
20 test "$#" -eq "2" || die "download requires exactly two arguments, was given $@"
21
22 - if ! check_writeable "$output"; then
23 - die "download error: cannot write to $output"
22 + if ! check_writeable "$dl_output"; then
23 + die "download error: cannot write to $dl_output"
24 fi
25
26 if have_binary wget; then
27 - printf '==> Using wget to download "%s" to "%s"\n' "$url" "$output"
28 - wget "$url" -O "$output"
27 + printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output"
28 + wget "$dl_url" -O "$dl_output" || return
29 elif have_binary curl; then
30 - printf '==> Using curl to download "%s" to "%s"\n' "$url" "$output"
31 - curl --silent "$url" > "$output"
30 + printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output"
31 + curl --silent "$dl_url" > "$dl_output" || return
32 elif have_binary fetch; then
33 - printf '==> Using fetch to download "%s" to "%s"\n' "$url" "$output"
34 - fetch "$url" -o "$output"
33 + printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output"
34 + fetch "$dl_url" -o "$dl_output" || return
35 else
36 - die "no binary found to download $url. exiting."
37 - fi
38 - if [ "$?" -ne 0 ]; then
39 - return $?
36 + die "no binary found to download $dl_url. exiting."
37 fi
38 echo "==> download complete!"
39 }
@@ -88,13 +85,12 @@ get_go_vars() {
85 }
86
87 mkurl() {
91 - local name="$1"
92 - local vers="$2"
93 - local archive="$3"
94 -
95 - local govars=$(get_go_vars)
88 + m_name="$1"
89 + m_vers="$2"
90 + m_archive="$3"
91 + m_govars=$(get_go_vars) || die "could not get go env vars"
92
97 - echo "http://dist.ipfs.io/$name/$vers/${name}_${vers}_$govars.$archive"
93 + echo "http://dist.ipfs.io/$m_name/$m_vers/${m_name}_${m_vers}_$m_govars.$m_archive"
94 }
95
96 distname="$1"
@@ -105,13 +101,18 @@ if [ -z "$distname" ] || [ -z "$outpath" ] || [ -z "$version" ]; then
101 die "usage: dist_get <distname> <outpath> <version>"
102 fi
103
108 -if [ ${version:0:1} != "v" ]; then
109 - echo "invalid version '$version'" >&2
110 - die "versions must begin with 'v', for example: v0.4.0"
111 -fi
104 +case $version in
105 + v*)
106 + # correct input
107 + ;;
108 + *)
109 + echo "invalid version '$version'" >&2
110 + die "versions must begin with 'v', for example: v0.4.0"
111 + ;;
112 +esac
113
114 # TODO: don't depend on the go tool being installed to detect this
114 -goenv=$(get_go_vars)
115 +goenv=$(get_go_vars) || die "could not get go env vars"
116
117 case $goenv in
118 linux-*)