Created
November 19, 2018 06:12
-
-
Save sj26/db20012bd2353800275e94c65a43d80b to your computer and use it in GitHub Desktop.
Setup a mirror to use with $HOMEBREW_ARTIFACT_DOMAIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Homebrew has $HOMEBREW_ARTIFACT_DOMAIN which allows using a mirror for downloads: | |
# | |
# https://docs.brew.sh/Manpage#environment | |
# | |
# But no easy way to create such a mirror. This command which creates a mirror from | |
# all core formulae downloads. Pop it in /usr/local/Homebrew/Library/Homebrew/cmd/ | |
# with a `chmod +x` and run `brew mirror-artifacts`. | |
require "formula" | |
base_path = Pathname.new(ENV.fetch("HOMEBREW_ARTIFACT_PATH") { Dir.pwd }) | |
ohai "Mirroring all formula downloads to: #{path}" | |
Formula.core_files.each do |fi| | |
begin | |
f = Formula[fi] | |
rescue Exception => e | |
opoo "#{fi}: something goes wrong." | |
puts e.message | |
puts e.backtrace.inspect | |
next | |
end | |
if f.downloader.is_a? CurlDownloadStrategy | |
ohai "Mirroring #{f}" | |
url = f.downloader.url | |
uri = URI.parse(url) | |
path = base_path.join(uri.host, uri.path.delete_prefix("/")) | |
path.parent.mkpath | |
curl_download url, to: path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment