mount 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. source "$rvm_scripts_path/functions/build"
  4. source "$rvm_scripts_path/functions/irbrc"
  5. source "$rvm_scripts_path/functions/osx-ssl-certs"
  6. source "$rvm_scripts_path/functions/rubygems"
  7. source "$rvm_scripts_path/functions/manage/truffleruby"
  8. external_automount()
  9. {
  10. external_mount_uniq $(
  11. __rvm_remove_rvm_from_path
  12. __rvm_which -a ruby
  13. )
  14. }
  15. external_reject_existing()
  16. {
  17. \typeset __check
  18. \typeset -a __existing __failed
  19. __failed=()
  20. __existing=( $(
  21. for ext in $rvm_rubies_path/ext-*/bin/ruby
  22. do
  23. if [[ -L "$ext" ]]
  24. then __rvm_readlink "$ext"
  25. fi
  26. done
  27. ) )
  28. rvm_debug "existing:${__existing[*]}:"
  29. for __check
  30. do
  31. if
  32. [[ " ${__existing[*]} " == *" ${__check} "* ]]
  33. then
  34. __failed+=( ${__check} )
  35. fi
  36. done
  37. if
  38. (( ${#__failed[@]} > 1 ))
  39. then
  40. rvm_error "The given paths '${__failed[*]}' are already mounted."
  41. elif
  42. (( ${#__failed[@]} > 0 ))
  43. then
  44. rvm_error "The given path '${__failed[*]}' is already mounted."
  45. fi
  46. return ${#__failed[@]}
  47. }
  48. external_mount_uniq()
  49. {
  50. \typeset ruby_path
  51. \typeset -a ruby_paths
  52. __rvm_read_lines ruby_paths <(
  53. for ruby_path in "$@"
  54. do
  55. if
  56. [[ -d "${ruby_path}" && -x "${ruby_path}/bin/ruby" ]]
  57. then
  58. echo "${ruby_path}/bin/ruby"
  59. elif
  60. [[ -f "${ruby_path}" && -x "${ruby_path}" ]]
  61. then
  62. echo "${ruby_path}"
  63. fi
  64. done | sort -u
  65. )
  66. if
  67. (( ${#ruby_paths[@]} == 0 ))
  68. then
  69. rvm_error "The given paths '$*' do not point to a ruby installation."
  70. return 1
  71. else
  72. external_reject_existing ${#ruby_paths[@]} || exit $?
  73. for ruby_path in ${ruby_paths[@]}
  74. do
  75. ( external_mount "${ruby_path}" ) || exit $?
  76. done
  77. fi
  78. }
  79. external_mount_link_default_binaries_detect_link()
  80. {
  81. rvm_debug "ruby_path:${ruby_path}"
  82. if
  83. [[ "${ruby_path##*/}" == "ruby" && -L "${ruby_path}" ]]
  84. then
  85. _binary_long="$( \command \readlink "${ruby_path}" )"
  86. case "${_binary_long}" in
  87. (/*)
  88. ruby_path="${_binary_long}"
  89. ;;
  90. (*/*)
  91. ruby_path="$( cd "${ruby_path}" ; cd "${_binary_long%/*}" ; pwd )${_binary_long##*/}"
  92. ;;
  93. (*)
  94. ruby_path="${ruby_path%ruby}${_binary_long}"
  95. ;;
  96. esac
  97. rvm_debug "linked ruby_path:${ruby_path}"
  98. fi
  99. }
  100. external_mount_link_default_binaries_detect_prefix_suffix()
  101. {
  102. _binary="${ruby_path##*/}"
  103. case "${_binary}" in
  104. (ruby)
  105. _binary_prefix=""
  106. _binary_suffix=""
  107. ;;
  108. (*ruby)
  109. _binary_prefix="${_binary%ruby}"
  110. _binary_suffix=""
  111. ;;
  112. (ruby*)
  113. _binary_prefix=""
  114. _binary_suffix="${_binary#ruby}"
  115. ;;
  116. esac
  117. rvm_debug "_binary_prefix:${_binary_prefix}: _binary_suffix:${_binary_suffix}:"
  118. }
  119. external_mount_link_default_binaries_create_links()
  120. {
  121. for _binary in "${_binaries[@]}"
  122. do
  123. _binary_long="${_binary_prefix}${_binary}${_binary_suffix}"
  124. # link short
  125. if
  126. [[ -e "${prefix_path}/bin/${_binary}" ]]
  127. then
  128. ln -s "${prefix_path}/bin/${_binary}" "${_target_path}/${_binary}"
  129. fi
  130. # link long
  131. if
  132. [[ -e "${prefix_path}/bin/${_binary_long}" && "${_binary_long}" != "${_binary}" ]]
  133. then
  134. ln -s "${prefix_path}/bin/${_binary_long}" "${_target_path}/${_binary_long}"
  135. # link short - long if there was no short
  136. [[ -e "${_target_path}/${_binary}" ]] ||
  137. ln -s "${prefix_path}/bin/${_binary_long}" "${_target_path}/${_binary}"
  138. fi
  139. # relink links
  140. if
  141. [[ -L "${prefix_path}/bin/${_binary}" ]]
  142. then
  143. _binary="$( __rvm_readlink "${prefix_path}/bin/${_binary}" )"
  144. case "${_binary}" in
  145. (*/*)
  146. true # skip relative paths
  147. ;;
  148. (*)
  149. [[ -e "${_target_path}/${_binary}" ]] || # avoid duplicate relinking
  150. ln -s "${prefix_path}/bin/${_binary}" "${_target_path}/${_binary}"
  151. ;;
  152. esac
  153. fi
  154. done
  155. }
  156. external_mount_link_default_binaries()
  157. {
  158. \typeset _binary _binary_prefix _binary_suffix _binary_long _target_path
  159. \typeset -a _binaries
  160. _binaries=( erb gem irb rake ri rdoc ruby testrb )
  161. external_mount_link_default_binaries_detect_link
  162. external_mount_link_default_binaries_detect_prefix_suffix
  163. _target_path="$rvm_rubies_path/$rvm_ruby_string/bin"
  164. mkdir -p "${_target_path}"
  165. external_mount_link_default_binaries_create_links
  166. }
  167. __rvm_osx_ssl_certs_ensure_for_ruby_except_jruby()
  168. {
  169. case "$1" in
  170. (jruby*) true ;;
  171. (*) __rvm_osx_ssl_certs_ensure_for_ruby "$2" ;;
  172. esac
  173. }
  174. external_mount()
  175. {
  176. \typeset _given_path ruby_path prefix_path
  177. _given_path="$1"
  178. if [[ ! -d "${_given_path}" && -x "${_given_path}" ]] && "${_given_path}" --version | __rvm_grep rub >/dev/null
  179. then
  180. ruby_path="${_given_path}"
  181. prefix_path="$( __rvm_ruby_config_get prefix "${_given_path}" )"
  182. elif [[ -d "${_given_path}" && -x "${_given_path}/bin/ruby" ]] && "${_given_path}/bin/ruby" --version | __rvm_grep rub >/dev/null
  183. then
  184. ruby_path="${_given_path}/bin/ruby"
  185. prefix_path="$( __rvm_ruby_config_get prefix "${ruby_path}" )"
  186. if [[ "${_given_path}" != "${prefix_path}" ]]
  187. then
  188. rvm_error "The given path '$_given_path' contains ruby but it has different prefix '$prefix_path'."
  189. exit 2
  190. fi
  191. else
  192. rvm_error "The given path '$_given_path' does not point to a ruby installation."
  193. exit 3
  194. fi
  195. if [[ -z "${rvm_ruby_string:-}" && -n "${rvm_ruby_name:-}" ]]
  196. then rvm_ruby_string="$rvm_ruby_name"
  197. fi
  198. if [[ -z "${rvm_ruby_string:-}" ]]
  199. then
  200. if ! external_select_name "${ruby_path}" "${prefix_path}" ||
  201. [[ -z "${rvm_ruby_string:-}" ]]
  202. then
  203. rvm_error "No name selected for ruby in '$prefix_path'."
  204. exit 4
  205. fi
  206. fi
  207. rvm_ruby_string="ext-${rvm_ruby_string}"
  208. echo "Mounting '${rvm_ruby_string}' from '${prefix_path}' with 'bin/${ruby_path##*/}'"
  209. external_mount_link_default_binaries
  210. mkdir -p "$rvm_gems_path/$rvm_ruby_string" "$rvm_gems_path/$rvm_ruby_string@global"
  211. __rvm_select "$rvm_ruby_string"
  212. __rvm_fix_rbconfig "$rvm_rubies_path/$rvm_ruby_string"
  213. __rvm_ruby_post_install_hook "$rvm_ruby_string" "$rvm_rubies_path/$rvm_ruby_string"
  214. __rvm_initial_gemsets_create_without_rubygems "$rvm_rubies_path/$rvm_ruby_string/bin/ruby"
  215. __rvm_irbrc
  216. __rvm_ruby_config_save "$ruby_path" "$rvm_rubies_path/$rvm_ruby_string/config"
  217. __rvm_fix_group_permissions "$rvm_rubies_path/$rvm_ruby_string"
  218. __rvm_record_install "$rvm_ruby_string"
  219. __rvm_osx_ssl_certs_ensure_for_ruby_except_jruby "$rvm_ruby_string" "$ruby_path"
  220. }
  221. external_select_name()
  222. {
  223. \typeset proposed_name ruby_version ruby_path prefix_path
  224. export rvm_ruby_string
  225. ruby_path="$1"
  226. prefix_path="$2"
  227. ruby_version="$( "${ruby_path}" --version)"
  228. if [[ -x "${ruby_path}" ]] &&
  229. proposed_name="$( external_propose_name "$ruby_version" )" &&
  230. [[ -n "${proposed_name:-}" ]]
  231. then
  232. echo "Found '${ruby_version}' in '${prefix_path}'"
  233. printf "\n# Please enter name [${proposed_name}]: "
  234. read rvm_ruby_string
  235. printf "\n"
  236. : rvm_ruby_string:${rvm_ruby_string:=${proposed_name}}:
  237. else
  238. echo "Name not found for '${ruby_path}' in '${prefix_path}'"
  239. false
  240. fi
  241. }
  242. external_propose_name()
  243. {
  244. \typeset parts __tmp1 __tmp2
  245. parts="$( echo "$1" | __rvm_sed 's/[()]//g; s/\[.*\]//;' )"
  246. case "${parts}" in
  247. (*Ruby[[:space:]]Enterprise[[:space:]]Edition*)
  248. __tmp1="${parts#* }"
  249. __tmp1="${__tmp1%% *}"
  250. __tmp2="${parts##* }"
  251. printf "ree-${__tmp1}-${__tmp2}"
  252. ;;
  253. (ruby[[:space:]]*patchlevel[[:space:]]*)
  254. __tmp1="${parts#* }"
  255. __tmp1="${__tmp1%% *}"
  256. __tmp2="${parts##*patchlevel }"
  257. __tmp2="${__tmp2%% *}"
  258. printf "ruby-${__tmp1}-p${__tmp2}"
  259. ;;
  260. (ruby[[:space:]][0-9].[0-9].[0-9]p[0-9]*)
  261. __tmp1="${parts#* }"
  262. __tmp1="${__tmp1%% *}"
  263. __tmp2="${__tmp1##+([0-9\.])}"
  264. __tmp1="${__tmp1%${__tmp2}}"
  265. printf "ruby-${__tmp1}-${__tmp2}"
  266. ;;
  267. (ruby[[:space:]]*revision[[:space:]]*|ruby[[:space:]]*trunk[[:space:]]*)
  268. __tmp1="${parts#* }"
  269. __tmp1="${__tmp1%% *}"
  270. __tmp2="${parts##*trunk }"
  271. __tmp2="${__tmp2##*revision }"
  272. __tmp2="${__tmp2%% *}"
  273. printf "ruby-${__tmp1}-r${__tmp2}"
  274. ;;
  275. (ruby[[:space:]]*)
  276. __tmp1="${parts#* }"
  277. __tmp1="${__tmp1%% *}"
  278. __tmp2="${__tmp1##+([0-9\.])}"
  279. __tmp1="${__tmp1%${__tmp2}}"
  280. printf "ruby-${__tmp1}-${__tmp2}"
  281. ;;
  282. (jruby[[:space:]]*)
  283. __tmp1="${parts#* }"
  284. __tmp1="${__tmp1%% *}"
  285. __tmp2="${parts#* }"
  286. __tmp2="${__tmp2#* }"
  287. __tmp2="${__tmp2%% *}"
  288. __tmp2="${__tmp2#ruby-}"
  289. __tmp2="${__tmp2//-/_}"
  290. printf "jruby-${__tmp1}-default_${__tmp2}"
  291. ;;
  292. (maglev[[:space:]]*)
  293. __tmp1="${parts#* }"
  294. __tmp1="${__tmp1%% *}"
  295. __tmp2="${parts#* }"
  296. __tmp2="${__tmp2#* }"
  297. __tmp2="${__tmp2#* }"
  298. __tmp2="${__tmp2%% *}"
  299. printf "maglev-${__tmp1}-default_${__tmp2}"
  300. ;;
  301. (topaz[[:space:]]*)
  302. __tmp1="${parts#* }"
  303. __tmp1="${__tmp1%% *}"
  304. __tmp2="${parts#* }"
  305. __tmp2="${__tmp2#* }"
  306. __tmp2="${__tmp2#* }"
  307. __tmp2="${__tmp2%% *}"
  308. printf "topaz-${__tmp1}-default_${__tmp2}"
  309. ;;
  310. (rubinius[[:space:]]*)
  311. __tmp1="${parts#* }"
  312. __tmp1="${__tmp1%% *}"
  313. __tmp2="${parts#* }"
  314. __tmp2="${__tmp2#* }"
  315. __tmp2="${__tmp2%% *}"
  316. printf "rbx-${__tmp1}-default_${__tmp2}"
  317. ;;
  318. (*)
  319. false
  320. ;;
  321. esac
  322. }
  323. external_import_configure()
  324. {
  325. \typeset platform architecture libc __flags
  326. if (( ${rvm_install_on_use_flag:-0} > 0 ))
  327. then err_command=rvm_warn
  328. else err_command=rvm_error
  329. fi
  330. rvm_ruby_url="$1"
  331. rvm_ruby_string="${2:-${rvm_ruby_name:-${rvm_ruby_url}}}"
  332. rvm_ruby_package_file=""
  333. # autodetect skips assignment of package name from URL
  334. __flags="$*"
  335. if
  336. [[ -r "${rvm_ruby_url}" ]]
  337. then
  338. if
  339. [[ "${__flags}" != *"autodetect"* ]]
  340. then
  341. rvm_ruby_package_file="${rvm_ruby_url##*/}"
  342. fi
  343. else
  344. case "${rvm_ruby_url}" in
  345. (http*)
  346. if
  347. [[ "${__flags}" != *"autodetect"* ]]
  348. then
  349. rvm_ruby_package_file="${rvm_ruby_url##*/}"
  350. # lets hope nobody uses the same file name with ?version=...
  351. rvm_ruby_package_file="${rvm_ruby_package_file%%\?*}"
  352. fi
  353. ;;
  354. (*)
  355. __rvm_ruby_string
  356. \typeset __rvm_ruby_verify_download_flag
  357. rvm_ruby_url="$( __rvm_remote_server_path "${rvm_ruby_string}" )"
  358. IFS=: read __rvm_ruby_verify_download_flag rvm_ruby_url <<<"$rvm_ruby_url"
  359. rvm_log "Found remote file ${rvm_ruby_url}"
  360. if
  361. (( ${__rvm_ruby_verify_download_flag:-0} > ${rvm_verify_downloads_flag_cli:-${rvm_verify_downloads_flag:-1}} ))
  362. then
  363. rvm_verify_downloads_flag=${__rvm_ruby_verify_download_flag}
  364. fi
  365. ;;
  366. esac
  367. fi
  368. rvm_ruby_string="${rvm_ruby_string##*/}"
  369. rvm_ruby_string="${rvm_ruby_string/bin-/}"
  370. rvm_ruby_string="${rvm_ruby_string%.t*}"
  371. if
  372. [[ -n "${rvm_ruby_name}" ]]
  373. then
  374. if
  375. [[ "${rvm_ruby_name}" == "${rvm_ruby_string}"* ]]
  376. then
  377. detected_rvm_ruby_name="${rvm_ruby_name#${rvm_ruby_string}-}"
  378. rvm_ruby_string="${rvm_ruby_name}"
  379. else
  380. detected_rvm_ruby_name="${rvm_ruby_name}"
  381. rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_name}"
  382. fi
  383. fi
  384. if
  385. [[ -z "${rvm_ruby_package_file:-}" ]]
  386. then
  387. __rvm_ruby_package_file "${rvm_ruby_string}"
  388. if
  389. [[ "${rvm_ruby_package_file}" == *bin-* ]]
  390. then
  391. rvm_ruby_package_file="${rvm_ruby_package_file##*/}"
  392. elif
  393. [[ "${rvm_ruby_url##*/}" == *bin-* ]]
  394. then
  395. rvm_ruby_package_file="${rvm_ruby_url##*/}"
  396. else
  397. rvm_ruby_package_file="bin-${rvm_ruby_string}.$(__rvm_remote_extension "${rvm_ruby_string}" -)"
  398. fi
  399. fi
  400. }
  401. external_import_download()
  402. {
  403. if
  404. [[ -r "${rvm_ruby_url}" ]]
  405. then
  406. [[ "${rvm_ruby_url}" == "$rvm_archives_path/${rvm_ruby_package_file}" ]] ||
  407. __rvm_cp -f "${rvm_ruby_url}" "$rvm_archives_path/${rvm_ruby_package_file}" || {
  408. $err_command "Copying ${rvm_ruby_url} failed."
  409. return 3
  410. }
  411. elif
  412. [[ -n "${rvm_ruby_url}" ]]
  413. then
  414. "$rvm_scripts_path/fetch" "${rvm_ruby_url}?rvm=${rvm_version%% *}" "${rvm_ruby_package_file}" || {
  415. $err_command "Downloading ${rvm_ruby_url} failed."
  416. return 2
  417. }
  418. else
  419. $err_command "No remote url detected for ${rvm_ruby_string}."
  420. return 4
  421. fi
  422. }
  423. external_import_validate_archive()
  424. {
  425. \typeset -a downloaded_names path_to_bin_ruby
  426. \typeset short_ruby_string
  427. __rvm_read_lines path_to_bin_ruby <(
  428. __rvm_package_list "$rvm_archives_path/${rvm_ruby_package_file}" | __rvm_grep "bin/ruby$" ||
  429. __rvm_package_list "$rvm_archives_path/${rvm_ruby_package_file}" | __rvm_grep "bin/jruby$"
  430. )
  431. __rvm_read_lines downloaded_names <(
  432. __rvm_package_list "$rvm_archives_path/${rvm_ruby_package_file}" | __rvm_awk -F/ '{print $1}' | sort -u
  433. )
  434. rvm_debug "downloaded_names:${#downloaded_names[@]}:${downloaded_names[*]}:"
  435. short_ruby_string="${rvm_ruby_string%-${detected_rvm_ruby_name:-}}"
  436. if
  437. [[ "${#path_to_bin_ruby[*]}" -eq 1 ]]
  438. then
  439. __path_to_extract="${path_to_bin_ruby[*]}"
  440. __path_to_extract="${__path_to_extract%bin/ruby}"
  441. __path_to_extract="${__path_to_extract%bin/jruby}"
  442. elif
  443. [[ "${short_ruby_string}" == "${downloaded_names[*]}" ]]
  444. then
  445. __path_to_extract="${short_ruby_string}"
  446. elif
  447. [[ "${short_ruby_string/-bin-/-}" == "${downloaded_names[*]}" ]]
  448. then
  449. if [[ -z "${rvm_ruby_string}" ]]
  450. then rvm_ruby_string="${short_ruby_string/-bin-/-}"
  451. fi
  452. __path_to_extract="${short_ruby_string}"
  453. elif
  454. [[ "${short_ruby_string/rbx-/rubinius-}" == "${downloaded_names[*]}" ]]
  455. then
  456. __path_to_extract="${short_ruby_string/rbx-/rubinius-}"
  457. else
  458. $err_command "The downloaded package for ${rvm_ruby_url},
  459. Does not contains single 'bin/ruby' or '${short_ruby_string}',
  460. Only '${downloaded_names[*]}' were found instead."
  461. return 4
  462. fi
  463. }
  464. external_import_extract()
  465. {
  466. \command \rm -rf "${rvm_rubies_path}/${rvm_ruby_string}"
  467. mkdir -p "${rvm_rubies_path}/${rvm_ruby_string}"
  468. __rvm_package_extract "$rvm_archives_path/${rvm_ruby_package_file}" "${rvm_rubies_path}/${rvm_ruby_string}" || {
  469. $err_command "Unpacking ${rvm_ruby_package_file} failed."
  470. return 6
  471. }
  472. if
  473. [[ -n "${__path_to_extract}" &&
  474. "${__path_to_extract}" != "/" &&
  475. "${__path_to_extract}" != "./"
  476. ]]
  477. then
  478. [[ -d "${rvm_rubies_path}/${rvm_ruby_string}/${__path_to_extract}/bin" ]] || {
  479. $err_command "Target directory '${__path_to_extract}' was not created,
  480. make sure '${rvm_ruby_url}' is a valid binary ruby archive."
  481. return 8
  482. }
  483. \command \mv "${rvm_rubies_path}/${rvm_ruby_string}/${__path_to_extract}"/* "${rvm_rubies_path}/${rvm_ruby_string}/"
  484. \command \rm -rf "${rvm_rubies_path}/${rvm_ruby_string}/${__path_to_extract%%/*}"
  485. fi
  486. }
  487. # validate libraries - make sure everything can be loaded
  488. external_import_validate_binary()
  489. {
  490. \typeset IFS
  491. \typeset -a found_libs missing_libs
  492. export _libdir
  493. _libdir="$( __rvm_ruby_config_get libdir "${rvm_rubies_path}/${rvm_ruby_string}/bin/ruby" )"
  494. case "${rvm_ruby_string}" in
  495. (*jruby*)
  496. case ${_system_type} in
  497. (Darwin)
  498. external_libdir="lib/{native,jni}/Darwin"
  499. ;;
  500. (*)
  501. external_libdir="lib/{native,jni}/${_system_arch}-${_system_type}"
  502. ;;
  503. esac
  504. ;;
  505. (*)
  506. external_libdir=""
  507. ;;
  508. esac
  509. missing_libs=()
  510. found_libs=()
  511. if [[ -x "${rvm_rubies_path}/${rvm_ruby_string}/bin/ruby" ]]
  512. then found_libs+=( "${rvm_rubies_path}/${rvm_ruby_string}/bin/ruby" )
  513. fi
  514. case ${_system_type} in
  515. (Linux|SunOS)
  516. found_libs+=( $(
  517. __rvm_find "${rvm_rubies_path}/${rvm_ruby_string}/${external_libdir}" -name '*.so' 2>/dev/null
  518. ) )
  519. if
  520. [[ -n "${found_libs[*]}" ]]
  521. then
  522. missing_libs=( $(
  523. LD_LIBRARY_PATH="${_libdir}" ldd "${found_libs[@]}" 2>/dev/null |
  524. __rvm_awk '/not found/{print $1}' | sort -u
  525. ) )
  526. fi
  527. ;;
  528. (Darwin)
  529. found_libs+=( $(
  530. __rvm_find "${rvm_rubies_path}/${rvm_ruby_string}/${external_libdir}" -name "*.bundle" 2>/dev/null
  531. ) )
  532. if
  533. [[ -n "${found_libs[*]}" ]]
  534. then
  535. missing_libs=( $(
  536. LD_LIBRARY_PATH="${_libdir}" otool -L "${found_libs[@]}" 2>&1 |
  537. __rvm_awk -F"[ :]" '{print $1}' |
  538. __rvm_sed 's#@executable_path#'"${rvm_rubies_path}/${rvm_ruby_string}"'/bin#' |
  539. __rvm_xargs __rvm_ls -1 2>&1 1>/dev/null |
  540. __rvm_awk -F"[ :]" '{print $3}' | sort -u
  541. ) )
  542. fi
  543. ;;
  544. (*)
  545. rvm_warn "$(command uname) libraries validation not yet implemented"
  546. ;;
  547. esac
  548. unset _libdir
  549. [[ -z "${missing_libs[*]}" ]] || {
  550. IFS=","
  551. $err_command "Libraries missing for ${rvm_ruby_string}: ${missing_libs[*]}. Refer to your system manual for installing libraries"
  552. return 10
  553. }
  554. }
  555. __rvm_fix_wrappers()
  556. {
  557. \typeset actual_file
  558. __rvm_find "$rvm_rubies_path/$rvm_ruby_string/bin/" -type f |
  559. while read actual_file
  560. do
  561. if
  562. [[ -s "$actual_file" ]]
  563. then
  564. __rvm_sed_i "$actual_file" \
  565. -e "/^ENV\[[\"']GEM_HOME[\"']\]=/ d" \
  566. -e "/^ENV\[[\"']GEM_PATH[\"']\]=/ d" \
  567. -e "/^ENV\[[\"']PATH[\"']\]=/ d"
  568. fi
  569. done
  570. if
  571. [[ ! -f "$rvm_rubies_path/$rvm_ruby_string/bin/ruby" ]] &&
  572. [[ -f "$rvm_rubies_path/$rvm_ruby_string/bin/jruby" ]]
  573. then
  574. ln -s "$rvm_rubies_path/$rvm_ruby_string/bin/jruby" "$rvm_rubies_path/$rvm_ruby_string/bin/ruby"
  575. fi
  576. }
  577. __rvm_fix_lib_files()
  578. {
  579. \typeset __path __file
  580. __path="$rvm_rubies_path/$rvm_ruby_string"
  581. __file="$( __rvm_find "${__path}" -name libyaml.la )"
  582. __rvm_sed_i "${__file}" -e "s#^libdir=.*\$#libdir='$(dirname "${__file}")'#"
  583. __rvm_find "${__path}" -name "*.pc" | while read __file
  584. do
  585. __rvm_sed_i "${__file}" -e "s#^prefix=.*\$#prefix=${__path}#"
  586. done
  587. }
  588. __rvm_ruby_post_install_hook()
  589. {
  590. case "$1" in
  591. truffleruby*)
  592. truffleruby_post_install_hook "$2"
  593. ;;
  594. *)
  595. ;;
  596. esac
  597. }
  598. external_import_setup()
  599. {
  600. __rvm_select
  601. __rvm_fix_wrappers
  602. __rvm_fix_lib_files
  603. __rvm_fix_rbconfig "$rvm_rubies_path/$rvm_ruby_string"
  604. __rvm_ruby_post_install_hook "$rvm_ruby_string" "$rvm_rubies_path/$rvm_ruby_string"
  605. __rvm_initial_gemsets_create_without_rubygems "$rvm_rubies_path/$rvm_ruby_string/bin/ruby"
  606. __rvm_irbrc
  607. __rvm_ruby_config_save "$rvm_rubies_path/$rvm_ruby_string/bin/ruby" "$rvm_rubies_path/$rvm_ruby_string/config"
  608. __rvm_record_install "$rvm_ruby_string"
  609. __rvm_osx_ssl_certs_ensure_for_ruby_except_jruby "$rvm_ruby_string" "$rvm_rubies_path/$rvm_ruby_string/bin/ruby"
  610. }
  611. external_import()
  612. {
  613. \typeset step err_command rvm_ruby_url rvm_ruby_string rvm_ruby_package_file __path_to_extract
  614. for step in configure download validate_archive extract validate_binary setup
  615. do
  616. rvm_log "${rvm_ruby_string:-${2:-$1}} - #${step//_/ }"
  617. external_import_${step} "$@" || return $?
  618. done
  619. }
  620. action="${1:-}"
  621. shift || {
  622. rvm_error_help "Missing action for external." mount
  623. exit 1
  624. }
  625. # skip first param if empty
  626. [[ -n "${1:-}" ]] || (( $#==0 )) || shift
  627. case "${action}" in
  628. (automount)
  629. external_automount "$@"
  630. ;;
  631. (mount|*_name)
  632. [[ -n "${1:-}" ]] ||
  633. {
  634. rvm_error_help "Missing path/url for '$action'." mount $action
  635. exit 2
  636. }
  637. if
  638. (( rvm_remote_flag > 0 )) ||
  639. [[ "$1" == http* || "$1" == *tar.bz2 ]]
  640. then
  641. external_import "$@"
  642. else
  643. external_mount_uniq "$@"
  644. fi
  645. ;;
  646. (*)
  647. rvm_error_help "Wrong action for mount '$action'." mount $action
  648. exit 2
  649. ;;
  650. esac