summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-03-18 13:15:12 +0100
committerEugen Wissner <belka@caraus.de>2023-03-18 13:15:12 +0100
commit6b634b40557bd8401093dc67002b355e7de16d44 (patch)
tree2546dc988d6890c07702dffcbefb9c02a82f71af /lib
parenta24f1b436ebc070b7c7a040ba2090d73095bd58e (diff)
downloadslackbuilder-6b634b40557bd8401093dc67002b355e7de16d44.tar.gz
Replace eol ioncube with php82
Diffstat (limited to 'lib')
-rw-r--r--lib/download.rb113
1 files changed, 50 insertions, 63 deletions
diff --git a/lib/download.rb b/lib/download.rb
index 64a453f..5b824f5 100644
--- a/lib/download.rb
+++ b/lib/download.rb
@@ -14,19 +14,21 @@ require 'term/ansicolor'
module SlackBuilder
extend Rake::FileUtilsExt
- def self.clone(repo, package, tag_prefix = 'v')
- repository = Pathname.new('pkg') + package.name_version
+ def self.clone(repo, tarball, tag_prefix = 'v')
+ name_version = File.basename tarball, '.tar.xz'
+ remote_path = tarball[tarball.index('/')..]
- if repository.directory?
- sh 'git', '-C', repository.to_path, 'remote', 'update', '--prune'
- else
- sh 'git', 'clone', repo, repository.to_path
+ if remote_file_exists?(remote_path)
+ uri = URI hosted_sources(remote_path)
+
+ return download(uri, "slackbuilds/#{tarball}").hexdigest
end
- sh 'git', '-C', repository.to_path, 'checkout', "#{tag_prefix}#{package.version}"
- sh 'git', '-C', repository.to_path, 'submodule', 'update', '--init', '--recursive'
+ clone_and_archive repo, name_version, tarball, tag_prefix
+
+ sh(*upload_command(tarball, remote_path))
- repository
+ Digest::MD5.hexdigest File.read("slackbuilds/#{tarball}")
end
def self.download(uri, target)
@@ -41,6 +43,33 @@ module SlackBuilder
checksum
end
+ def hosted_sources(absolute_url)
+ CONFIG[:download_url] + absolute_url
+ end
+
+ def remote_file_exists?(url)
+ uri = URI hosted_sources(url)
+
+ request = Net::HTTP.new uri.host, uri.port
+ request.use_ssl = true
+ response = request.request_head uri.path
+
+ response.code.to_i == 200
+ end
+
+ def self.download_and_deploy(uri, tarball)
+ remote_path = tarball[tarball.index('/')..]
+
+ if SlackBuilder.remote_file_exists?(remote_path)
+ 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.redirect_download(location, target)
puts 'redirecting...'
new_location = URI location
@@ -80,67 +109,23 @@ module SlackBuilder
end
end
end
-end
-
-def hosted_sources(absolute_url)
- CONFIG[:download_url] + absolute_url
-end
-
-def remote_file_exists?(url)
- uri = URI hosted_sources(url)
- request = Net::HTTP.new uri.host, uri.port
- request.use_ssl = true
- response = request.request_head uri.path
-
- response.code.to_i == 200
-end
-
-def upload_command(local_path, remote_path)
- ['scp', "slackbuilds/#{local_path}", CONFIG[:remote_path] + remote_path]
-end
-
-def clone_and_archive(repo, name_version, tarball, tag_prefix = 'v')
- _, _, version = name_version.rpartition '-'
-
- rm_rf name_version
-
- sh 'git', 'clone', repo, name_version
- sh 'git', '-C', name_version, 'checkout', "#{tag_prefix}#{version}"
- sh 'git', '-C', name_version, 'submodule', 'update', '--init', '--recursive'
-
- sh 'tar', 'Jcvf', "slackbuilds/#{tarball}", name_version
- rm_rf name_version
-end
-
-def clone(repo, tarball, tag_prefix = 'v')
- name_version = File.basename tarball, '.tar.xz'
- remote_path = tarball[tarball.index('/')..]
-
- if remote_file_exists?(remote_path)
- uri = URI hosted_sources(remote_path)
-
- return download(uri, "slackbuilds/#{tarball}").hexdigest
+ private_class_method def self.upload_command(local_path, remote_path)
+ ['scp', "slackbuilds/#{local_path}", CONFIG[:remote_path] + remote_path]
end
- clone_and_archive repo, name_version, tarball, tag_prefix
+ private_class_method def self.clone_and_archive(repo, name_version, tarball, tag_prefix = 'v')
+ _, _, version = name_version.rpartition '-'
- sh(*upload_command(tarball, remote_path))
+ rm_rf name_version
- Digest::MD5.hexdigest File.read("slackbuilds/#{tarball}")
-end
-
-def download_and_deploy(uri, tarball)
- remote_path = tarball[tarball.index('/')..]
+ sh 'git', 'clone', repo, name_version
+ sh 'git', '-C', name_version, 'checkout', "#{tag_prefix}#{version}"
+ sh 'git', '-C', name_version, 'submodule', 'update', '--init', '--recursive'
- if remote_file_exists?(remote_path)
- uri = URI hosted_sources(remote_path)
- return SlackBuilder.download(uri, "slackbuilds/#{tarball}").hexdigest
+ sh 'tar', 'Jcvf', "slackbuilds/#{tarball}", name_version
+ rm_rf name_version
end
-
- checksum = SlackBuilder.download uri, "slackbuilds/#{tarball}"
- sh(*upload_command(tarball, remote_path))
- checksum.hexdigest
end
def write_info(package, downloads:)
@@ -149,6 +134,8 @@ def write_info(package, downloads:)
end
def update_slackbuild_version(package_path, version)
+ raise TypeError, %(expected a version string, got "#{version}") unless version.is_a?(String)
+
name = package_path.split('/').last
slackbuild_filename = "slackbuilds/#{package_path}/#{name}.SlackBuild"
slackbuild_contents = File.read(slackbuild_filename)