checks.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Helps with finding current OS
  2. module OS
  3. def OS.windows?
  4. (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
  5. end
  6. def OS.mac?
  7. (/darwin/ =~ RUBY_PLATFORM) != nil
  8. end
  9. def OS.unix?
  10. !OS.windows?
  11. end
  12. def OS.linux?
  13. OS.unix? and not OS.mac?
  14. end
  15. end
  16. # Helps with finding current OS
  17. module ARCH
  18. def ARCH.is64?
  19. (/x86_64/ =~ RUBY_PLATFORM) != nil
  20. end
  21. def ARCH.is32?
  22. !ARCH.is64?
  23. end
  24. end
  25. def get_provider()
  26. # Workaround for mitchellh/vagrant#1867
  27. if (ARGV[1] and ARGV[1].split('=')[0] == "--provider" and ARGV[1].split('=')[1])
  28. provider = ARGV[1].split('=')[1].to_sym
  29. else
  30. provider = (ARGV[2] || ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
  31. end
  32. provider
  33. end
  34. def check_provider_needs(provider)
  35. if provider == :"aws"
  36. check_aws_needs
  37. elsif provider == :"virtualbox"
  38. check_vb_needs
  39. end
  40. end
  41. def check_aws_needs()
  42. # Check required variables
  43. if !(ENV['TFB_AWS_ACCESS_KEY'] and ENV['TFB_AWS_SECRET_KEY'] \
  44. and ENV['TFB_AWS_KEY_NAME'] and ENV['TFB_AWS_KEY_PATH'])
  45. abort 'If you want to use the AWS provider, you must provide these four variables:
  46. TFB_AWS_ACCESS_KEY : Your Amazon Web Services Access Key
  47. TFB_AWS_SECRET_KEY : Your Amazon Web Services Secret Access Key
  48. TFB_AWS_KEY_NAME : The name of the keypair you are using
  49. TFB_AWS_KEY_PATH : Path to the *.pem file for the keypair you are using'
  50. end
  51. # Print warning
  52. warning = "\033[33m\
  53. WARNING: FrameworkBenchmarks is disabling folder sync between your
  54. local working copy and Amazon Web Services - the ~/FrameworkBenchmarks
  55. directory in your VM will be a git clone of TechEmpower/FrameworkBenchmarks.
  56. You can re-enable folder sync using
  57. $ TFB_FORCE_SYNC=true vagrant up --provider=aws
  58. but be aware that you will need to upload ~2GB to Amazon before you can use
  59. the VM as normal.\033[0m"
  60. puts warning
  61. end
  62. def check_vb_needs()
  63. # Check if this computer can run a 64-bit OS
  64. warning = "\033[31m\
  65. WARNING: FrameworkBenchmarks only officially supports a 64-bit
  66. virtual machine, which your current system may not be able to
  67. support. Use `TFB_SHOW_VM=true vagrant up` to watch the VM launch -
  68. if you just see a black window you likely cannot run a 64-bit VM.
  69. To workaround, consider using the Amazon (e.g. AWS) provider
  70. $ vagrant up --provider=aws
  71. Or forcing FrameworkBenchmarks to attempt a 32-bit VM
  72. $ TFB_VB_ARCH=32 vagrant up
  73. See http://askubuntu.com/questions/41550 for more info\033[0m"
  74. # AMD-based needs svm feature, Intel-based needs vmx feature
  75. if OS.linux? and %x(egrep '(vmx|svm)' /proc/cpuinfo).empty?
  76. puts warning
  77. end
  78. # Ignore PowerPC, check for intel features
  79. if OS.mac? and %x(sysctl -n machdep.cpu.features | grep -i vmx).empty?
  80. puts warning
  81. end
  82. # Don't really know how to check CPU features, so I'll just check
  83. # the arch
  84. if OS.windows? and ARCH.is32?
  85. puts warning
  86. end
  87. end