diff --git a/linux-update.rb b/linux-update.rb index b0d8984..f0261b7 100755 --- a/linux-update.rb +++ b/linux-update.rb @@ -46,10 +46,32 @@ EOF end end -RequiredGems.require do |rg, &push| +def requires_lib_gem &block + requires = [] + push = lambda {|lib, gem = lib, name = gem| requires.push [lib, gem, name] } + block.call &push + failed = requires.reject do |(lib, _, _)| + begin + require lib + true + rescue LoadError + false + end + end + return if failed.empty? + STDERR.puts < #{tarball}" + if true + raise DownloadFailed, uri unless Kernel.system( 'wget', '-c', '-O', dest.to_s, uri.to_s) + else + done = dest.size + p dest => done + dest.open 'a+' do |fd| + streamer = lambda do |chunk, remaining, total| + fd.write chunk + count = total - remaining + STDERR.print "\rloading %s/%s % 3d%%\e[J" % [ + format_bytes(count), format_bytes(total), 100.0*count/total ] end - Process.waitpid tar_pid - tar_status = $?.exitstatus - raise DownloadFailed, "Download of #{uri} failed." unless 0 == curl_status and 0 == tar_status + res = Excon.get uri.to_s, + response_block: streamer, + expects: 200, + headers: {'Range' => "#{done}-" } end end + dest.rename file + end + + def _unpack tarball, destdir + info "Unpack #{tarball} => #{destdir}" + unless Kernel.system 'tar', '-C', destdir.to_s, '-xf', tarball.to_s + raise UnpackFailed, tarball + end + end + + def download release_or_uri + uri = + case release_or_uri + when Release then release_or_uri.source + when URI, String then URI.parse release_or_uri.to_s + else raise UnexpectedThingToDownload, "This is no URI, String or Release" + end + # We do not understand anything else than operating systems with / as separator + @cache_dir.mkdir 0755 unless @cache_dir.exist? + tarball = @cache_dir + File.basename( uri.path) + _download uri, tarball unless tarball.exist? + _unpack tarball, @sources_base_dir end def oldconfig_prepare version = nil, config = nil version = find_fetched_version version - config = case config + config = + case config when lambda {|x| Pathname.new( config.to_s).exist? } then config when nil, false then configured.max.config else find_fetched_version( config).config @@ -315,7 +391,7 @@ module LinuxUpdate end desc 'importconfig [VERSION] [CONFIG]', 'Imports an other config from file or an other source directory. (default: most actual version with config to most actual version).' - def importconfig version, config = nil + def importconfig version = nil, config = nil version, config = base.oldconfig_prepare( version, options[:config]) version.import_config config if config end