prepare 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. external_prepare()
  4. {
  5. \typeset remote_shell
  6. rvm_ruby_string="${1:-}"
  7. remote_shell="${2:-}"
  8. shift || [[ -n "${rvm_ruby_string}" ]] || {
  9. rvm_error_help "Missing ruby name to export for prepare." external prepare
  10. return 3
  11. }
  12. __rvm_ruby_string
  13. __rvm_remote_extension "${rvm_ruby_string}"
  14. external_prepare_package "${rvm_ruby_string}.${rvm_remote_extension}" &&
  15. external_prepare_upload "${rvm_ruby_string}.${rvm_remote_extension}" "${remote_shell}"
  16. }
  17. external_prepare_package()
  18. {
  19. \typeset file_name
  20. file_name="$1"
  21. [[ -d "${rvm_rubies_path}/${rvm_ruby_string}" ]] ||
  22. {
  23. rvm_error "Ruby ${rvm_ruby_string} does not exist, maybe install first?."
  24. return 2
  25. }
  26. rvm_log "Preparing ${rvm_ruby_string} ..."
  27. if
  28. __rvm_package_create "${file_name}" "${rvm_rubies_path}" "${rvm_ruby_string}"
  29. then
  30. rvm_log "Prepared ${file_name}."
  31. else
  32. case $? in
  33. 199)
  34. rvm_error "Unrecognized archive format for ${file_name}"
  35. return 199
  36. ;;
  37. *)
  38. rvm_error "Error packaging ${file_name}."
  39. return 1
  40. ;;
  41. esac
  42. fi
  43. }
  44. #TODO: move to SMF ! RVM2 ?
  45. external_prepare_upload()
  46. {
  47. \typeset remote_path remote_shell remote_directory system_path __remote_file file_name local_file path_prefix
  48. file_name="$1"
  49. remote_path="${2:-rvm@ssh.rvm.io:~/site/shared/public/binaries}"
  50. system_path="$(__rvm_system_path - 99 )"
  51. remote_directory="${remote_path#*:}/${system_path}"
  52. remote_shell="${remote_path%:*}"
  53. if
  54. [[ ${rvm_path_flag:-0} -eq 1 ]]
  55. then
  56. path_prefix="${remote_path#*:}"
  57. path_prefix="${path_prefix##*/}"
  58. mkdir -p "${path_prefix}/${system_path}"
  59. local_file="${path_prefix}/${system_path}/${file_name}"
  60. \command \mv "${file_name}" "${local_file}"
  61. else
  62. local_file="${file_name}"
  63. fi
  64. __rvm_calculate_remote_file 0 1 1 "${file_name}"
  65. rvm_log "--- upload:"
  66. printf "%b" "ssh \"$remote_shell\" \"mkdir -p $remote_directory/\"\n"
  67. if
  68. [[ ${rvm_path_flag:-0} -eq 1 ]]
  69. then
  70. printf "%b" "rsync -av --rsh=ssh \"${path_prefix}/\" \"${remote_path}/\"\n"
  71. else
  72. printf "%b" "scp \"${local_file}\" \"$remote_shell:$remote_directory/${file_name}\"\n"
  73. fi
  74. rvm_log "--- rvm/config/remote:"
  75. printf "%b" "${__remote_file}\n"
  76. rvm_log "--- rvm/config/md5:"
  77. printf "%b" "${__remote_file}=$( __rvm_md5_calculate "${local_file}" )\n"
  78. rvm_log "--- rvm/config/sha512:"
  79. printf "%b" "${__remote_file}=$( __rvm_sha__calculate 512 "${local_file}" )\n"
  80. }
  81. action="${1:-}"
  82. shift || {
  83. rvm_error_help "Missing action for prepare." prepare
  84. exit 1
  85. }
  86. # skip first param if empty
  87. [[ -n "${1:-}" ]] || (( $#==0 )) || shift
  88. case "${action}" in
  89. (prepare)
  90. external_prepare "$@"
  91. ;;
  92. (*)
  93. rvm_error_help "Wrong action for prepare '$action'." prepare $action
  94. exit 2
  95. ;;
  96. esac