Class: Akabei::ChrootTree
- Inherits:
-
Object
- Object
- Akabei::ChrootTree
- Extended by:
- AttrPath
- Defined in:
- lib/akabei/chroot_tree.rb
Constant Summary collapse
- BASE_PACKAGES =
%w[base base-devel sudo]
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root, arch) ⇒ ChrootTree
constructor
A new instance of ChrootTree.
- #makechrootpkg(dir, env) ⇒ Object
- #mkarchroot(args) ⇒ Object
- #with_chroot(&block) ⇒ Object
Methods included from AttrPath
attr_path_accessor, attr_path_writer
Constructor Details
#initialize(root, arch) ⇒ ChrootTree
Returns a new instance of ChrootTree.
13 14 15 16 |
# File 'lib/akabei/chroot_tree.rb', line 13 def initialize(root, arch) @root = root && Pathname.new(root).tap(&:mkpath).realpath @arch = arch end |
Instance Attribute Details
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
9 10 11 |
# File 'lib/akabei/chroot_tree.rb', line 9 def arch @arch end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/akabei/chroot_tree.rb', line 9 def root @root end |
Instance Method Details
#makechrootpkg(dir, env) ⇒ Object
38 39 40 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |