Move download functions into a module

This commit is contained in:
Eugen Wissner 2023-01-04 10:51:08 +01:00
parent 5b26e7dca8
commit ef9942fe99
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 67 additions and 48 deletions

View File

@ -30,7 +30,7 @@ task :composer, [:version] do |_, arguments|
homepage: 'https://getcomposer.org/' homepage: 'https://getcomposer.org/'
uri = "https://getcomposer.org/download/#{arguments[:version]}/composer.phar" uri = "https://getcomposer.org/download/#{arguments[:version]}/composer.phar"
checksum = download URI(uri), 'slackbuilds/development/composer/composer.phar' checksum = SlackBuilder.download URI(uri), 'slackbuilds/development/composer/composer.phar'
write_info package, downloads: [Download.new(uri, checksum.hexdigest)] write_info package, downloads: [Download.new(uri, checksum.hexdigest)]
update_slackbuild_version 'development/composer', arguments[:version] update_slackbuild_version 'development/composer', arguments[:version]
@ -47,7 +47,7 @@ task 'universal-ctags', [:version] do |_, arguments|
uri = "https://github.com/universal-ctags/ctags/archive/#{arguments[:version]}/ctags-#{arguments[:version]}.tar.gz" uri = "https://github.com/universal-ctags/ctags/archive/#{arguments[:version]}/ctags-#{arguments[:version]}.tar.gz"
tarball = "slackbuilds/development/universal-ctags/ctags-#{arguments[:version]}.tar.gz" tarball = "slackbuilds/development/universal-ctags/ctags-#{arguments[:version]}.tar.gz"
checksum = download URI(uri), tarball checksum = SlackBuilder.download URI(uri), tarball
download = "https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{arguments[:version]}.tar.gz" download = "https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{arguments[:version]}.tar.gz"
write_info package, write_info package,
@ -90,8 +90,8 @@ task :ioncube do
'64' => URI("http://downloads3.ioncube.com/loader_downloads/#{tarball_name['64']}") '64' => URI("http://downloads3.ioncube.com/loader_downloads/#{tarball_name['64']}")
} }
checksum = { checksum = {
'32' => download(uri['32'], "slackbuilds/development/ioncube-loader/#{tarball_name['32']}").hexdigest, '32' => SlackBuilder.download(uri['32'], "slackbuilds/development/ioncube-loader/#{tarball_name['32']}").hexdigest,
'64' => download(uri['64'], "slackbuilds/development/ioncube-loader/#{tarball_name['64']}").hexdigest '64' => SlackBuilder.download(uri['64'], "slackbuilds/development/ioncube-loader/#{tarball_name['64']}").hexdigest
} }
package = Package.new 'development/ioncube-loader', package = Package.new 'development/ioncube-loader',
version: arguments[:version], version: arguments[:version],
@ -110,7 +110,7 @@ end
task :webex do task :webex do
tarball = 'slackbuilds/network/webex/Webex.deb' tarball = 'slackbuilds/network/webex/Webex.deb'
uri = 'https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb' uri = 'https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb'
checksum = download URI(uri), tarball checksum = SlackBuilder.download URI(uri), tarball
last_stdout, = Open3.pipeline_r ['ar', 'p', tarball, 'control.tar.gz'], ['tar', 'zxO', './control'] last_stdout, = Open3.pipeline_r ['ar', 'p', tarball, 'control.tar.gz'], ['tar', 'zxO', './control']
version = last_stdout.read.lines version = last_stdout.read.lines
@ -127,3 +127,22 @@ task :webex do
update_slackbuild_version 'network/webex', package.version update_slackbuild_version 'network/webex', package.version
commit 'network/webex', package.version commit 'network/webex', package.version
end end
task 'rdiff-backup', [:version] do |_, arguments|
raise 'Version is not specified.' unless arguments.key? :version
package = Package.new 'system/rdiff-backup',
version: arguments[:version],
homepage: 'https://rdiff-backup.net/',
requires: ['librsync']
uri = "https://github.com/rdiff-backup/rdiff-backup/releases/download/v#{arguments[:version]}/rdiff-backup-#{arguments[:version]}.tar.gz"
tarball = "system/rdiff-backup/rdiff-backup-#{arguments[:version]}.tar.gz"
checksum = download_and_deploy URI(uri), tarball
download = "https://download.dlackware.com/hosted-sources/rdiff-backup/rdiff-backup-#{arguments[:version]}.tar.gz"
write_info package, downloads: [Download.new(download, checksum)]
update_slackbuild_version 'system/rdiff-backup', arguments[:version]
commit 'system/rdiff-backup', arguments[:version]
end

