[New] Dynamically detect if curl supports `--compressed`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Peter Dave Hello · committed by Peter Dave Hello · parent 6a3b1dd · Browse files · 3 files·+60 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+60 added−3 removed
- tests:+45 added−1 removed
- other:+15 added−2 removed
Provenance
- Commit
973dfc6- Tree
37026ec- Author
Peter Dave Hello <hsu@peterdavehello.org>- Committer
Peter Dave Hello <hsu@peterdavehello.org>- Parent
6a3b1dd
3 files changed+60 added−3 removed
added:test/fast/Unit tests/nvm_curl_libz_support+39 added
1+#!/bin/sh2+3+cleanup() {4+ unset -f curl5+}6+7+die() { cleanup; echo "$@" ; exit 1; }8+9+\. ../../../nvm.sh10+11+curl() {12+ # curl with libz feature13+ if [ $# -ne 1 ] || [ "$1" != "-V" ]; then14+ die "This fake curl only takes one parameter -V"15+ fi16+ echo "17+curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.318+Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp19+Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets"20+}21+22+nvm_curl_libz_support || die "nvm_curl_libz_support should return 0"23+24+unset -f curl25+26+curl() {27+ # curl without libz feature28+ if [ "$#" -ne 1 ] || [ "$1" != "-V" ]; then29+ die "This fake curl only takes one parameter -V"30+ fi31+ echo "32+curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3233+Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp34+Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP UnixSockets"35+}36+37+! nvm_curl_libz_support || die "nvm_curl_libz_support should return 1"38+39+unset -f curlmodified:test/slow/nvm_get_latest/nvm_get_latest+6 added-1 removed
12 unmodified lines13 EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"14 EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"15 16 curl() {17+ if [ $# -eq 1 ] && [ "$1" = "-V" ]; then18+ echo "19+curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.320+Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp21+Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets"17- if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then22+ elif [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then23 echo >&2 "expected args ($EXPECTED_CURL_ARGS), got ($*)"24 return 125 else26 echo $URL96 unmodified linesmodified:nvm.sh+15 added-2 removed
55 unmodified lines56 fi57 [ "${NVM_COLORS:--1}" -ge 8 ]58 }59 60+nvm_curl_libz_support() {61+ curl -V | grep "^Features:" | grep -q "libz"62+}63+64 nvm_get_latest() {65 local NVM_LATEST_URL66+ local CURL_COMPRESSED_FLAG67+ if nvm_curl_libz_support; then68+ CURL_COMPRESSED_FLAG="--compressed"69+ fi70 if nvm_has "curl"; then63- NVM_LATEST_URL="$(curl --compressed -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"71+ NVM_LATEST_URL="$(curl "${CURL_COMPRESSED_FLAG:-}" -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"72 elif nvm_has "wget"; then73 NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"74 else75 nvm_err 'nvm needs curl or wget to proceed.'6 unmodified lines82 nvm_echo "${NVM_LATEST_URL##*/}"83 }84 85 nvm_download() {86+ local CURL_COMPRESSED_FLAG87+ if nvm_curl_libz_support; then88+ CURL_COMPRESSED_FLAG="--compressed"89+ fi90 if nvm_has "curl"; then79- curl --compressed -q "$@"91+ curl "${CURL_COMPRESSED_FLAG:-}" -q "$@"92 elif nvm_has "wget"; then93 # Emulate curl with wget94 ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \95 -e 's/--compressed //' \3107 unmodified lines3203 nvm_list_aliases nvm_make_alias nvm_print_alias_path \3204 nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \3205 nvm_sanitize_path nvm_has_colors nvm_process_parameters \3206 node_version_has_solaris_binary iojs_version_has_solaris_binary \3207+ nvm_curl_libz_support \3208 > /dev/null 2>&13209 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \3210 NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \3211 > /dev/null 2>&192 unmodified lines