Repository: nvm-sh/nvm
File: nvm.sh (Shell)

Code before:
  NVM_OS="$(nvm_get_os)"

  local tarball
  tarball=''
  local sum
  sum=''
  local make
  make='make'
  if [ "_$NVM_OS" = "_freebsd" ]; then
    make='gmake'
    MAKE_CXX="CXX=c++"
  fi

  if [ -z "$NVM_CPU_THREADS" ] || [[ ! $NVM_CPU_THREADS =~ ^[0-9]+$ ]] ; then
    if [ "_$NVM_OS" = "_linux" ]; then
      NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"
    elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
      NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"
    elif [ "_$NVM_OS" = "_sunos" ]; then
      NVM_CPU_THREADS="$(psrinfo | wc -l)"
    fi
    if [ -z "$NVM_CPU_THREADS" ] || [[ ! $NVM_CPU_THREADS =~ ^[0-9]+$ ]] ; then
      echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&2
      echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&2
      NVM_MAKE_JOBS="1"
    else
      NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))
    fi
  else
    NVM_MAKE_JOBS=$NVM_CPU_THREADS
  fi
  local tmpdir
  tmpdir="$NVM_DIR/src"
  local tmptarball
  tmptarball="$tmpdir/node-$VERSION.tar.gz"

  if [ "$(nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - 2>&1 | command grep '200 OK')" != '' ]; then
    tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
    sum=$(nvm_download -L -s "$NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt" -o - | command grep "node-${VERSION}.tar.gz" | command awk '{print $1}')
  elif [ "$(nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | command grep '200 OK')" != '' ]; then
    tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
  fi

  if (
    [ -n "$tarball" ] && \
    command mkdir -p "$tmpdir" && \
    echo "Downloading $tarball..." && \
    nvm_download -L --progress-bar "$tarball" -o "$tmptarball" && \
    nvm_checksum "$tmptarball" "$sum" && \
    command tar -xzf "$tmptarball" -C "$tmpdir" && \
    cd "$tmpdir/node-$VERSION" && \

Review comment (bug):
If you want to encourage people to include `nvm debug` output in this error message (and then update `nvm debug` to output `NVM_OS` and `NVM_ARCH`), that would help the error reports be more useful :-)


Code after:
  NVM_OS="$(nvm_get_os)"

  local tarball
  tarball=''
  local sum
  sum=''
  local make
  make='make'
  if [ "_$NVM_OS" = "_freebsd" ]; then
    make='gmake'
    MAKE_CXX="CXX=c++"
  fi

  if [ -z "$NVM_MAKE_JOBS" ]; then
    if [ "_$NVM_OS" = "_linux" ]; then
      NVM_CPU_THREADS="$(grep -c 'core id' /proc/cpuinfo)"
    elif [ "_$NVM_OS" = "_freebsd" ] || [ "_$NVM_OS" = "_darwin" ]; then
      NVM_CPU_THREADS="$(sysctl -n hw.ncpu)"
    elif [ "_$NVM_OS" = "_sunos" ]; then
      NVM_CPU_THREADS="$(psrinfo | wc -l)"
    fi
    local NVM_CPU_THREAD_VALID
    NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $NVM_CPU_THREADS)
    if [ -z "$NVM_CPU_THREADS" ] || [ "$NVM_CPU_THREAD_VALID" != "true" ] ; then
      echo "Can not determine how many thread(s) we can use, set to only 1 now." 1>&2
      echo "Please report an issue on GitHub to help us make it better and run it faster on your computer!" 1>&2
      NVM_MAKE_JOBS="1"
    else
      echo "Detected that you have $NVM_CPU_THREADS CPU thread(s)"
      if [ $NVM_CPU_THREADS -gt 2 ]; then
        NVM_MAKE_JOBS=$(($NVM_CPU_THREADS - 1))
        echo "Set the number of jobs to $NVM_CPU_THREADS - 1 = $NVM_MAKE_JOBS jobs to speed up the build"
      else
        NVM_MAKE_JOBS=1
        echo "Number of CPU thread(s) less or equal to 2 will have only one job a time for 'make'"
      fi
    fi
  fi
  local tmpdir
  tmpdir="$NVM_DIR/src"
  local tmptarball
  tmptarball="$tmpdir/node-$VERSION.tar.gz"

  if [ "$(nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - 2>&1 | command grep '200 OK')" != '' ]; then
    tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
    sum=$(nvm_download -L -s "$NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt" -o - | command grep "node-${VERSION}.tar.gz" | command awk '{print $1}')
  elif [ "$(nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | command grep '200 OK')" != '' ]; then
    tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
  fi

  if (