View File

@ -28,17 +28,35 @@ module SlackBuilder
repository repository
end end
end
def write_chunk(response, checksum, progressbar, io) def self.download(uri, target)
print Term::ANSIColor.green "Downloading #{uri} "
checksum = nil
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
checksum = start_download uri, target, http
end
puts
checksum
end
private_class_method def self.redirect_download(location, target)
puts 'redirecting...'
new_location = URI location
download new_location, target
end
private_class_method def self.write_chunk(response, checksum, progressbar, io)
response.read_body do |chunk| response.read_body do |chunk|
progressbar.progress += chunk.length progressbar.progress += chunk.length
io << chunk io << chunk
checksum << chunk checksum << chunk
end end
end end
def write_download(target, response) private_class_method def self.write_download(target, response)
checksum = Digest::MD5.new checksum = Digest::MD5.new
progressbar = ProgressBar.create title: target, total: response.header.content_length progressbar = ProgressBar.create title: target, total: response.header.content_length
@ -48,16 +66,9 @@ def write_download(target, response)
progressbar.finish progressbar.finish
checksum checksum
end end
def redirect_download(location, target) private_class_method def self.start_download(uri, target, http)
puts 'redirecting...'
new_location = URI location
download new_location, target
end
def start_download(uri, target, http)
request = Net::HTTP::Get.new uri request = Net::HTTP::Get.new uri
http.request request do |response| http.request request do |response|
@ -68,18 +79,7 @@ def start_download(uri, target, http)
return write_download target, response return write_download target, response
end end
end end
end
def download(uri, target)
print Term::ANSIColor.green "Downloading #{uri} "
checksum = nil
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
checksum = start_download uri, target, http
end end
puts
checksum
end end
def hosted_sources(absolute_url) def hosted_sources(absolute_url)
@ -135,10 +135,10 @@ def download_and_deploy(uri, tarball)
if remote_file_exists?(remote_path) if remote_file_exists?(remote_path)
uri = URI hosted_sources(remote_path) uri = URI hosted_sources(remote_path)
return download(uri, "slackbuilds/#{tarball}").hexdigest return SlackBuilder.download(uri, "slackbuilds/#{tarball}").hexdigest
end end
checksum = download uri, "slackbuilds/#{tarball}" checksum = SlackBuilder.download uri, "slackbuilds/#{tarball}"
sh(*upload_command(tarball, remote_path)) sh(*upload_command(tarball, remote_path))
checksum.hexdigest checksum.hexdigest
end end

View File

@ -15,7 +15,7 @@ module SlackBuilder
tarball_name = "dmd.#{version}.linux.tar.xz" tarball_name = "dmd.#{version}.linux.tar.xz"
uri = URI "http://downloads.dlang.org/releases/2.x/#{version}/#{tarball_name}" uri = URI "http://downloads.dlang.org/releases/2.x/#{version}/#{tarball_name}"
checksum = download(uri, "slackbuilds/development/dmd/#{tarball_name}") checksum = SlackBuilder.download(uri, "slackbuilds/development/dmd/#{tarball_name}")
package = Package.new 'development/dmd', version: version, package = Package.new 'development/dmd', version: version,
homepage: 'https://dlang.org' homepage: 'https://dlang.org'