64 lines
1.9 KiB
Ruby
Raw Normal View History

#: @hide_from_man_page
#: * `mirror` <formulae>:
#: Reuploads the stable URL for a formula to Bintray to use it as a mirror.
require "cli_parser"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def mirror_args
Homebrew::CLI::Parser.new do
switch :debug
switch :verbose
end
end
def mirror
mirror_args.parse
2016-09-23 11:01:40 +02:00
odie "This command requires at least formula argument!" if ARGV.named.empty?
bintray_user = ENV["HOMEBREW_BINTRAY_USER"]
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
if !bintray_user || !bintray_key
raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!"
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_executable, "--silent", "--fail", "--output", "/dev/null", package_url
2018-07-11 15:17:40 +02:00
package_blob = <<~JSON
{"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
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
2018-10-01 10:19:55 +02:00
destination_url = "https://dl.bintray.com/homebrew/mirror/#{filename}"
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
puts
ohai "Mirrored #{filename}!"
end
end
end