osx-ssl-certs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/osx-ssl-certs"
  3. source "$rvm_scripts_path/functions/osx-ssl-certs-curl"
  4. __rvm_osx_ssl_certs_run_select_rubies()
  5. {
  6. case "$2" in
  7. (all)
  8. __rvm_read_lines __rubies <(
  9. __rvm_cd "$rvm_rubies_path"
  10. __rvm_find . -maxdepth 1 -mindepth 1 -type d 2>/dev/null | cut -c 3-
  11. )
  12. __rubies+=(curl)
  13. ;;
  14. (*,*)
  15. __rvm_custom_separated_array __rubies , "$2"
  16. ;;
  17. ("")
  18. __rubies=( "${GEM_HOME##*/}" )
  19. ;;
  20. (*)
  21. __rubies=( "$2" )
  22. ;;
  23. esac
  24. rvm_log "Selected SSL certs for: $__rubies"
  25. }
  26. __rvm_osx_ssl_certs_run_filter_and_run()
  27. {
  28. \typeset cert_file
  29. for __ruby in "${__rubies[@]}"
  30. do
  31. if
  32. [[ "${__ruby}" == "curl" ]]
  33. then
  34. rvm_debug "Getting SSL certs path for ${__ruby}"
  35. __path=$(__rvm_osx_ssl_certs_curl_cert_find_path)
  36. [[ -z $__path || " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
  37. elif
  38. [[ -f "${__ruby}" && -x "${__ruby}" ]]
  39. then
  40. rvm_debug "Getting SSL certs for ${__ruby}"
  41. __rvm_osx_ssl_certs_file_from_openssl "${__ruby}" || return $?
  42. __path="$cert_file"
  43. [[ " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
  44. elif
  45. [[ -f "${__ruby}" ]] &&
  46. __rvm_grep -- "-----BEGIN CERTIFICATE-----" "${__ruby}" 1>/dev/null 2>&1
  47. then
  48. rvm_debug "SSL certs file for ${__ruby}"
  49. [[ " ${__paths[*]} " == *" ${__ruby} "* ]] || __paths+=( "${__ruby}" )
  50. elif
  51. [[ -d "${__ruby}" ]]
  52. then
  53. rvm_debug "SSL certs path for ${__ruby}"
  54. [[ " ${__paths[*]} " == *" ${__ruby} "* ]] || __paths+=( "${__ruby}" )
  55. else
  56. rvm_debug "Getting ruby certs path for ${__ruby}"
  57. __path="$( __rvm_with "${__ruby}" "__rvm_osx_ssl_certs_file_for_ruby" )"
  58. [[ " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
  59. fi
  60. done
  61. for __path in "${__paths[@]}"
  62. do
  63. rvm_debug "Updating SSL certs ${__path}"
  64. "$1" "${__path}"
  65. done
  66. }
  67. __rvm_osx_ssl_certs_run()
  68. {
  69. \typeset __ruby __path
  70. \typeset -a __rubies __paths
  71. __rubies=()
  72. __paths=()
  73. __rvm_osx_ssl_certs_run_select_rubies "$@"
  74. __rvm_osx_ssl_certs_run_filter_and_run "$@"
  75. }
  76. __rvm_osx_ssl_certs_status()
  77. {
  78. __rvm_osx_ssl_certs_run __rvm_osx_ssl_certs_status_for_path "$1"
  79. }
  80. __rvm_osx_ssl_certs_update()
  81. {
  82. __rvm_osx_ssl_certs_run __rvm_osx_ssl_certs_update_for_path "$1"
  83. }
  84. __rvm_osx_ssl_certs_cron_status()
  85. {
  86. if __rvm_cron_find "$RVM_OSX_SSL_UPDATER"
  87. then rvm_log "Automatic certs updating installed."
  88. else rvm_warn "Automatic certs updating not installed."
  89. fi
  90. }
  91. __rvm_osx_ssl_certs_cron_install()
  92. {
  93. if
  94. __rvm_cron_find "$RVM_OSX_SSL_UPDATER"
  95. then
  96. __rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER" ||
  97. {
  98. \typeset result=$?
  99. rvm_error "Automatic certs updating failed uninstalling."
  100. return $result
  101. }
  102. fi
  103. if
  104. __rvm_cron_install "$RVM_OSX_SSL_UPDATER"
  105. then
  106. rvm_log "Automatic certs updating installed."
  107. else
  108. \typeset result=$?
  109. rvm_error "Automatic certs updating failed installing."
  110. return $result
  111. fi
  112. }
  113. __rvm_osx_ssl_certs_cron_uninstall()
  114. {
  115. if
  116. __rvm_cron_find "$RVM_OSX_SSL_UPDATER"
  117. then
  118. if
  119. __rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER"
  120. then
  121. rvm_log "Automatic certs updating uninstalled."
  122. else
  123. \typeset result=$?
  124. rvm_error "Automatic certs updating failed uninstalling."
  125. return $result
  126. fi
  127. else
  128. rvm_log "Automatic certs updating already uninstalled."
  129. fi
  130. }
  131. __rvm_osx_ssl_certs_cron()
  132. {
  133. \typeset cron_action="${1:-status}"
  134. shift 1
  135. case "${cron_action}" in
  136. (status|install|uninstall)
  137. __rvm_osx_ssl_certs_cron_${cron_action}
  138. ;;
  139. (help)
  140. rvm_help osx-ssl-certs cron "$@"
  141. ;;
  142. (*)
  143. rvm_error_help "Unknown subcommand '$*' for osx-ssl-certs cron" osx-ssl-certs cron "$@"
  144. return 1
  145. ;;
  146. esac
  147. }
  148. __rvm_osx_ssl_certs()
  149. {
  150. \typeset action="${1:-status}"
  151. shift 1
  152. case "${action}" in
  153. (status|update|cron)
  154. if
  155. [[ "${_system_name}" == "OSX" ]]
  156. then
  157. __rvm_osx_ssl_certs_${action} "$@"
  158. else
  159. rvm_error "'rvm osx-ssl-certs' is intended only for OSX systems, it is not required on ${_system_name}."
  160. return 1
  161. fi
  162. ;;
  163. (help)
  164. rvm_help osx-ssl-certs "$@"
  165. ;;
  166. (*)
  167. rvm_error_help "Unknown subcommand '$*' for osx-ssl-certs" osx-ssl-certs "$@"
  168. return 1
  169. ;;
  170. esac
  171. }
  172. __rvm_osx_ssl_certs "${args[@]}"