Files
chromebrew/lib/downloader.rb
Satadru Pramanik, DO, MPH, MEng 8dbc3925d2 icu4c => 75.1 + updates (#10246)
* Update icu4c, libxml2

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update libxml2

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update binaries

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* libxslt rebuild

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* updates and rebuilds for harfbuzz, freetype, fontconfig, cairo, pango

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild libxslt with new version

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add icu version to libarchive

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust xmlto deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust xmlto deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust xmlto deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* icu version shared_mime_info

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add js115 py deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* python updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update binutils to master

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* more test changes for js115

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update py3_pyicu

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild wayland

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update librsvg

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild xfsprogs

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild bind

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* boost rebuild

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add libabigail, update sphinx and deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild yelp

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update gspell

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update imlib2

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update libgsf

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild libcdr, update libical

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild libmetalink, update libvisio

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild caja

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update gtk3

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update glib

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update gobject_introspection

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update gnome_docking_library package

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* more gnome updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup nautilus

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update vte, revert js115 changes to allow installs, add arm builds for tinysparql, localsearch, nautilus

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* glibc testing upload

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update r

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* suggested changes to add detection for -icu??.?

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rebuild geany_plugins

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add dehtml, rework glibc_build237

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update py3_pyyaml

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update libdbusmenu_gtk3

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update gtksourceview_5, cleanup sass packages

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update sass packages, add binaries

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update graphicsmagick, refactor glibc_build237

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add x86_84 binaries for tinysparql, localsearch, nautilus

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update evolution_data_server

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* iterate

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* xwayland => 24.1.2

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update glibc_build237 binaries

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* sync glibc packages

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* remove instance variables

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* more pkg updates, update mold

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fix webkitgtk_6 pkg

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* sync glibc changes

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust mysql deps

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add new packages to packages.yaml

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update package file for webkitgtk_6

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* python => 3.12.5

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust build options for js115

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update js115

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update more packages

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add i686 build

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add builds for uriparser

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust force flag

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fix downloader force

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup download pkg_name usage

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update smbclient package

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update tesseract package

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* package updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update tesseract, add time check for builds to crew

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update some samba packages

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update tepl packages

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add ruby_pry_byebug

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update smbclient

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* tepl updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update smbclient

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update imagemagick7

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add postgresql binaries

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fix yaml

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust build_elapsed time code, add verbose build to unit test

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add CREW_DEBUG to help debug issues with crew (invoke with crew <command> --debug).

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update crew_profile_base

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* some python package cleanups

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add print_source_bashrc to docbook_xsl

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add debugging info message

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* bump version

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* suggested changes and install updates

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add crew_sudo binaries

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* rubocop fixes

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Fixes: #10291

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* refactor crew upload

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* abort when a file is already uploaded

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* use highline for crew upload prompt

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add highline to buildessential

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* adjust highline update speed in packages.yaml

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2024-08-11 03:19:59 -05:00

191 lines
6.7 KiB
Ruby

require 'io/console'
require 'digest/sha2'
require 'uri'
require_relative 'const'
require_relative 'color'
require_relative 'progress_bar'
begin
require 'securerandom'
require 'resolv-replace'
require 'net/http'
rescue RuntimeError => e
# hide the error message and fallback to curl if securerandom raise an error
if e.message == 'failed to get urandom'
Object.send(:remove_const, :CREW_USE_CURL)
CREW_USE_CURL = true
else
raise
end
end
def downloader(url, sha256sum, filename = File.basename(url), verbose = false)
# downloader: wrapper for all Chromebrew downloaders (`net/http`,`curl`...)
# Usage: downloader <url>, <sha256sum>, <filename::optional>, <verbose::optional>
#
# <url>: URL that points to the target file
# <sha256sum>: SHA256 checksum, verify downloaded file with given checksum
# <filename>: (Optional) Output path/filename
# <verbose>: (Optional) Verbose output
#
puts "downloader(#{url}, #{sha256sum}, #{filename}, #{verbose})" if verbose
uri = URI(url)
if CREW_USE_CURL || !ENV['CREW_DOWNLOADER'].to_s.empty?
# force using external downloader if either CREW_USE_CURL or ENV['CREW_DOWNLOADER'] is set
puts "external_downloader(#{uri}, #{filename}, #{verbose})" if verbose
external_downloader(uri, filename, verbose)
else
case uri.scheme
when 'http', 'https'
# use net/http if the url protocol is http(s)://
puts "http_downloader(#{uri}, #{filename}, #{verbose})" if verbose
http_downloader(uri, filename, verbose)
when 'file'
# use FileUtils to copy if it is a local file (the url protocol is file://)
if File.exist?(uri.path)
return FileUtils.cp(uri.path, filename)
else
abort "#{uri.path}: File not found :/".lightred
end
else
# use external downloader (curl by default) if the url protocol is not http(s):// or file://
puts "external_downloader(#{uri}, #{filename}, #{verbose})" if verbose
external_downloader(uri, filename, verbose)
end
end
# verify with given checksum
calc_sha256sum = Digest::SHA256.hexdigest(File.read(filename))
unless (sha256sum =~ /^SKIP$/i) || (calc_sha256sum == sha256sum)
if CREW_FORCE
pkg_name = @pkg_name.empty? ? name : @pkg_name
puts "Updating checksum for #{filename}".lightblue
puts "from #{sha256sum} to #{calc_sha256sum}".lightblue
puts "in #{CREW_LOCAL_REPO_ROOT}/packages/#{pkg_name}.rb .".lightblue
system "sed -i 's/#{sha256sum}/#{calc_sha256sum}/' #{CREW_LOCAL_REPO_ROOT}/packages/#{pkg_name}.rb"
else
FileUtils.rm_f filename
warn 'Checksum mismatch :/ Try again?'.lightred, <<~EOT
#{''}
Filename: #{filename.lightblue}
Expected checksum (SHA256): #{sha256sum.green}
Calculated checksum (SHA256): #{calc_sha256sum.red}
EOT
exit 2
end
end
rescue StandardError => e
warn e.full_message
# fallback to curl if error occurred
puts "external_downloader(#{uri}, #{filename}, #{verbose})" if verbose
external_downloader(uri, filename, verbose)
end
def http_downloader(uri, filename = File.basename(url), verbose = false)
# http_downloader: Downloader based on net/http library
ssl_error_retry = 0
# open http connection
Net::HTTP.start(uri.host, uri.port, {
max_retries: CREW_DOWNLOADER_RETRY,
use_ssl: uri.scheme.eql?('https'),
min_version: :TLS1_2,
ca_file: SSL_CERT_FILE,
ca_path: SSL_CERT_DIR
}) do |http|
http.request(Net::HTTP::Get.new(uri)) do |response|
case
when response.is_a?(Net::HTTPSuccess)
# Response is successful, don't abort
when response.is_a?(Net::HTTPRedirection) # follow HTTP redirection
puts <<~EOT if verbose
* Follow HTTP redirection: #{response['Location']}
*
EOT
redirect_uri = URI(response['Location'])
# add url scheme/host for redirected url based on original url if missing
redirect_uri.scheme ||= uri.scheme
redirect_uri.host ||= uri.host
return send(__method__, redirect_uri, filename, verbose)
else
abort "Download failed with error #{response.code}: #{response.msg}".lightred
end
# get target file size (should be returned by the server)
file_size = response['Content-Length'].to_f
downloaded_size = 0.0
# initialize progress bar
progress_bar = ProgressBar.new(file_size)
if verbose
warn <<~EOT
* Connected to #{uri.host} port #{uri.port}
* HTTPS: #{uri.scheme.eql?('https')}
*
EOT
# parse response's header to readable format
response.to_hash.each_pair { |k, v| warn "> #{k}: #{v}" }
warn "\n"
end
progress_bar_thread = progress_bar.show # print progress bar
# read file chunks from server, write it to filesystem
File.open(filename, 'wb') do |io|
response.read_body do |chunk|
downloaded_size += chunk.size # record downloaded size, used for showing progress bar
progress_bar.set_downloaded_size(downloaded_size, invalid_size_error: false) if file_size.positive?
io.write(chunk) # write to file
end
ensure
# stop progress bar, wait for it to terminate
progress_bar.progress_bar_showing = false
progress_bar_thread.join
end
end
end
rescue OpenSSL::SSL::SSLError
# handle SSL errors
ssl_error_retry += 1
ssl_error_retry <= 3 ? retry : raise
end
def external_downloader(uri, filename = File.basename(url), verbose = false)
# external_downloader: wrapper for external downloaders in CREW_DOWNLOADER (curl by default)
# default curl cmdline, CREW_DOWNLOADER should be in this format also
# %<verbose>s: Will be substitute to "--verbose" if #{verbose} set to true, otherwise will be substitute to ""
# %<retry>: Will be substitute to #{CREW_DOWNLOADER_RETRY}
# %<url>s: Will be substitute to #{url}
# %<output>s: Will be substitute to #{filename}
# i686 curl throws a "SSL certificate problem: self signed certificate in certificate chain" error.
# Only bypass this when we are using the system curl early in install.
@default_curl = `which curl`.chomp
curl_cmdline = ARCH == 'i686' && @default_curl == '/usr/bin/curl' ? 'curl %<verbose>s -kL -# --retry %<retry>s %<url>s -o %<output>s' : 'curl %<verbose>s -L -# --retry %<retry>s %<url>s -o %<output>s'
# use CREW_DOWNLOADER if specified, use curl by default
downloader_cmdline = CREW_DOWNLOADER || curl_cmdline
return system(
format(downloader_cmdline,
{
verbose: verbose ? '--verbose' : '',
retry: CREW_DOWNLOADER_RETRY,
url: uri.to_s,
output: filename
}), exception: true
)
end