opal 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. opal_install()
  3. {
  4. rvm_log "Running Opal prereqs checking script."
  5. __rvm_which node > /dev/null &&
  6. __rvm_which npm > /dev/null ||
  7. {
  8. result=$?
  9. rvm_error "Prerequisite checks have failed - can not find 'node' and/or 'npm' commands.
  10. Halting the installation."
  11. return $result
  12. }
  13. __rvm_log_command "prepare_directories" \
  14. "Preparing directories for opal" \
  15. opal_install_prepare_directories
  16. __rvm_cd "${rvm_ruby_home}"
  17. system="${_system_type}"
  18. arch="$(file "$( __rvm_which node)" )"
  19. arch="$(echo "${arch##* }" )"
  20. if
  21. node_binary="$(
  22. __rvm_which opal-node 2>/dev/null ||
  23. npm explore opal -- which bin/opal-node 2>/dev/null
  24. )"
  25. then
  26. rvm_log "Found opal-node at $node_binary"
  27. else
  28. __rvm_log_command "npm.install.opal" \
  29. "Installing opal-node globally" \
  30. npm install -g opal ||
  31. return $result
  32. node_binary="$(
  33. npm explore opal -- which bin/opal-node 2>/dev/null
  34. )"
  35. fi
  36. __rvm_log_command "install" \
  37. "Installing opal to $rvm_ruby_home" \
  38. opal_install_files
  39. }
  40. opal_install_prepare_directories()
  41. {
  42. __rvm_rm_rf "$rvm_ruby_home" &&
  43. \command \mkdir -vp "${rvm_ruby_home}/bin/" &&
  44. \command \mkdir -vp "$rvm_ruby_gem_home/bin" &&
  45. \command \mkdir -vp "$rvm_ruby_global_gems_path/bin" ||
  46. return $?
  47. }
  48. opal_install_files()
  49. {
  50. __rvm_cd "$rvm_ruby_home/bin/"
  51. ln -fs "$node_binary" "ruby"
  52. cat <<-FAKE_GEM > gem
  53. #!/usr/bin/env bash
  54. echo "OPAL FAKE GEM COMMAND: $@"
  55. exit 127
  56. FAKE_GEM
  57. chmod +x ruby gem
  58. cat <<-FAKE_CONFIG > "$rvm_ruby_home/config"
  59. target_cpu=$arch
  60. FAKE_CONFIG
  61. }