-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better combo curl/wget handling #452
Conversation
@koenpunt: mind taking a look at this? |
Looks fine, but maybe we should rename |
Good idea. Unfortunately, this doesn't work :-/ it seems the curl options we use can't be cleanly passed to wget. |
The other option is to just remove wget support everywhere. |
@@ -391,16 +405,16 @@ nvm() { | |||
tmpdir="$NVM_DIR/src" | |||
local tmptarball | |||
tmptarball="$tmpdir/node-$VERSION.tar.gz" | |||
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then | |||
if [ "`nvm_curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unsupported arguments are --progress-bar
, which is the default for wget so we can just strip that, and -L
(follow location) is also the default in wget so we can strip that as well, and -C
(continue transfer) has an equal in wget: -c
:
nvm_curl() {
ARGS="$* "
ARGS=${ARGS/--progress-bar /}
ARGS=${ARGS/-L /}
ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-o /-O }
ARGS=${ARGS/-C /-c }
wget "$ARGS"
}
And then there is -I
, but we can replace that for a version comparison, as it seems like that since version 0.5.1 they all end up in a subdirectory on http://nodejs.org/dist anyway:
[ $(nvm_normalize_version "$VERSION") -ge $(nvm_normalize_version "0.5.1") ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think for now I'll just strip the -I
check (making the wget
less efficient), and we can change the logic in another PR.
I tested both curl and wget manually here, and it all works. |
ARGS=${ARGS/--progress-bar /--progress=bar } | ||
ARGS=${ARGS/-L /} | ||
ARGS=${ARGS/-I /} | ||
ARGS=${ARGS/-s /-qO- } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like the correct replacement.. -qO-
means silent and output to stdout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which part? (i'll take out the echo, oops)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in curl, -s
silences the output but still prints the data to stdout. in wget, -q
silences the output but does not print to stdout - to keep the same semantics, -qO-
will silence output and print data to stdout in wget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add -o -
to the commands that need it would be a solution. From the manual:
-o, --output
Write output to instead of stdout.
....
Specifying the output as '-' (a single dash) will force the output to be done to stdout.
ARGS=${ARGS/--progress-bar /--progress=bar } | ||
ARGS=${ARGS/-L /} | ||
ARGS=${ARGS/-I /} | ||
ARGS=${ARGS/-s /-qO- } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
fix nvm_curl arguments for stdout
So it wasn't renamed to nvm_download after all? |
Anyway, huge props for it! |
Oops :-) I'll do that in a followup. Still not in a release tag, so nobody should be using it unless they're testing nvm itself. |
I thought of that, but imho And I think we should extract the checksum verification into its own method. |
@koenpunt i'll be happy to accept PRs for those :-) |
Fixes #451