mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	Use curl or wget, whichever is available
Also spit out an error message if we have neither.
This commit is contained in:
		
							
								
								
									
										23
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -8,6 +8,24 @@ | ||||
| # Auto detect the NVM_DIR using magic bash 3.x stuff | ||||
| export NVM_DIR=$(dirname ${BASH_ARGV[0]}) | ||||
|  | ||||
| # Emulate curl with wget, if necessary | ||||
| if [ ! `which curl` ]; then | ||||
|     if [ `which wget` ]; then | ||||
|         curl() { | ||||
|             ARGS="$* " | ||||
|             ARGS=${ARGS/-s /-q } | ||||
|             ARGS=${ARGS/-\# /} | ||||
|             ARGS=${ARGS/-C - /-c } | ||||
|             ARGS=${ARGS/-o /-O } | ||||
|  | ||||
|             wget $ARGS | ||||
|         } | ||||
|     else | ||||
|         NOCURL='nocurl' | ||||
|         curl() { echo 'Need curl or wget to proceed.' >&2; } | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| nvm() | ||||
| { | ||||
|   if [ $# -lt 1 ]; then | ||||
| @@ -36,10 +54,11 @@ nvm() | ||||
|         nvm help | ||||
|         return; | ||||
|       fi | ||||
|       [ "$NOCURL" ] && curl && return | ||||
|       START=`pwd` | ||||
|       mkdir -p "$NVM_DIR/src" && \ | ||||
|       cd "$NVM_DIR/src" && \ | ||||
|       wget "http://nodejs.org/dist/node-$2.tar.gz" -N && \ | ||||
|       curl -C - -# "http://nodejs.org/dist/node-$2.tar.gz" -o "node-$2.tar.gz" && \ | ||||
|       tar -xzf "node-$2.tar.gz" && \ | ||||
|       cd "node-$2" && \ | ||||
|       ./configure --prefix="$NVM_DIR/$2" && \ | ||||
| @@ -48,7 +67,7 @@ nvm() | ||||
|       nvm use $2 | ||||
|       if ! which npm ; then | ||||
|         echo "Installing npm..." | ||||
|         curl http://npmjs.org/install.sh | sh | ||||
|         curl -# http://npmjs.org/install.sh -o - | sh | ||||
|       fi | ||||
|       cd $START | ||||
|     ;; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user