From e9831ba31bdebc68f1e4ce137dce22724f49b7d4 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sat, 20 Jun 2020 23:09:28 +0200 Subject: [PATCH] mounted: counter for each mountpoint, for umount after last release. moving output-methods to OutputHelper. --- lib/to_lvm_xfs/base.rb | 87 +++++++++++++++++++++----------------- lib/to_lvm_xfs/raspbian.rb | 24 ++++++++--- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/lib/to_lvm_xfs/base.rb b/lib/to_lvm_xfs/base.rb index 2eafb19..631dd4d 100644 --- a/lib/to_lvm_xfs/base.rb +++ b/lib/to_lvm_xfs/base.rb @@ -19,7 +19,19 @@ class Pathname end end -class Base +module OutputHelper + def d msg, eq + raise ProgrammError, msg, caller[1..-1] unless eq + end + + def err *args + STDERR.puts "\e[31;1m#{args.join ' '}\e[0m" + end + + def msg first, *args + STDERR.puts "\e[33m#{first}\e[35m #{args.join ' '}\e[0m" + end + def task name, &exe STDERR.puts "\e[30;1m***\e[0m #{name} \e[30;1m#{'*' * [0,80-name.length].max}\e[0m" if yield @@ -31,23 +43,15 @@ class Base STDERR.puts "\n\e[31;1m|||\e[0m #{name} \e[31;1m#{'|' * [0,80-name.length].max}\e[0m\n" raise end +end + +class Base + include OutputHelper def self.run *args, &exe new( *args).instance_eval &exe end - def d msg, eq - raise ProgrammError, msg, caller[1..-1] unless eq - end - - def err *args - STDERR.puts "\e[31;1m#{args.join ' '}\e[0m" - end - - def msg first, *args - STDERR.puts "\e[33m#{first}\e[35m #{args.join ' '}\e[0m" - end - def kpartx image, read_only: nil sh.kpartx "-sa#{read_only ? :r : ''}", image lpartx image @@ -103,10 +107,10 @@ class Base msg :manipulate, file File.open file.to_s, flags do |file| lines = [] - exe.call file, &lines.method(:push) + exe.call file, &lines.method( :push) file.truncate 0 file.pos = 0 - lines.each &file.method(:puts) + lines.each &file.method( :puts) end end @@ -158,22 +162,22 @@ class Base #end #STDERR.puts x.inspect #exit 1 - @mounted, @activated_vgs = [], [] + @mounted, @activated_vgs = Hash.new.tap {|h| h.default = 0 }, [] @looped = Hash.new {|h,k| h[k] = [] } @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 < { initramfs: 'initramfs initrd.img followkernel', }, 'pi0' => { initramfs: 'initramfs initrd.img followkernel', }, } - blocks = [nil] content = Hash.new {|h,block| h[block] = [] } block = nil + blocks = Set.new + blocks.add nil f.each_line do |l| l.chomp! case l when /\A\[([^\]]*)\]\z/ block = $1 - blocks.push block - when /\Ainitramfs / - l = replace[block].delete :initramfs + l = nil + blocks.add block + when /\A\s*(\w+)\s*=/i, /\A\s*(initramfs)\s+/ + b = $1.to_sym + l = replace[block].delete b if replace[block]&.has_key? b + end + unless l.nil? + content[block].push l if ''==l or l.start_with?( '#') or not content[block].include?( l) end - content[block].push l end - replace.each {|block, rpl| content[block] += rpl.values + [''] unless rpl.empty? } - blocks.flat_map {|block| content[block] } + replace.each do |block, rpl| + unless rpl.empty? + content[block] += rpl.values + [''] + blocks.add block + end + end + blocks.flat_map {|block| ["[#{block}]"] + content[block] } end addmp[:boot].join( 'ssh').write ''