Module: Hobo::Lib::HostCheck
- Extended by:
- HostCheck
- Included in:
- HostCheck
- Defined in:
- lib/hobo/lib/host_check.rb,
lib/hobo/lib/host_check/git.rb,
lib/hobo/lib/host_check/deps.rb,
lib/hobo/lib/host_check/hobo.rb,
lib/hobo/lib/host_check/ruby.rb,
lib/hobo/lib/host_check/vagrant.rb
Class Method Summary collapse
Instance Method Summary collapse
- #git_autocrlf_disabled(opts) ⇒ Object
- #git_config_email_set(opts) ⇒ Object
- #git_config_name_set(opts) ⇒ Object
- #git_present(opts) ⇒ Object
- #latest_hobo_version(opts) ⇒ Object
- #not_using_system_ruby(opts) ⇒ Object
- #php_present(opts) ⇒ Object
- #ssh_present(opts) ⇒ Object
- #system_paths_for_ruby(opts) ⇒ Object
- #vagrant_version(opts) ⇒ Object
Class Method Details
.check(opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hobo/lib/host_check.rb', line 6 def check opts = {} opts = { :filter => nil, :raise => false }.merge(opts) results = {} methods = Hobo::Lib::HostCheck.public_instance_methods(false) methods.each do |method| next if opts[:filter] && !method.match(opts[:filter]) if opts[:raise] self.send method, opts else begin self.send method, opts results[method] = :ok rescue Hobo::Error => error results[method] = error end end end return results end |
Instance Method Details
#git_autocrlf_disabled(opts) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/hobo/lib/host_check/git.rb', line 48 def git_autocrlf_disabled opts return unless Hobo.windows? advice = <<-EOF You're using git with the core.autocrlf option enabled. This setting can often cause problems when you clone a repository on windows but need to execute the contents of that repository within a linux VM. You can disable autocrlf globally with the following command: git config --global core.autocrlf false Disabling this setting will cause git to see all line endings as changed in a repository that was cloned with it enabled. As such, you must either enable it just for those repositories or delete and re-clone them with the setting disabled. You can enable the setting on a per-clone basis by ensuring that you are in the project directory and executing the following command: git config core-autocrlf true EOF begin value = shell "git config core.autocrlf", :capture => true if value != "false" raise Hobo::HostCheckError.new("Git config has autocrlf enabled", advice) end rescue Hobo::ExternalCommandError # NOP end end |
#git_config_email_set(opts) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hobo/lib/host_check/git.rb', line 33 def git_config_email_set opts advice = <<-EOF You have not set your email in git config! Please do so with the following command: git config --global user.email <your email here> EOF begin shell "git config user.email" rescue Hobo::ExternalCommandError raise Hobo::HostCheckError.new("Git config is incomplete (Email)", advice) end end |
#git_config_name_set(opts) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hobo/lib/host_check/git.rb', line 19 def git_config_name_set opts advice = <<-EOF You have not set your name in git config! Please do so with the following command: git config --global user.name <your name here> EOF begin shell "git config user.name" rescue Hobo::ExternalCommandError raise Hobo::HostCheckError.new("Git config is incomplete (Full name)", advice) end end |
#git_present(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hobo/lib/host_check/git.rb', line 4 def git_present opts advice = "The Git command could not be detected on your system.\n\n" if Hobo.windows? advice += "Please install it from http://git-scm.com/downloads ensuring you select the 'Use git and unix tools everywhere' option." else advice += "Please install it using your package manager." end begin shell "git --version" rescue Errno::ENOENT raise Hobo::HostCheckError.new("Git is missing", advice) end end |
#latest_hobo_version(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hobo/lib/host_check/hobo.rb', line 4 def latest_hobo_version opts require 'semantic' installed = ::Semantic::Version.new Hobo::VERSION return if installed >= get_latest_hobo_version if opts[:raise] answer = Hobo.ui.ask("A new version of hobo is available. Would you like to install it?", :default => 'y') if answer =~ /^[yY](es)?/ Hobo.ui.success "Installing new version... please wait" shell "gem install hobo-inviqa", :realtime => true Hobo.ui.success "Installed" Hobo.relaunch! end else raise Hobo::HostCheckError.new("A new version of hobo is available", "Install it with `gem install hobo-inviqa`") end end |
#not_using_system_ruby(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hobo/lib/host_check/ruby.rb', line 4 def not_using_system_ruby opts return if Hobo.windows? advice = <<-EOF You're using a system ruby install which can cause issues with installing Gems and running some older projects. rbenv is HIGHLY recommended. You can install it with the following command: curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash Once installed, run the following to set it as the default ruby and re-install hobo-inviqa: rbenv install 1.9.3-p448 && rbenv global 1.9.3-448 && gem install hobo-inviqa EOF require "rbconfig" which = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]) unless which =~ /\.rbenv|\.rvm|jruby/ raise Hobo::HostCheckError.new("Hobo is running under a system ruby", advice) end end |
#php_present(opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hobo/lib/host_check/deps.rb', line 20 def php_present opts advice = <<-EOF The PHP command could not be located on your system. This is an optional command that can speed up composer dependency installs. Please install it from your package manager ensuring that the following command does not produce any errors: php -r "readfile('https://getcomposer.org/installer');" | php EOF begin shell "php --version" rescue Errno::ENOENT raise Hobo::HostCheckError.new("PHP is missing", advice) end end |
#ssh_present(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hobo/lib/host_check/deps.rb', line 4 def ssh_present opts advice = "The SSH command could not be located on your system.\n\n" if Hobo.windows? advice += "To make SSH available you must re-install git using the installer from http://git-scm.com/downloads ensuring you select the 'Use git and unix tools everywhere' option." else advice += "Please install openssh using your package manager." end begin shell "ssh -V" rescue Errno::ENOENT raise Hobo::HostCheckError.new("SSH is missing", advice) end end |
#system_paths_for_ruby(opts) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hobo/lib/host_check/ruby.rb', line 24 def system_paths_for_ruby opts return if Hobo.windows? advice = <<-EOF The ordering of your system paths may cause a problem with Gems. Unfortunately we can't automatically fix this for you at this time. Please seek assistance. Your paths were detected as: #{ENV['PATH'].split(':').join("\n")} EOF paths = ENV['PATH'].split(':') system_path_found = false ruby_path_found = false paths.each do |path| system_before_ruby = system_path_found && !ruby_path_found ruby_after_system = path =~ /\.rbenv|\.rvm/ && system_path_found raise Hobo::HostCheckError.new("System paths appear to be mis-ordered", advice) if system_before_ruby or ruby_after_system ruby_path_found = true if path =~ /\.rbenv|\.rvm/ system_path_found = true if path =~ /\/usr\/bin|\/usr\/local\/bin/ end end |
#vagrant_version(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hobo/lib/host_check/vagrant.rb', line 4 def vagrant_version opts require 'semantic' begin version = shell "vagrant --version", :capture => true version.gsub!(/^Vagrant[^0-9]+/, '') version = ::Semantic::Version.new version.strip minimum_version = ::Semantic::Version.new "1.3.5" advice = <<-EOF The version of vagrant which you are using (#{version}) is less than the minimum required (#{minimum_version}). Please go to http://www.vagrantup.com/downloads.html and download the latest version for your platform. EOF raise Hobo::HostCheckError.new("Vagrant is too old!", advice) if version < minimum_version rescue Errno::ENOENT advice = <<-EOF Vagrant could not be detected on the path! Please go to http://www.vagrantup.com/downloads.html and download the latest version for your platform. EOF raise Hobo::HostCheckError.new("Vagrant is not on the path", advice) rescue Hobo::ExternalCommandError => error advice = <<-EOF Vagrant produced an error while checking its presence. This is usually caused by using the vagrant gem which is no longer supported. Uninstall any gem version of vagrant with the following command selecting "yes" to any prompt: gem uninstall vagrant You can then download and install the latest version from http://www.vagrantup.com/downloads.html If you do not have any vagrant gems installed it may be possible that a gem such as vagrant-wrapper is installed and is failing. Please seek assistance from #devops if this is the case. EOF raise Hobo::HostCheckError.new("Vagrant produced an error while checking presence", advice) end end |