Browse Source

program-checks (dependencies to qemu, kpartx, ...)

master
Denis Knauf 3 years ago
parent
commit
068bbc95b6
  1. 27
      lib/to_lvm_xfs/base.rb
  2. 5
      lib/to_lvm_xfs/raspbian.rb

27
lib/to_lvm_xfs/base.rb

@ -9,6 +9,15 @@ require 'to_lvm_xfs/structs'
class ProgrammError < RuntimeError
end
class Pathname
def self.which cmd
ENV['PATH'].each do |path|
path = Pathname.new( path) + cmd
return path if path.executable?
end
end
end
class Base
def self.run *args, &exe
new( *args).instance_eval &exe
@ -96,6 +105,11 @@ class Base
STDERR.print "\e[0m"
end
def check_program cmd
path = Pathname.which cmd
raise Error, "#{cmd} not found." unless path&.executable?
end
attr_reader :sh, :mounted, :looped, :base, :dest, :vgname
def initialize *args
OptionParser.new do |opts|
@ -103,6 +117,12 @@ class Base
opts.parse! args
end
%w[kpartx parted rsync lvm lvs pvs vgs mkfs.xfs mkfs.vfat dmsetup losetup lsblk blkid].each do |cmd|
check_program cmd
end
@qemu_bin_src = check_program 'qemu-arm-static'
raise Error, "@qemu-arm-static not found. Please install qemu-user-static" unless @qemu_bin_srci&.executable?
if :ask == @password
v = b = nil
require 'io/console'
@ -127,6 +147,8 @@ class Base
@base = Image.new self, 'base', image: @baseimage
@dest = Image.new self, 'dest', image: @destination
@qemu_bin = dest.root.join 'usr/bin/qemu-arm-static'
STDERR.print <<EOF
Settings:
username: #{@username || '(default)'}
@ -205,10 +227,9 @@ EOF
nok = false
build
qemu_bin = dest.root + "usr/bin/qemu-arm-static"
if qemu_bin.exist?
if @qemu_bin.exist?
msg :remove, "/usr/bin/qemu-arm-static"
qemu_bin.unlink
@qemu_bin.unlink
end
rescue ProgrammError

5
lib/to_lvm_xfs/raspbian.rb

@ -147,8 +147,7 @@ class Raspbian < Base
end
end
qemu_bin = dest.root.join 'usr/bin/qemu-arm-static'
qemu_bin.copy '/usr/bin/qemu-arm-static', preserve: true
@qemu_bin.copy @qemu_bin_src, preserve: true
preload, preload_x = dest.root+'etc/ld.so.preload', dest.root+'etc/ld.so.preload.tp'
preload.rename preload_x
@ -193,6 +192,6 @@ class Raspbian < Base
ish.system *%w[dpkg-reconfigure raspberrypi-kernel]
preload_x.rename preload
qemu_bin.unlink
@qemu_bin.unlink
end
end

Loading…
Cancel
Save