aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie Sharpsteen2011-09-19 08:38:41 -0700
committerCharlie Sharpsteen2011-09-19 09:25:02 -0700
commit80ce89e954e8ba64ab653e1b259fd16e255974f8 (patch)
tree40c06ebfdeeacbd0bd7fa2ed8b68885fbc2d4442
parentb44c76cad0ecd4e488be85edcb2d4a5a03c6d817 (diff)
downloadhomebrew-80ce89e954e8ba64ab653e1b259fd16e255974f8.tar.bz2
mirror support: External command for mirror tests
`brew mirror-check <formula...>` will process a list of Formulae and check their mirrors to see if they are reachable and the MD5 sums are valid.
-rwxr-xr-xLibrary/Contributions/examples/brew-mirror-check.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/Library/Contributions/examples/brew-mirror-check.rb b/Library/Contributions/examples/brew-mirror-check.rb
new file mode 100755
index 000000000..1ae06ce6a
--- /dev/null
+++ b/Library/Contributions/examples/brew-mirror-check.rb
@@ -0,0 +1,55 @@
+require 'formula'
+
+class Formula
+ def test_mirror mirror
+ url, specs = mirror.values_at :url, :specs
+ downloader = download_strategy.new url, name, version, specs
+
+ # Force the downloader to attempt the download by removing the tarball if
+ # it is allready cached.
+ tarball_path = downloader.tarball_path
+ tarball_path.unlink if tarball_path.exist?
+
+ begin
+ fetched = downloader.fetch
+ rescue DownloadError => e
+ opoo "Failed to fetch from URL: #{url}"
+ return
+ end
+
+ verify_download_integrity fetched if fetched.kind_of? Pathname
+ end
+end
+
+module Homebrew extend self
+ def check_mirrors
+ mirror_check_usage = <<-EOS
+Usage: brew mirror-check <formulae ...>
+
+Cycle through mirror lists for each formula, attempt a download and validate
+MD5 sums.
+ EOS
+
+ if ARGV.empty?
+ puts mirror_check_usage
+ exit 0
+ end
+
+ formulae = ARGV.formulae
+ raise FormulaUnspecifiedError if formulae.empty?
+
+ formulae.each do |f|
+ if f.mirrors.empty?
+ opoo "#{f.name} has no mirrors"
+ next
+ else
+ oh1 "Testing mirrors for #{f.name}"
+ f.mirrors.each{ |m| f.test_mirror m }
+ end
+ end
+ end
+end
+
+# Here is the actual code that gets run when `brew` loads this external
+# command.
+Homebrew.check_mirrors