container.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. set -e
  3. gems="$(ruby -e '
  4. # list taken from https://rubygems.org/stats
  5. gems = %w{
  6. bundler
  7. multi_json
  8. rake
  9. rack
  10. json
  11. mime-types
  12. activesupport
  13. thor
  14. i18n
  15. diff-lcs
  16. }
  17. # last updated 2017-11-15
  18. require "json"
  19. require "open-uri"
  20. # https://github.com/ruby/ruby/commit/05aac90a1bcfeb180f5e78ea8b00a4d1b04d5eed
  21. # https://bugs.ruby-lang.org/issues/15893
  22. # for Ruby 2.5+, we should use "URI.open", but for Ruby 2.4 we still need to use "open(...)" directly
  23. def openURI(uri)
  24. if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create("2.5")
  25. URI.open(uri)
  26. else
  27. open(uri)
  28. end
  29. end
  30. for gem in gems
  31. # ruby 2.2.2+: rack activesupport
  32. # ruby 2.0+: mime-types
  33. # (jruby 1.7 is ruby 1.9)
  34. gemRubyVersion = JSON.load(openURI("https://rubygems.org/api/v1/versions/#{ gem }.json"))[0]["ruby_version"]
  35. if Gem::Dependency.new("", gemRubyVersion).match?("", RUBY_VERSION)
  36. puts gem
  37. else
  38. STDERR.puts "skipping #{ gem } due to required Ruby version: #{ gemRubyVersion } (vs #{ RUBY_VERSION })"
  39. end
  40. end
  41. ')"
  42. for gem in $gems; do
  43. echo "$ gem install $gem"
  44. gem install "$gem"
  45. done