[do not use] httpclient.
This commit is contained in:
parent
8273ad411d
commit
7376a8521e
|
@ -7,22 +7,52 @@ require 'pathname'
|
||||||
require 'shell'
|
require 'shell'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
def load_required_gem lib, gem = nil, name = nil
|
class RequiredGems
|
||||||
|
attr_reader :requires, :failed
|
||||||
|
def self.require &block
|
||||||
|
rg = new
|
||||||
|
block.call rg, &rg.method(:push)
|
||||||
|
rg.require
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@requires, @failed = [], []
|
||||||
|
end
|
||||||
|
|
||||||
|
def push lib, gem = nil, name = nil
|
||||||
gem ||= lib
|
gem ||= lib
|
||||||
name ||= gem
|
name ||= gem
|
||||||
|
@requires.push [lib, gem, name]
|
||||||
|
end
|
||||||
|
|
||||||
|
def try_require lib
|
||||||
require lib
|
require lib
|
||||||
rescue LoadError
|
true
|
||||||
|
rescue LoadError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def require lib = nil
|
||||||
|
return super lib if lib # if lib given, require it.
|
||||||
|
|
||||||
|
@failed = @requires.reject {|(lib, _, _)| try_require lib }
|
||||||
|
return if @failed.empty?
|
||||||
STDERR.puts <<EOF
|
STDERR.puts <<EOF
|
||||||
Loading #{name} failed. Please install it first:
|
Loading of #{@failed.map{|(_,_,n)|n}.join ', '} failed.
|
||||||
sudo gem install #{gem}
|
Please install if first:
|
||||||
|
sudo gem install #{@failed.map{|(_,g,_)|g}.join ' '}
|
||||||
EOF
|
EOF
|
||||||
raise
|
exit 127
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RequiredGems.require do |rg, &push|
|
||||||
|
push[ 'thor', nil, 'Thor']
|
||||||
|
push[ 'irb-pager', nil, 'IRB::Pager']
|
||||||
|
push[ 'httpclient', nil, 'HTTPClient']
|
||||||
|
push[ 'versionomy', nil, 'Versionomy']
|
||||||
end
|
end
|
||||||
|
|
||||||
load_required_gem 'thor', nil, 'Thor'
|
|
||||||
load_required_gem 'irb-pager', nil, 'IRB::Pager'
|
|
||||||
load_required_gem 'httpclient', nil, 'HTTPClient'
|
|
||||||
load_required_gem 'versionomy', nil, 'Versionomy'
|
|
||||||
|
|
||||||
module LinuxUpdate
|
module LinuxUpdate
|
||||||
Release = Struct.new :version, :moniker, :source, :pgp, :released, :gitweb, :changelog, :patch_full, :patch_incremental, :iseol
|
Release = Struct.new :version, :moniker, :source, :pgp, :released, :gitweb, :changelog, :patch_full, :patch_incremental, :iseol
|
||||||
|
@ -149,6 +179,8 @@ module LinuxUpdate
|
||||||
end
|
end
|
||||||
class MakeFailed <Error
|
class MakeFailed <Error
|
||||||
end
|
end
|
||||||
|
class DownloadFailed <Error
|
||||||
|
end
|
||||||
attr_reader :releases_uri, :sources_base_dir
|
attr_reader :releases_uri, :sources_base_dir
|
||||||
ReleasesURI = 'https://www.kernel.org/releases.json'
|
ReleasesURI = 'https://www.kernel.org/releases.json'
|
||||||
SourcesBaseDir = '/usr/src'
|
SourcesBaseDir = '/usr/src'
|
||||||
|
@ -177,7 +209,10 @@ module LinuxUpdate
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetched
|
def fetched
|
||||||
@fetched ||= Dir[ @sources_base_dir + 'linux-*'].map {|d| Fetched.new d }
|
@fetched ||= Dir[ @sources_base_dir + 'linux-*'].
|
||||||
|
map( &Pathname.method( :new)).
|
||||||
|
select!( &:directory?).
|
||||||
|
map {|d| Fetched.new d }
|
||||||
end
|
end
|
||||||
|
|
||||||
def configured() fetched.select &:configured? end
|
def configured() fetched.select &:configured? end
|
||||||
|
@ -205,10 +240,19 @@ module LinuxUpdate
|
||||||
else raise UnexpectedThingToDownload, "This is no URI, String or Release"
|
else raise UnexpectedThingToDownload, "This is no URI, String or Release"
|
||||||
end
|
end
|
||||||
dir = @sources_base_dir
|
dir = @sources_base_dir
|
||||||
::Shell.new.transact do
|
HTTPClient.new do |hc|
|
||||||
self.verbose = 0
|
hc.get uri do |chunk|
|
||||||
chdir dir
|
p chunk.length
|
||||||
system( 'curl', uri) | system( 'tar', '-xJf', '-')
|
next
|
||||||
|
tar_pid = fork do
|
||||||
|
Dir.chdir dir
|
||||||
|
STDIN.reopen rd
|
||||||
|
Kernel.exec 'tar', '--no-ignore-command-error', '-xJf', '-'
|
||||||
|
end
|
||||||
|
Process.waitpid tar_pid
|
||||||
|
tar_status = $?.exitstatus
|
||||||
|
raise DownloadFailed, "Download of #{uri} failed." unless 0 == curl_status and 0 == tar_status
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -327,6 +371,16 @@ module LinuxUpdate
|
||||||
version.install
|
version.install
|
||||||
end
|
end
|
||||||
|
|
||||||
|
option :any, type: :boolean, aliases: '-a', desc: 'Select any versions.'
|
||||||
|
option :longterm, type: :boolean, aliases: '-o', desc: 'Select long term versions.'
|
||||||
|
option :stable, type: :boolean, aliases: '-s', desc: 'Select stable versions (default).'
|
||||||
|
option :mainline, type: :boolean, aliases: '-m', desc: 'Select mainline versions.'
|
||||||
|
desc 'update [VERSION]', 'Download, compile and install linux-kernel'
|
||||||
|
def update version = nil
|
||||||
|
fetch version
|
||||||
|
all version
|
||||||
|
end
|
||||||
|
|
||||||
no_commands do
|
no_commands do
|
||||||
def base
|
def base
|
||||||
@base ||= Base.new
|
@base ||= Base.new
|
||||||
|
|
Loading…
Reference in a new issue