base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/manage/base_fetch"
  3. source "$rvm_scripts_path/functions/manage/base_install"
  4. source "$rvm_scripts_path/functions/manage/base_install_patches"
  5. source "$rvm_scripts_path/functions/manage/base_remove"
  6. __rvm_uninstall_ruby()
  7. {
  8. __rvm_remove_ruby uninstall
  9. }
  10. __rvm_reinstall_ruby()
  11. {
  12. export pristine_gems_filter="! gem.extensions.empty?"
  13. __rvm_remove_ruby reinstall &&
  14. __rvm_install_ruby "$@" &&
  15. __rvm_gemset_pristine_all "$rvm_ruby_string"
  16. }
  17. __rvm_gemset_pristine_all()
  18. {
  19. if (( ${rvm_skip_pristine_flag:-0} ))
  20. then return 0
  21. fi
  22. case "$rvm_ruby_string" in
  23. (mruby*) return 0 ;;
  24. esac
  25. \typeset -a destination_gemsets
  26. \typeset destination_gemset
  27. __rvm_read_lines destination_gemsets <(
  28. __rvm_list_gemset_strings | __rvm_grep -E "^$1(@.*)?$"
  29. )
  30. for destination_gemset in "${destination_gemsets[@]}"
  31. do __rvm_gemset_pristine "$destination_gemset"
  32. done
  33. }
  34. __rvm_manage_rubies()
  35. {
  36. \typeset manage_result bin_line current_ruby_string
  37. \typeset -a rubies
  38. rubies=()
  39. rvm_gemset_name=""
  40. rvm_ruby_selected_flag=0
  41. rvm_ruby_gem_home="${rvm_ruby_gem_home%%${rvm_gemset_separator:-"@"}*}"
  42. rvm_ruby_string="${rvm_ruby_string%%${rvm_gemset_separator:-"@"}*}"
  43. # Given list of ruby strings.
  44. if
  45. __rvm_string_match "${rubies_string:-}" "old:*"
  46. then
  47. \typeset _older_then
  48. _older_then=${rubies_string#old:}
  49. if
  50. [[ -z "${_older_then}" ]]
  51. then
  52. # minified https://github.com/mpapis/home_dotfiles/blob/master/bin/git-summary#L5-L50
  53. case "${_system_type}" in
  54. (Darwin) _older_then="$( __rvm_date -j -v6m +%F )" ;;
  55. (*) _older_then="$( __rvm_date --date="-6months" +%F )" ;;
  56. esac
  57. fi
  58. __rvm_read_lines rubies <(
  59. __rvm_cd "$rvm_rubies_path"
  60. # find on bsd does not have -not, we need to use \!
  61. __rvm_find . -maxdepth 1 -mindepth 1 -type d \! -newermt $_older_then 2>/dev/null | cut -c 3-
  62. )
  63. (( ${#rubies[*]} )) ||
  64. {
  65. rvm_warn "No rubies older then ${_older_then}."
  66. return 1
  67. }
  68. __rvm_ask_for "Are you SURE you wish to '$action' ${rubies[*]}?" yes || return $?
  69. elif
  70. [[ -n "${rubies_string:-}" && "${rubies_string}" != "all" ]]
  71. then
  72. if
  73. [[ "${rubies_string}" == *,* || -z "${rvm_ruby_string:-}" ]]
  74. then
  75. __rvm_custom_separated_array rubies , "${rubies_string}"
  76. else
  77. rubies=( "${rvm_ruby_string}" )
  78. fi
  79. elif
  80. [[ "$action" == "install" ]]
  81. then
  82. rvm_error 'Really? '"$action"', all? See "rvm list known" and limit the selection to something more sane please :)'
  83. return 1
  84. elif
  85. [[ -z "${rubies_string}" ]]
  86. then
  87. rvm_error 'Really? '"$action"', all? See "rvm list" and limit the selection to something more sane please :)'
  88. return 1
  89. else
  90. # explicit all && not install
  91. if
  92. (( ${rvm_force_flag:-0} == 0 )) &&
  93. [[ "$action" == "reinstall" || "$action" == "remove" || "$action" == "uninstall" ]]
  94. then
  95. __rvm_ask_for "Are you SURE you wish to '$action' all rubies?" yes || return $?
  96. fi
  97. __rvm_read_lines rubies <(
  98. __rvm_cd "$rvm_rubies_path"
  99. __rvm_find . -maxdepth 1 -mindepth 1 -type d 2>/dev/null | cut -c 3-
  100. )
  101. fi
  102. for rvm_ruby_string in "${rubies[@]}"
  103. do
  104. rvm_debug "${rvm_ruby_string} - $action"
  105. current_ruby_string="$rvm_ruby_string"
  106. if
  107. # in () so it does not mess with env. variables
  108. (
  109. rvm_hook="before_install"
  110. source "$rvm_scripts_path/hook"
  111. __rvm_${action}_ruby
  112. )
  113. then
  114. if [[ "$action" == "install" ]]
  115. then __rvm_record_install "$current_ruby_string"
  116. fi
  117. else
  118. : manage_result:${manage_result:=$?}
  119. fi
  120. done
  121. return "${manage_result:-0}"
  122. }