smf 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #!/usr/bin/env bash
  2. requirements_find_smf()
  3. {
  4. if # find SMF in PATH
  5. __rvm_which sm >/dev/null 2>&1
  6. then
  7. return 0
  8. else # find SMF out of PATH and link to rvm/bin
  9. \typeset __binary
  10. for __binary in ~/.sm/bin/sm /opt/sm/bin/sm
  11. do
  12. if
  13. [[ -f "${__binary}" && -s "${__binary}" && -x "${__binary}" ]]
  14. then
  15. PATH="$PATH:${__binary%/*}"
  16. return 0
  17. fi
  18. done
  19. return 1
  20. fi
  21. }
  22. __smf_try_sudo()
  23. {
  24. if [[ -w "$( __rvm_which sm )" ]]
  25. then "$@"
  26. else __rvm_try_sudo "$@"
  27. fi
  28. }
  29. requirements_smf_lib_installed()
  30. {
  31. sm pkg list | __rvm_grep "^${1}:" >/dev/null || return $?
  32. }
  33. requirements_smf_lib_install_command()
  34. {
  35. __smf_install_command=( sm "$1" install )
  36. if
  37. [[ "${rvm_static_flag:-}" == "1" ]]
  38. then
  39. __smf_install_command=(
  40. /usr/bin/env CFLAGS="-fPIC" LDFLAGS="-fPIC" "${__smf_install_command[@]}" static
  41. )
  42. fi
  43. __smf_install_command=( __smf_try_sudo "${__smf_install_command[@]}" )
  44. }
  45. requirements_smf_lib_install()
  46. {
  47. \typeset -a __smf_install_command
  48. requirements_smf_lib_install_command "$@"
  49. rvm_debug "__smf_install_command: ${__smf_install_command[*]};"
  50. "${__smf_install_command[@]}" ||
  51. {
  52. \typeset ret=$?
  53. rvm_warn "There were package installation errors with SM Framework, make sure to read the log.
  54. If you see this on OSX, then you might want to try macports (https://www.macports.org/) or homebrew (http://brew.sh/) and tell RVM to use them by running:
  55. rvm autolibs macports #OR
  56. rvm autolibs homebrew
  57. You might get help by reporting tickets to https://github.com/sm/sm/issues"
  58. return $ret
  59. }
  60. shift
  61. }
  62. requirements_smf_gcc_42_check()
  63. {
  64. case "$1" in
  65. (ruby-2*|ruby-head) true ;; # ruby-2.0.0+ is supposed to work with clang
  66. (*)
  67. # install gcc-4.2 only if not yet available, prevents problems with gcc-4.2 on OSX 10.6
  68. if
  69. ! __rvm_which gcc-4.2 >/dev/null &&
  70. __rvm_compiler_is_llvm
  71. then
  72. rvm_error "SM Framework does not know how to install gcc-4.2, please install osx-gcc-installer first for older rubies."
  73. fi
  74. ;;
  75. esac
  76. }
  77. requirements_smf_install_extension_sets()
  78. {
  79. \typeset __set
  80. for __set
  81. do __smf_try_sudo sm set install "${__set}" || return $?
  82. done
  83. }
  84. requirements_smf_update_system_ensure_etc_openssl()
  85. {
  86. [[ -d "/etc/openssl" ]] || __rvm_try_sudo mkdir -p "/etc/openssl" || return $?
  87. [[ -w "/etc/openssl" ]] ||
  88. {
  89. __rvm_try_sudo chmod -R 755 "/etc/openssl" &&
  90. __rvm_try_sudo chown -R $USER "/etc/openssl"
  91. } || return $?
  92. }
  93. requirements_smf_update_system()
  94. {
  95. requirements_smf_update_system_ensure_etc_openssl || return $?
  96. __rvm_log_command sm_get_head "Updating SMF" __smf_try_sudo sm get head || return $?
  97. if
  98. [[ "${#required_extension_sets[@]}" -gt 0 ]]
  99. then
  100. __rvm_log_command sm_install_extension_sets "Installing/updating extension sets: ${required_extension_sets[*]}" \
  101. requirements_smf_install_extension_sets "${required_extension_sets[@]}" ||
  102. return $?
  103. fi
  104. }
  105. requirements_smf_define_git()
  106. {
  107. __rvm_which git >/dev/null || {
  108. required_extension_sets+=( vcs )
  109. requirements_check autoconf git || return $?
  110. }
  111. }
  112. requirements_smf_define()
  113. {
  114. case "$1" in
  115. (rvm)
  116. true
  117. ;;
  118. (jruby*)
  119. requirements_check make
  120. if
  121. is_head_or_disable_binary "$1"
  122. then
  123. requirements_smf_define_git || return $?
  124. case $( jruby_installation_method "$1" ) in
  125. ant) __rvm_which ant >/dev/null 2>&1 || return $? ;;
  126. mvn) requirements_check_custom_after mvn=maven ;;
  127. esac
  128. fi
  129. __rvm_which java >/dev/null 2>&1 || return $?
  130. ;;
  131. (ir*)
  132. __rvm_which mono >/dev/null 2>&1 || return $?
  133. ;;
  134. (opal)
  135. required_extension_sets+=( javascript )
  136. requirements_check node
  137. ;;
  138. (*-head)
  139. requirements_smf_define default
  140. requirements_smf_define_git || return $?
  141. ;;
  142. (*)
  143. required_extension_sets+=( databases gnu libraries tools )
  144. if
  145. [[ "${_system_name}" == "OSX" ]]
  146. then
  147. # TODO: ruby up to 1.9.3 requires openssl 0.9.8 on OSX
  148. if __rvm_version_compare "${_system_version}" -ge 10.9
  149. then requirements_check pkg-config libyaml zlib ncurses readline openssl sqlite3 gdbm
  150. else requirements_check pkg-config libtool libyaml zlib ncurses readline openssl sqlite3 gdbm
  151. fi
  152. else
  153. requirements_check pkg-config libtool libyaml zlib ncurses ncursesw readline openssl sqlite3 gdbm
  154. fi
  155. ;;
  156. esac
  157. }
  158. requirements_smf_install_sm()
  159. {
  160. rvm_error "SMF Framework support is only intended for RailsInstaller / Tokaido.app, please use Macports / Homebrew integration instead."
  161. return 100
  162. }
  163. requirements_smf_ensure_smf_available()
  164. {
  165. __rvm_which sm >/dev/null ||
  166. {
  167. rvm_requiremnts_fail_or_run_action 2 \
  168. "Requested installation with SM Framework, but SM Framework is not available." \
  169. requirements_smf_install_sm ||
  170. return $?
  171. }
  172. }
  173. requirements_smf_find_sm()
  174. {
  175. export __sm_path
  176. : __sm_path:${__sm_path:=$( __rvm_which sm )}
  177. __rvm_readlink_deep __sm_path
  178. [[ -n "${__sm_path}" ]] || return $?
  179. }
  180. requirements_smf_before()
  181. {
  182. required_extension_sets=()
  183. requirements_smf_ensure_smf_available || return $?
  184. requirements_smf_find_sm || return $?
  185. }
  186. requirements_smf_after()
  187. {
  188. requirements_smf_gcc_42_check "$1" || return $?
  189. if
  190. [[ "${_system_name}" == "OSX" ]]
  191. then
  192. case "$1" in
  193. (ruby-1*|ruby-2.0*)
  194. __rvm_update_configure_env LDFLAGS="-Z -L${__sm_path%/bin/sm}/pkg/active/lib -L/usr/lib"
  195. ;;
  196. (*) # 2.1.0+
  197. __rvm_update_configure_env LDFLAGS="-L${__sm_path%/bin/sm}/pkg/active/lib"
  198. ;;
  199. esac
  200. __rvm_update_configure_env CFLAGS="-I${__sm_path%/bin/sm}/pkg/active/include"
  201. fi
  202. case "$PATH" in
  203. (${__sm_path%/bin/sm}/pkg/active/bin:*)
  204. true
  205. ;;
  206. (*)
  207. __rvm_add_to_path prepend "${__sm_path%/bin/sm}/pkg/active/bin"
  208. ;;
  209. esac
  210. export PKG_CONFIG_PATH="${__sm_path%/bin/sm}/pkg/active/lib/pkgconfig"
  211. case "$1" in
  212. (jruby*) true ;;
  213. (*) requirements_smf_after_update_certs_openssl ;;
  214. esac
  215. }
  216. requirements_smf_after_update_certs_openssl()
  217. {
  218. requirements_osx_update_openssl_cert "${__sm_path%/bin/sm}/pkg/active/bin/openssl" || return $?
  219. }