Class: App::UtilsTools
- Inherits:
-
Object
- Object
- App::UtilsTools
- Defined in:
- lib/core/utils_tools.rb
Constant Summary collapse
- OS_WINDOWS =
'windows'
- OS_MAC =
'mac'
- OS_LINUX =
'linux'
- OS_UNIX =
'unix'
- OS_OTHER =
'other'
Class Method Summary collapse
-
.check_remote_is_reachable(host_address) ⇒ Object
Check that remote host is reachable.
-
.check_sshpass_is_installed ⇒ Object
Check that SSHPASS is installed.
-
.get_base_path ⇒ Object
Get PATH to assets, scripts, etc.
-
.os ⇒ Object
Get the operating system.
-
.ping(host_address, verbose = true) ⇒ Object
Ping a URL or IP and returns the exit status.
-
.this_is_a_mac ⇒ Object
Returns TRUE if Mac, FALSE if Linux (or anything else for that matter).
Class Method Details
.check_remote_is_reachable(host_address) ⇒ Object
Check that remote host is reachable.
23 24 25 26 27 |
# File 'lib/core/utils_tools.rb', line 23 def self.check_remote_is_reachable(host_address) if ping(host_address) != 0 App::Terminal::error('Cannot reach remote host', ["#{App::Terminal::format_highlight(host_address)} cannot be reached.", 'Please make sure the host is online and/or configured correctly.']) end end |
.check_sshpass_is_installed ⇒ Object
Check that SSHPASS is installed.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/core/utils_tools.rb', line 39 def self.check_sshpass_is_installed if @sshpass_installed.nil? sshpass_result = App::Terminal::command_capture('sshpass -h', nil, false, false) sshpass_result = sshpass_result[0].split(' ') unless sshpass_result[0].downcase == 'usage:' if this_is_a_mac = "Find how to install it at: #{App::Terminal::format_highlight('https://www.google.co.uk/search?q=install+sshpass+on+mac')}" else = "Install it using: #{App::Terminal::format_command('sudo apt-get install sshpass')}" end App::Terminal::error("#{App::Terminal::format_highlight('sshpass')} is not installed", , true) end @sshpass_installed = true end end |
.get_base_path ⇒ Object
Get PATH to assets, scripts, etc.
15 16 17 18 19 |
# File 'lib/core/utils_tools.rb', line 15 def self.get_base_path base_path = File.dirname(File.(__FILE__)) base_path = base_path.gsub(/\/\w+\/\w+\z/i, '') base_path end |
.os ⇒ Object
Get the operating system.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core/utils_tools.rb', line 63 def self.os @os ||= ( host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ OS_WINDOWS when /darwin|mac os/ OS_MAC when /linux/ OS_LINUX when /solaris|bsd/ OS_UNIX else OS_OTHER end ) end |
.ping(host_address, verbose = true) ⇒ Object
Ping a URL or IP and returns the exit status. 0 = success, anything else means it failed.
31 32 33 34 35 |
# File 'lib/core/utils_tools.rb', line 31 def self.ping(host_address, verbose = true) App::Terminal::output("Checking if #{App::Terminal::format_highlight(host_address)} is reachable...") if verbose == true `ping -t 1 -c 1 #{host_address}` $?.exitstatus end |
.this_is_a_mac ⇒ Object
Returns TRUE if Mac, FALSE if Linux (or anything else for that matter)
57 58 59 |
# File 'lib/core/utils_tools.rb', line 57 def self.this_is_a_mac return os == OS_MAC end |