class Akabei::ChrootTree

Constants

BASE_PACKAGES

Attributes

arch[R]
root[R]

Public Class Methods

new(root, arch) click to toggle source
# File lib/akabei/chroot_tree.rb, line 13
def initialize(root, arch)
  @root = root && Pathname.new(root).tap(&:mkpath).realpath
  @arch = arch
end

Public Instance Methods

makechrootpkg(dir, env) click to toggle source
# File lib/akabei/chroot_tree.rb, line 38
def makechrootpkg(dir, env)
  System.sudo(['makechrootpkg', '-cur', @root], chdir: dir, env: env, arch: @arch)
end
mkarchroot(args) click to toggle source
# File lib/akabei/chroot_tree.rb, line 42
def mkarchroot(args)
  cmd = ['mkarchroot']
  [['-M', makepkg_config], ['-C', pacman_config]].each do |flag, path|
    if path
      cmd << flag << path
    end
  end
  cmd << @root.join('root')
  System.sudo(cmd + args, arch: @arch)
end
with_chroot(&block) click to toggle source
# File lib/akabei/chroot_tree.rb, line 20
def with_chroot(&block)
  if @root
    unless @root.join('root').directory?
      mkarchroot(BASE_PACKAGES)
    end
    block.call
  else
    @root = Pathname.new(Dir.mktmpdir)
    begin
      mkarchroot(BASE_PACKAGES)
      block.call
    ensure
      System.sudo(['rm', '-rf', @root], {})
      @root = nil
    end
  end
end