2016-09-08 09:05:00 +01:00
|
|
|
#: @hide_from_man_page
|
2018-04-10 18:37:15 +05:30
|
|
|
#: * `mirror` <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
|
|
|
|
2018-04-10 18:37:15 +05:30
|
|
|
require "cli_parser"
|
|
|
|
|
2016-05-20 11:00:51 +01:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-07-30 18:25:38 +05:30
|
|
|
def mirror_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2018-04-01 16:47:30 +05:30
|
|
|
switch :debug
|
|
|
|
switch :verbose
|
|
|
|
end
|
2018-07-30 18:25:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def mirror
|
|
|
|
mirror_args.parse
|
2018-04-01 16:47:30 +05:30
|
|
|
|
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}"
|
|
|
|
|
2018-06-25 06:33:44 -07:00
|
|
|
unless system curl_executable, "--silent", "--fail", "--output", "/dev/null", package_url
|
2018-07-11 15:17:40 +02:00
|
|
|
package_blob = <<~JSON
|
2016-05-20 11:00:51 +01:00
|
|
|
{"name": "#{bintray_package}",
|
|
|
|
"public_download_numbers": true,
|
|
|
|
"public_stats": true}
|
2018-07-11 15:17:40 +02:00
|
|
|
JSON
|
2017-08-08 18:10:13 +02:00
|
|
|
curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}",
|
|
|
|
"--header", "Content-Type: application/json",
|
|
|
|
"--data", package_blob, bintray_repo_url
|
2016-05-20 11:00:51 +01:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
2018-10-01 10:19:55 +02:00
|
|
|
downloader = f.downloader
|
|
|
|
|
|
|
|
downloader.fetch
|
|
|
|
f.verify_download_integrity(downloader.cached_location)
|
|
|
|
|
|
|
|
filename = downloader.basename
|
2016-05-20 11:00:51 +01:00
|
|
|
|
2018-10-01 10:19:55 +02:00
|
|
|
destination_url = "https://dl.bintray.com/homebrew/mirror/#{filename}"
|
2016-05-20 11:00:51 +01:00
|
|
|
ohai "Uploading to #{destination_url}"
|
2018-10-01 10:19:55 +02:00
|
|
|
|
|
|
|
content_url =
|
|
|
|
"https://api.bintray.com/content/homebrew/mirror/#{bintray_package}/#{f.pkg_version}/#{filename}?publish=1"
|
2017-08-08 18:10:13 +02:00
|
|
|
curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}",
|
2018-10-01 10:19:55 +02:00
|
|
|
"--upload-file", downloader.cached_location, content_url
|
2016-05-20 11:00:51 +01:00
|
|
|
puts
|
|
|
|
ohai "Mirrored #{filename}!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|