program-checks (dependencies to qemu, kpartx, ...)
This commit is contained in:
parent
6aee21c7ca
commit
068bbc95b6
|
@ -9,6 +9,15 @@ require 'to_lvm_xfs/structs'
|
||||||
class ProgrammError < RuntimeError
|
class ProgrammError < RuntimeError
|
||||||
end
|
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
|
class Base
|
||||||
def self.run *args, &exe
|
def self.run *args, &exe
|
||||||
new( *args).instance_eval &exe
|
new( *args).instance_eval &exe
|
||||||
|
@ -96,6 +105,11 @@ class Base
|
||||||
STDERR.print "\e[0m"
|
STDERR.print "\e[0m"
|
||||||
end
|
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
|
attr_reader :sh, :mounted, :looped, :base, :dest, :vgname
|
||||||
def initialize *args
|
def initialize *args
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
|
@ -103,6 +117,12 @@ class Base
|
||||||
opts.parse! args
|
opts.parse! args
|
||||||
end
|
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
|
if :ask == @password
|
||||||
v = b = nil
|
v = b = nil
|
||||||
require 'io/console'
|
require 'io/console'
|
||||||
|
@ -127,6 +147,8 @@ class Base
|
||||||
@base = Image.new self, 'base', image: @baseimage
|
@base = Image.new self, 'base', image: @baseimage
|
||||||
@dest = Image.new self, 'dest', image: @destination
|
@dest = Image.new self, 'dest', image: @destination
|
||||||
|
|
||||||
|
@qemu_bin = dest.root.join 'usr/bin/qemu-arm-static'
|
||||||
|
|
||||||
STDERR.print <<EOF
|
STDERR.print <<EOF
|
||||||
Settings:
|
Settings:
|
||||||
username: #{@username || '(default)'}
|
username: #{@username || '(default)'}
|
||||||
|
@ -205,10 +227,9 @@ EOF
|
||||||
nok = false
|
nok = false
|
||||||
build
|
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"
|
msg :remove, "/usr/bin/qemu-arm-static"
|
||||||
qemu_bin.unlink
|
@qemu_bin.unlink
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue ProgrammError
|
rescue ProgrammError
|
||||||
|
|
|
@ -147,8 +147,7 @@ class Raspbian < Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
qemu_bin = dest.root.join 'usr/bin/qemu-arm-static'
|
@qemu_bin.copy @qemu_bin_src, preserve: true
|
||||||
qemu_bin.copy '/usr/bin/qemu-arm-static', preserve: true
|
|
||||||
|
|
||||||
preload, preload_x = dest.root+'etc/ld.so.preload', dest.root+'etc/ld.so.preload.tp'
|
preload, preload_x = dest.root+'etc/ld.so.preload', dest.root+'etc/ld.so.preload.tp'
|
||||||
preload.rename preload_x
|
preload.rename preload_x
|
||||||
|
@ -193,6 +192,6 @@ class Raspbian < Base
|
||||||
ish.system *%w[dpkg-reconfigure raspberrypi-kernel]
|
ish.system *%w[dpkg-reconfigure raspberrypi-kernel]
|
||||||
|
|
||||||
preload_x.rename preload
|
preload_x.rename preload
|
||||||
qemu_bin.unlink
|
@qemu_bin.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue