mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 18:25:52 +08:00 
			
		
		
		
	Force install method by setting METHOD=git/script
This commit is contained in:
		
							
								
								
									
										40
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								install.sh
									
									
									
									
									
								
							| @@ -14,9 +14,9 @@ fi | |||||||
| download_file() { | download_file() { | ||||||
|   # download_file source destination |   # download_file source destination | ||||||
|   if has "curl"; then |   if has "curl"; then | ||||||
|     curl --silent "$1" -o "$2" |     curl -s "$1" -o "$2" | ||||||
|   elif has "wget"; then |   elif has "wget"; then | ||||||
|     wget --quiet "$1" -O "$2" |     wget -q "$1" -O "$2" | ||||||
|   else |   else | ||||||
|     return 1 |     return 1 | ||||||
|   fi |   fi | ||||||
| @@ -28,13 +28,15 @@ install_from_git() { | |||||||
|   fi |   fi | ||||||
|  |  | ||||||
|   if [ -d "$NVM_DIR/.git" ]; then |   if [ -d "$NVM_DIR/.git" ]; then | ||||||
|     echo "=> NVM is already installed in $NVM_DIR, trying to update" |     echo "=> nvm is already installed in $NVM_DIR, trying to update" | ||||||
|     echo -e "\r=> \c" |     echo -e "\r=> \c" | ||||||
|     cd "$NVM_DIR" && git pull 2> /dev/null || { |     cd "$NVM_DIR" && git pull 2> /dev/null || { | ||||||
|       echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." |       echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." | ||||||
|     } |     } | ||||||
|   else |   else | ||||||
|     # Cloning to $NVM_DIR |     # Cloning to $NVM_DIR | ||||||
|  |     echo "=> Downloading nvm from git to '$NVM_DIR'" | ||||||
|  |     echo -e "\r=> \c" | ||||||
|     mkdir -p "$NVM_DIR" |     mkdir -p "$NVM_DIR" | ||||||
|     git clone "$NVM_SOURCE" "$NVM_DIR" |     git clone "$NVM_SOURCE" "$NVM_DIR" | ||||||
|   fi |   fi | ||||||
| @@ -48,23 +50,37 @@ install_as_script() { | |||||||
|   # Downloading to $NVM_DIR |   # Downloading to $NVM_DIR | ||||||
|   mkdir -p "$NVM_DIR" |   mkdir -p "$NVM_DIR" | ||||||
|   if [ -d "$NVM_DIR/nvm.sh" ]; then |   if [ -d "$NVM_DIR/nvm.sh" ]; then | ||||||
|     echo "=> NVM is already installed in $NVM_DIR, trying to update" |     echo "=> nvm is already installed in $NVM_DIR, trying to update" | ||||||
|   else |   else | ||||||
|     echo "=> Downloading NVM to '$NVM_DIR'" |     echo "=> Downloading nvm as script to '$NVM_DIR'" | ||||||
|   fi |   fi | ||||||
|   download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || { |   download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || { | ||||||
|     echo >&2 "Failed.." |     echo >&2 "Failed to download '$NVM_SOURCE'.." | ||||||
|     return 1 |     return 1 | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| if has "git"; then | if [ -z "$METHOD" ]; then | ||||||
|  install_from_git |  install_from_git || { | ||||||
| else |    echo >&2 "Install using git failed, falling to back to script" | ||||||
|    install_as_script || { |    install_as_script || { | ||||||
|     echo >&2 -e "You need git, curl or wget to install NVM" |      echo >&2 "You need git, curl or wget to install nvm" | ||||||
|      exit 1 |      exit 1 | ||||||
|    } |    } | ||||||
|  |  } | ||||||
|  | else | ||||||
|  |   if [ "$METHOD" = "git" ]; then | ||||||
|  |     install_from_git || { | ||||||
|  |       echo >&2 "You need git to install nvm" | ||||||
|  |       exit 1 | ||||||
|  |     } | ||||||
|  |   fi | ||||||
|  |   if [ "$METHOD" = "script" ]; then | ||||||
|  |     install_as_script || { | ||||||
|  |       echo >&2 "You need curl or wget to install nvm" | ||||||
|  |       exit 1 | ||||||
|  |     } | ||||||
|  |   fi | ||||||
| fi | fi | ||||||
|  |  | ||||||
| echo | echo | ||||||
| @@ -80,7 +96,7 @@ if [ -z "$PROFILE" ]; then | |||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
|  |  | ||||||
| SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"  # This loads NVM" | SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"  # This loads nvm" | ||||||
|  |  | ||||||
| if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then | if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then | ||||||
|   if [ -z $PROFILE ]; then |   if [ -z $PROFILE ]; then | ||||||
| @@ -105,5 +121,5 @@ else | |||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
|  |  | ||||||
| echo "=> Close and reopen your terminal to start using NVM" | echo "=> Close and reopen your terminal to start using nvm" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user