Sha256: 52e6527ea895741f069783cc9997fbc26ae2bc30020ac52532878701f18eafca

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

require 'open-uri'
require 'open3'
require 'fileutils'

module Helpers
  def self.efi?
    Dir.exist? '/sys/firmware/efi/efivars'
  end

  def self.get_file_online(url, dest)
    URI.open(url) do |l|
      File.open(dest, "wb") do |f|
        f.write(l.read)
      end
    end
  end

  def self.exec_or_die(cmd)
    _, stderr, status = Open3.capture3(cmd)
    unless status.success?
      raise "Problem running #{cmd}, stderr was:\n#{stderr}"
    end
  end

  def self.create_dir(path, perm = 0755)
    FileUtils.mkdir_p path, mode: perm if ! Dir.exist?(path)
  end

  def self.add_file(path, content = '')
    File.write path, content if ! File.exist? path
  end

  def self.emerge(pkgs, path)
    cmd = "chroot #{path} /bin/bash -c \"
      source /etc/profile
      emerge --changed-use #{pkgs}
    \""
    exec_or_die(cmd)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
getch-0.0.5 lib/getch/helpers.rb
getch-0.0.4 lib/getch/helpers.rb