base 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env bash
  2. # Base is a collection of general files + commonly included setup functions.
  3. #duplicated from scripts/rvm - rare reload issue
  4. __rvm_has_opt()
  5. {
  6. if # pre-gnu
  7. [[ -n "${ZSH_VERSION:-}" ]]
  8. then
  9. setopt | GREP_OPTIONS="" \command \grep "^${1:-}$" >/dev/null 2>&1 || return $?
  10. elif # mksh
  11. [[ -n "${KSH_VERSION:-}" ]]
  12. then
  13. set +o | GREP_OPTIONS="" \command \grep "-o ${1:-}$" >/dev/null 2>&1 || return $?
  14. elif # bash
  15. [[ -n "${BASH_VERSION:-}" ]]
  16. then
  17. [[ ":${SHELLOPTS:-}:" == *":${1:-}:"* ]] || return $?
  18. else # what is this?!
  19. return 1
  20. fi
  21. }
  22. if __rvm_has_opt "errexit"
  23. then rvm_stored_errexit=1
  24. fi
  25. set +e
  26. # duplication marker jkdfkdfngjdjkfngjkdfngjkd
  27. if
  28. (( ${rvm_trace_flag:-0} == 1 ))
  29. then
  30. if [[ -n "${BASH_VERSION:-}" ]]
  31. then export PS4="+ \$(__rvm_date \"+%s.%N\" 2>/dev/null) \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
  32. elif [[ -n "${ZSH_VERSION:-}" ]]
  33. then export PS4="+ %* %F{red}%x:%I %F{green}%N:%i%F{white} %_"
  34. fi
  35. set -o xtrace
  36. fi
  37. export __array_start rvm_path >/dev/null
  38. #
  39. # Setup environment parameters.
  40. #
  41. if [[ -n "${ZSH_VERSION:-}" ]]
  42. then __array_start=1
  43. else __array_start=0
  44. fi
  45. if (( ${rvm_ignore_rvmrc:=0} == 0 ))
  46. then
  47. [[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
  48. rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  49. if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
  50. then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  51. fi
  52. for rvmrc in "${rvm_rvmrc_files[@]}"
  53. do
  54. if [[ -f "$rvmrc" ]]
  55. then
  56. # pre-gnu
  57. if GREP_OPTIONS="" \command \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
  58. then
  59. printf "%b" "
  60. Error:
  61. $rvmrc is for rvm settings only.
  62. rvm CLI may NOT be called from within $rvmrc.
  63. Skipping the loading of $rvmrc"
  64. return 1
  65. else
  66. source "$rvmrc"
  67. fi
  68. fi
  69. done
  70. unset rvm_rvmrc_files
  71. fi
  72. # duplication marker jdgkjnfnkjdngjkfnd4fd
  73. export rvm_path
  74. if [[ -z "${rvm_path:-}" ]]
  75. then
  76. if [[ -n "${BASH_SOURCE:-$_}" && -f "${BASH_SOURCE:-$_}" ]]
  77. then
  78. rvm_path="${BASH_SOURCE:-$_}"
  79. rvm_path="$( \command \cd "${rvm_path%/scripts/base}">/dev/null; pwd )"
  80. elif (( UID == 0 )) && [[ -d "/usr/local/rvm" ]]
  81. then rvm_path="/usr/local/rvm"
  82. elif [[ -d "${HOME}/.rvm" ]]
  83. then rvm_path="${HOME}/.rvm"
  84. elif [[ -d "/usr/local/rvm" ]]
  85. then rvm_path="/usr/local/rvm"
  86. else echo "Can't find rvm install!" 1>&2 ; exit 1
  87. fi
  88. fi
  89. true ${rvm_scripts_path:="$rvm_path/scripts"}
  90. # Load the general scripts.
  91. # Use rvm_base_except="selector", for example, to override the loading.
  92. load_rvm_scripts()
  93. {
  94. \typeset -a scripts
  95. scripts=(
  96. selector logging support utility init cleanup env rvmrc install environment gemset checksum list
  97. )
  98. source "${rvm_scripts_path}/initialize"
  99. for entry in ${scripts[@]}
  100. do
  101. [[ " ${rvm_base_except:-} " == *" $entry "* ]] ||
  102. source "${rvm_scripts_path}/functions/$entry" ||
  103. return $?
  104. done
  105. unset rvm_base_except
  106. }
  107. load_rvm_scripts