2016-06-03 13:05:18 +01:00
|
|
|
require "pathname"
|
2016-07-12 19:46:29 +01:00
|
|
|
require "open3"
|
2016-06-03 13:05:18 +01:00
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
def curl_executable
|
2016-06-03 13:05:18 +01:00
|
|
|
curl = Pathname.new ENV["HOMEBREW_CURL"]
|
|
|
|
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
|
2017-08-04 16:24:29 +02:00
|
|
|
return curl if curl.executable?
|
|
|
|
raise "#{curl} is not executable"
|
|
|
|
end
|
2016-06-03 13:05:18 +01:00
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
def curl_args(*extra_args, show_output: false, user_agent: :default)
|
2016-12-25 23:01:40 +00:00
|
|
|
args = [
|
2017-08-04 16:24:29 +02:00
|
|
|
curl_executable.to_s,
|
|
|
|
"--fail",
|
|
|
|
"--show-error",
|
2016-12-25 23:01:40 +00:00
|
|
|
]
|
2016-06-03 13:05:18 +01:00
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
args << "--user-agent" << case user_agent
|
|
|
|
when :browser, :fake
|
|
|
|
HOMEBREW_USER_AGENT_FAKE_SAFARI
|
|
|
|
when :default
|
|
|
|
HOMEBREW_USER_AGENT_CURL
|
2017-01-07 14:03:08 +00:00
|
|
|
else
|
2017-08-04 16:24:29 +02:00
|
|
|
user_agent
|
2016-12-25 23:01:40 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
unless show_output
|
2016-12-25 23:01:40 +00:00
|
|
|
args << "--progress-bar" unless ARGV.verbose?
|
|
|
|
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
|
|
|
|
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
|
|
|
|
end
|
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
args + extra_args
|
2016-06-03 13:05:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def curl(*args)
|
2017-08-04 16:24:29 +02:00
|
|
|
safe_system(*curl_args(*args))
|
2016-06-03 13:05:18 +01:00
|
|
|
end
|
|
|
|
|
2017-08-04 16:24:29 +02:00
|
|
|
def curl_download(*args, to: nil, **options)
|
|
|
|
curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def curl_output(*args, **options)
|
|
|
|
Open3.capture3(*curl_args(*args, show_output: true, **options))
|
2016-06-03 13:05:18 +01:00
|
|
|
end
|