slackbuilder/lib/download.rb

67 lines
1.9 KiB
Ruby
Raw Normal View History

2020-12-09 18:28:42 +01:00
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true
2021-01-02 07:39:32 +01:00
require_relative '../config/config'
2020-12-09 18:28:42 +01:00
require_relative 'package'
require 'net/http'
2022-06-17 22:49:30 +02:00
require 'pathname'
2022-12-04 15:03:14 +01:00
require 'progressbar'
require 'term/ansicolor'
2022-06-17 22:49:30 +02:00
module SlackBuilder
extend Rake::FileUtilsExt
2023-03-18 13:15:12 +01:00
def self.clone(repo, tarball, tag_prefix = 'v')
2023-08-25 10:30:24 +02:00
`./bin/slackbuilder clone #{repo} #{tarball} #{tag_prefix}`
2022-06-17 22:49:30 +02:00
end
2020-12-09 18:28:42 +01:00
2023-01-04 10:51:08 +01:00
def self.download(uri, target)
2023-08-21 13:38:20 +02:00
`./bin/slackbuilder download #{uri} #{target}`.strip
2020-12-09 18:28:42 +01:00
end
def self.hosted_sources(absolute_url)
2023-03-18 13:15:12 +01:00
CONFIG[:download_url] + absolute_url
end
def self.remote_file_exists?(url)
`./bin/slackbuilder exists #{url}`.strip == 'True'
2023-03-18 13:15:12 +01:00
end
def self.download_and_deploy(uri, tarball)
remote_path = tarball[tarball.index('/')..]
if remote_file_exists?(remote_path)
2023-03-18 13:15:12 +01:00
uri = URI hosted_sources(remote_path)
return download(uri, "slackbuilds/#{tarball}").hexdigest
end
checksum = download uri, "slackbuilds/#{tarball}"
sh(*upload_command(tarball, remote_path))
checksum.hexdigest
end
private_class_method def self.upload_command(local_path, remote_path)
['scp', "slackbuilds/#{local_path}", CONFIG[:remote_path] + remote_path]
2020-12-09 18:28:42 +01:00
end
2023-03-18 13:15:12 +01:00
private_class_method def self.clone_and_archive(repo, name_version, tarball, tag_prefix = 'v')
sh './bin/slackbuilder', 'archive', repo, name_version, tarball, tag_prefix
2020-12-09 18:28:42 +01:00
end
end
2021-05-04 07:47:24 +02:00
def write_info(package, downloads:)
2022-06-14 06:52:24 +02:00
File.write "slackbuilds/#{package.path}/#{package.name}.info",
info_template(package, downloads)
2020-12-09 18:28:42 +01:00
end
def update_slackbuild_version(package_path, version)
2023-08-15 10:33:19 +02:00
sh './bin/slackbuilder', 'slackbuild', package_path, version
2020-12-09 18:28:42 +01:00
end
def commit(package_path, version)
2023-08-15 10:33:19 +02:00
sh './bin/slackbuilder', 'commit', package_path, version
2020-12-09 18:28:42 +01:00
end