remotewrapper-gem 939 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. CONTEXT="$1"; shift
  3. ARGS=($@)
  4. if [ "$CONTEXT" = "-c" ]; then
  5. ARGS_ALL=($@)
  6. CONTEXT="${ARGS_ALL[0]}"
  7. ARGS=(${ARGS_ALL[@]:1})
  8. fi
  9. RUBYVERSION="${ARGS[0]}"
  10. CMD="${ARGS[1]}"
  11. ARGS=(${ARGS[@]:2})
  12. if [ "$CONTEXT" = "" ]; then
  13. echo " Error: /opt context is not set" >&2
  14. exit 2
  15. fi
  16. if [ "$RUBYVERSION" = "" ]; then
  17. echo " Error: Ruby version is not set" >&2
  18. exit 2
  19. fi
  20. run() {
  21. exec sudo context-chruby-run "$CONTEXT" "$RUBYVERSION" gem $@
  22. }
  23. forbidden() {
  24. echo ' This command is forbidden' >&2
  25. exit 1
  26. }
  27. help() {
  28. gem help $@ | sed -e 's/ gem/ srv0-gem/g'
  29. exit 0
  30. }
  31. cmd_proc() {
  32. case "$CMD" in
  33. install)
  34. run install $@
  35. ;;
  36. list)
  37. run list $@
  38. ;;
  39. env)
  40. run env $@
  41. ;;
  42. build)
  43. forbidden $@
  44. ;;
  45. server)
  46. forbidden $@
  47. ;;
  48. help)
  49. help $@
  50. ;;
  51. "")
  52. help $@
  53. ;;
  54. *)
  55. #exec gem help
  56. echo " Unknown or forbidden command $CMD" >&2
  57. exit 1
  58. ;;
  59. esac
  60. }
  61. cmd_proc $ARGS