Module: Sambot::Runtime

Defined in:
lib/sambot/runtime.rb

Class Method Summary collapse

Class Method Details

.ensure_latestObject



13
14
15
16
17
18
19
20
# File 'lib/sambot/runtime.rb', line 13

def self.ensure_latest
  latest_version = Gems.new.versions('sambot')[0]["number"]
  UI.debug("Current version is #{Sambot::VERSION}")
  UI.debug("Latest version is #{latest_version}")
  if is_obsolete
    UI.info('A newer version of this gem exists - please update the gem before continuing')
  end
end

.is_obsoleteObject



8
9
10
11
# File 'lib/sambot/runtime.rb', line 8

def self.is_obsolete
  latest_version = Gems.new.versions('sambot')[0]["number"]
  Gem::Version.new(Sambot::VERSION) < Gem::Version.new(latest_version)
end

.sudo(command, flag_errors: true) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sambot/runtime.rb', line 22

def self.sudo(command, flag_errors: true)
  UI.warn("Running the command `sudo -S #{command}`")
  output = ''
  Open4::popen4("sudo -S #{command}") do |pid, stdin, stdout, stderr|
    stdin.puts ENV['SAMBOT_SUDO_PASSWORD']
    stdin.close
    output = stdout.read
    err = stderr.read
    if flag_errors && err.strip.size > 0
      UI.error(err)
      exit -1
    end
  end
  output
end