@cryptotaxi247 / kubo / commits / 3c7fad8af

address some CR feedback

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

Jeromy committed Apr 27, 2016 at 15:32 UTC 3c7fad8af19a3a1d76418429b13db5c707ebf194
1 file changed +23 -21
bin/dist_get
+23 -21
@@ -1,4 +1,4 @@
1 -#!/bin/bash
1 +#!/bin/sh
2
3 die() {
4 echo "$@" >&2
@@ -14,46 +14,48 @@ check_writeable() {
14 }
15
16 download() {
17 - local url="$1"
18 - local output="$2"
17 + dl_url="$1"
18 + dl_output="$2"
19
20 - if [ -z "$url" ] || [ -z "$output" ]; then
21 - die "download takes exactly two arguments. was given '$@'"
22 - fi
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"
24 fi
25
26 if have_binary wget; then
29 - printf 'Using wget to download "%s" to "%s"\n' "$url" "$output"
27 + printf '==> Using wget to download "%s" to "%s"\n' "$url" "$output"
28 wget "$url" -O "$output"
29 elif have_binary curl; then
32 - printf 'Using curl to download "%s" to "%s"\n' "$url" "$output"
30 + printf '==> Using curl to download "%s" to "%s"\n' "$url" "$output"
31 curl --silent "$url" > "$output"
32 elif have_binary fetch; then
35 - printf 'Using fetch to download "%s" to "%s"\n' "$url" "$output"
33 + printf '==> Using fetch to download "%s" to "%s"\n' "$url" "$output"
34 fetch "$url" -o "$output"
35 else
36 die "no binary found to download $url. exiting."
37 fi
38 + if [ "$?" -ne 0 ]; then
39 + return $?
40 + fi
41 + echo "==> download complete!"
42 }
43
44 unarchive() {
43 - local archivetype="$1"
44 - local infile="$2"
45 - local outfile="$3"
46 - local distname="$4"
45 + ua_archivetype="$1"
46 + ua_infile="$2"
47 + ua_outfile="$3"
48 + ua_distname="$4"
49
48 - if ! check_writeable "$outfile"; then
49 - die "unarchive error: cannot write to $outfile"
50 + if ! check_writeable "$ua_outfile"; then
51 + die "unarchive error: cannot write to $ua_outfile"
52 fi
53
52 - case $archivetype in
54 + case "$ua_archivetype" in
55 tar.gz)
56 if have_binary tar; then
57 echo "==> using 'tar' to extract binary from archive"
56 - cat "$infile" | tar -O -z -x "$distname/$distname" > "$outfile"
58 + cat "$ua_infile" | tar -O -z -x "$ua_distname/$ua_distname" > "$ua_outfile"
59 else
60 die "no binary on system for extracting tar files"
61 fi
@@ -61,16 +63,16 @@ unarchive() {
63 zip)
64 if have_binary unzip; then
65 echo "==> using 'unzip' to extract binary from archive"
64 - unzip -p "$infile" "$distname/$distname" > "$outfile"
66 + unzip -p "$ua_infile" "$ua_distname/$ua_distname" > "$ua_outfile"
67 else
68 die "no installed method for extracting .zip archives"
69 fi
70 ;;
71 *)
70 - die "unrecognized archive type '$archivetype'"
72 + die "unrecognized archive type '$ua_archivetype'"
73 esac
74
73 - chmod +x "$outfile"
75 + chmod +x "$ua_outfile"
76 }
77
78 get_go_vars() {
@@ -142,5 +144,5 @@ fi
144
145 unarchive "$archive" "$tmpfi" "$outpath" "$distname"
146 if [ $? -ne 0 ]; then
145 - die "failed to exract archive $tmpfi"
147 + die "failed to extract archive $tmpfi"
148 fi