Skip to content
Myr

[shellcheck] clean up `install.sh`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordan Harband · committed by Jordan Harband · parent 2228323 · Browse files · 1 file+26 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+26 added−24 removed

  • other:+26 added−24 removed

1 file+26 added−24 removed

modified:install.sh+26 added-24 removed
5 unmodified lines
6 type "$1" > /dev/null 2>&17}89nvm_install_dir() {10 echo ${NVM_DIR:-"$HOME/.nvm"}10 echo "${NVM_DIR:-"$HOME/.nvm"}"11}1213nvm_latest_version() {14 echo "v0.31.4"
33 unmodified lines
48}4950nvm_download() {51 if nvm_has "curl"; then52 curl -q $*52 curl -q "$@"53 elif nvm_has "wget"; then54 # Emulate curl with wget55 ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \56 -e 's/-L //' \57 -e 's/-I /--server-response /' \58 -e 's/-s /-q /' \59 -e 's/-o /-O /' \60 -e 's/-C - /-c /')61 # shellcheck disable=SC208661 wget $ARGS62 eval wget $ARGS63 fi64}6566install_nvm_from_git() {
1 unmodified line
68 INSTALL_DIR="$(nvm_install_dir)"6970 if [ -d "$INSTALL_DIR/.git" ]; then71 echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"71 printf "\r=> "72 command printf "\r=> "73 command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null || {74 echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself."75 exit 176 }77 else78 # Cloning to $INSTALL_DIR79 echo "=> Downloading nvm from git to '$INSTALL_DIR'"79 printf "\r=> "80 command printf "\r=> "81 mkdir -p "$INSTALL_DIR"82 command git clone "$(nvm_source)" "$INSTALL_DIR" || {83 echo >&2 "Failed to clone nvm repo. Please report this!"84 exit 1
69 unmodified lines
154# The echo'ed path is guaranteed to be an existing file155# Otherwise, an empty string is returned156#157nvm_detect_profile() {157 if [ -n "$PROFILE" -a -f "$PROFILE" ]; then158 echo "$PROFILE"158 if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then159 echo "${PROFILE}"160 return161 fi162163 local DETECTED_PROFILE
42 unmodified lines
206207 local NPM_GLOBAL_MODULES208 NPM_GLOBAL_MODULES="$(209 npm list -g --depth=0 |209 sed '/ npm@/d' |210 sed '/ (empty)$/d'210 command sed '/ npm@/d' |211 command sed '/ (empty)$/d'212 )"213214 local MODULE_COUNT215 MODULE_COUNT="$(215 printf %s\\n "$NPM_GLOBAL_MODULES" |216 sed -ne '1!p' | # Remove the first line216 command printf %s\\n "$NPM_GLOBAL_MODULES" |217 command sed -ne '1!p' | # Remove the first line218 wc -l | tr -d ' ' # Count entries219 )"220220 if [ $MODULE_COUNT -ne 0 ]; then221 if [ "${MODULE_COUNT}" != '0' ]; then222 cat <<-'END_MESSAGE'223 => You currently have modules installed globally with `npm`. These will no224 => longer be linked to the active version of Node when you install a new node225 => with `nvm`; and they may (depending on how you construct your `$PATH`)226 => override the binaries of modules installed with `nvm`:227228 END_MESSAGE228 printf %s\\n "$NPM_GLOBAL_MODULES"229 command printf %s\\n "$NPM_GLOBAL_MODULES"230 cat <<-'END_MESSAGE'231232 => If you wish to uninstall them at a later point (or re-install them under your233 => `nvm` Nodes), you can remove them from the system Node as follows:
32 unmodified lines
266267 echo268269 local NVM_PROFILE269 NVM_PROFILE=$(nvm_detect_profile)270 NVM_PROFILE="$(nvm_detect_profile)"271 local INSTALL_DIR272 INSTALL_DIR="$(nvm_install_dir)"273274 SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm\n"275275 if [ -z "$NVM_PROFILE" ] ; then276 echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."276 if [ -z "${NVM_PROFILE-}" ] ; then277 echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."278 echo "=> Create one of them and run this script again"278 echo "=> Create it (touch $NVM_PROFILE) and run this script again"279 echo "=> Create it (touch ${NVM_PROFILE}) and run this script again"280 echo " OR"281 echo "=> Append the following lines to the correct file yourself:"281 printf "$SOURCE_STR"282 command printf "${SOURCE_STR}"283 else283 if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then284 echo "=> Appending source string to $NVM_PROFILE"285 printf "$SOURCE_STR" >> "$NVM_PROFILE"284 if ! command grep -qc '/nvm.sh' "${NVM_PROFILE}"; then285 echo "=> Appending source string to ${NVM_PROFILE}"286 command printf "%s" "${SOURCE_STR}" >> "${NVM_PROFILE}"287 else287 echo "=> Source string already in $NVM_PROFILE"288 echo "=> Source string already in ${NVM_PROFILE}"289 fi290 fi291292 # Source nvm292 . "$INSTALL_DIR/nvm.sh"293 # shellcheck source=/dev/null294 . "${INSTALL_DIR}/nvm.sh"295296 nvm_check_global_modules297298 nvm_install_node299300 nvm_reset301302 echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"301 printf "$SOURCE_STR"303 command printf "%s" "${SOURCE_STR}"304}305306#307# Unsets the various functions defined
12 unmodified lines