Sha256: 6d5643066568aacba6a99adddeaba752c950dffa3668f5ea7b77ba6d32a8c775

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'open-uri'
require 'open3'
require 'fileutils'
require_relative 'command'

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}
    \""
    Getch::Command.new(cmd).run!
  end

  def self.run_chroot(cmd, path)
    script = "chroot #{path} /bin/bash -c \"
      source /etc/profile
      #{cmd}
    \""
    Getch::Command.new(script).run!
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
getch-0.0.8 lib/getch/helpers.rb
getch-0.0.7 lib/getch/helpers.rb