2016-09-08 09:05:00 +01:00
|
|
|
#: @hide_from_man_page
|
2017-02-25 17:37:57 -05:00
|
|
|
#: * `mirror` [`--test`] <formulae>:
|
2016-09-08 09:05:00 +01:00
|
|
|
#: Reuploads the stable URL for a formula to Bintray to use it as a mirror.
|
2016-05-20 11:00:51 +01:00
|
|
|
|
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2016-05-20 11:00:51 +01:00
|
|
|
def mirror
|
2016-09-23 11:01:40 +02:00
|
|
|
odie "This command requires at least formula argument!" if ARGV.named.empty?
|
2016-05-20 11:00:51 +01:00
|
|
|
|
2017-04-22 16:31:19 +01:00
|
|
|
bintray_user = ENV["HOMEBREW_BINTRAY_USER"]
|
|
|
|
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
|
2016-05-20 11:00:51 +01:00
|
|
|
if !bintray_user || !bintray_key
|
2017-04-22 16:31:19 +01:00
|
|
|
raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!"
|
2016-05-20 11:00:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
ARGV.formulae.each do |f|
|
|
|
|
bintray_package = Utils::Bottles::Bintray.package f.name
|
|
|
|
bintray_repo_url = "https://api.bintray.com/packages/homebrew/mirror"
|
|
|
|
package_url = "#{bintray_repo_url}/#{bintray_package}"
|
|
|
|
|
|
|
|
unless system "curl", "--silent", "--fail", "--output", "/dev/null", package_url
|
|
|
|
package_blob = <<-EOS.undent
|
|
|
|
{"name": "#{bintray_package}",
|
|
|
|
"public_download_numbers": true,
|
|
|
|
"public_stats": true}
|
|
|
|
EOS
|
|
|
|
curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}",
|
|
|
|
"-H", "Content-Type: application/json",
|
|
|
|
"-d", package_blob, bintray_repo_url
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
download = f.fetch
|
|
|
|
f.verify_download_integrity(download)
|
|
|
|
filename = download.basename
|
|
|
|
destination_url = "https://dl.bintray.com/homebrew/mirror/#{filename}"
|
|
|
|
|
|
|
|
ohai "Uploading to #{destination_url}"
|
|
|
|
content_url = "https://api.bintray.com/content/homebrew/mirror"
|
|
|
|
content_url += "/#{bintray_package}/#{f.pkg_version}/#{filename}"
|
|
|
|
content_url += "?publish=1"
|
|
|
|
curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}",
|
|
|
|
"-T", download, content_url
|
|
|
|
puts
|
|
|
|
ohai "Mirrored #{filename}!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|