Class: Dr::BuildRoot

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/dr/buildroot.rb

Instance Method Summary collapse

Methods included from Logger

log, #log, #tag

Constructor Details

#initialize(base, arch, br_cache) ⇒ BuildRoot

Returns a new instance of BuildRoot.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dr/buildroot.rb', line 14

def initialize(base, arch, br_cache)
  @location = "#{br_cache}/#{base.strip.downcase.gsub(" ", "_")}-#{arch}.tar.gz"
  @base = base
  @arch = arch

  @essential_pkgs = "sudo,vim,ca-certificates,fakeroot,build-essential," +
                    "curl,devscripts,debhelper,git,bc,locales,equivs," +
                    "pkg-config,libfile-fcntllock-perl"

  if !File.exists?(@location)
    setup base, arch
  end
end

Instance Method Details

#open ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dr/buildroot.rb', line 28

def open
  Dir.mktmpdir do |tmp|
    log :info, "Preparing #{@base.fg "blue"} #{@arch.fg "orange"} build root"
    ShellCmd.new "sudo tar xz -C #{tmp} -f #{@location}", :tag => "tar"
    begin
      log :info, "Mounting the /proc file system"
      mnt_cmd = "sudo chroot #{tmp} mount -t proc none /proc"
      ShellCmd.new mnt_cmd, :tag => "mount"
      yield tmp
    ensure
      log :info, "Unmounting the /proc file system"
      umnt_cmd = "sudo chroot #{tmp} umount -f /proc"
      ShellCmd.new umnt_cmd, :tag => "umount"

      log :info, "Cleaning up the buildroot"
      ShellCmd.new "sudo rm -rf #{tmp}/*", :tag => "rm"
    end
  end
end