9 type "$1" > /dev/null 2> /dev/null
13 printf "" > "$1" && rm "$1"
20 if [ -z "$url" ] || [ -z "$output" ]; then
21 die "download takes exactly two arguments. was given '$@'"
24 if ! check_writeable "$output"; then
25 die "download error: cannot write to $output"
28 if have_binary wget; then
29 printf 'Using wget to download "%s" to "%s"\n' "$url" "$output"
30 wget "$url" -O "$output"
31 elif have_binary curl; then
32 printf 'Using curl to download "%s" to "%s"\n' "$url" "$output"
33 curl --silent "$url" > "$output"
34 elif have_binary fetch; then
35 printf 'Using fetch to download "%s" to "%s"\n' "$url" "$output"
36 fetch "$url" -o "$output"
38 die "no binary found to download $url. exiting."
43 local archivetype="$1"
48 if ! check_writeable "$outfile"; then
49 die "unarchive error: cannot write to $outfile"
54 if have_binary tar; then
55 echo "==> using 'tar' to extract binary from archive"
56 cat "$infile" | tar -O -z -x "$distname/$distname" > "$outfile"
58 die "no binary on system for extracting tar files"
62 if have_binary unzip; then
63 echo "==> using 'unzip' to extract binary from archive"
64 unzip -p "$infile" "$distname/$distname" > "$outfile"
66 die "no installed method for extracting .zip archives"
70 die "unrecognized archive type '$archivetype'"
77 if [ ! -z "$GOOS" ] && [ ! -z "$GOARCH" ]; then
78 printf "%s-%s" "$GOOS" "$GOARCH"
81 if have_binary go; then
82 printf "%s-%s" "$(go env GOOS)" "$(go env GOARCH)"
84 die "no way of determining system GOOS and GOARCH\nPlease manually set GOOS and GOARCH then retry."
93 local govars=$(get_go_vars)
95 echo "http://dist.ipfs.io/$name/$vers/${name}_${vers}_$govars.$archive"
102 if [ -z "$distname" ] || [ -z "$outpath" ] || [ -z "$version" ]; then
103 die "usage: dist_get <distname> <outpath> <version>"
106 if [ ${version:0:1} != "v" ]; then
107 echo "invalid version '$version'" >&2
108 die "versions must begin with 'v', for example: v0.4.0"
111 # TODO: don't depend on the go tool being installed to detect this
128 echo "unrecognized system environment: $goenv" >&2
129 die "currently only linux, darwin, windows and freebsd are supported by this script"
135 url=$(mkurl "$distname" "$version" "$archive")
136 tmpfi="bin/tmp/$distname.$archive"
138 download "$url" "$tmpfi"
139 if [ $? -ne 0 ]; then
140 die "failed to download $url to $tmpfi"
143 unarchive "$archive" "$tmpfi" "$outpath" "$distname"
144 if [ $? -ne 0 ]; then
145 die "failed to exract archive $tmpfi"