#!/usr/bin/env ruby require 'shellwords' require 'getoptlong' require 'json' require 'pathname' require 'shell' require 'uri' def load_required_gem lib, gem = nil, name = nil gem ||= lib name ||= gem require lib rescue LoadError STDERR.puts <( other) version <=> other.version end def to_s r = "linux-#{version} (#{moniker})" r += " (EOL)" if end_of_life? r end end class Fetched attr_reader :dir def initialize dir @dir = Pathname.new dir end def make *opts, &block block ||= lambda {|rd| IO::copy_stream rd, STDOUT } dir = @dir.to_s rd, wr = IO.pipe pid = fork do STDOUT.reopen wr rd.close exec 'make', '-C', dir, *opts end wr.close wr = nil reader = Thread.new { block.call rd } Process.waitpid pid raise Base::MakeFailed, "make #{opts.join ' '}" unless 0 == $?.exitstatus reader.value ensure rd.close if rd wr.close if wr end def version @version ||= make '-is', 'kernelversion' do |rd| Versionomy.parse rd.readlines.join.chomp end end def config dir + '.config' end def configured? return @configured if @configured @configured = config.exist? end def <=>( other) version <=> other.version end def to_s r = "#{dir}" r += " #{version}" if @version r += " #{configured? ? :configured : 'not configured'}" if nil != @configured r end def open_config opts = nil, &block opts ||= 'r' if block_given? File.open config, opts, &block else File.open config, opts end end def import_config_from_io( io) open_config('w') {|c| io.each_line {|l| c.print l } } end def import_config file_or_io_or_fetched case file_or_io_or_fetched when IO then import_config_from_io file_or_io_or_fetched when Fetched file_or_io_or_fetched.open_config &method(:import_config_from_io) else File.open file_or_io_or_fetched.to_s, &method(:import_config_from_io) end end def oldconfig make 'oldconfig' end def menuconfig make 'menuconfig' end def compile make 'all' end def install make 'modules_install', 'install' end end class Base class Error a} end end end end end begin # if __FILE__ == $0 $debug = true if $DEBUG LinuxUpdate::Cmd.start ARGV rescue LinuxUpdate::Cmd::Error, LinuxUpdate::Base::Error STDERR.puts "Error: #{$!}" STDERR.puts $!.backtrace.map {|c| "\t#{c}" } if $debug raise #exit 1 rescue Object STDERR.puts "Unknown and unexpected Error: #{$!} (#{$!.class})" STDERR.puts $!.backtrace.map {|c| "\t#{c}" } if $debug raise #exit 2 end if __FILE__ == $0