HomeBrew Formula: Download Two URL Packages

I need to get nginx compiled with a file download package. The module is not part of the standard nginx brew formula. It seems that the brew formulas are based on a single pkg download, see below

class Nginx < Formula
  homepage 'http://nginx.org/'
  url 'http://nginx.org/download/nginx-1.2.0.tar.gz'
  md5 'a02ef93d65a7031a1ea3256ad5eba626'

  devel do
    url 'http://nginx.org/download/nginx-1.3.0.tar.gz'
    md5 'b02e171c4a088aa9a5ab387943ce08eb'
  end

How can I download below in a subfolder, say nginx / contrib?

url 'http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz'
md5 '2681a6167551830a23336fa41bc539a1'
+3
source share
2 answers

You can use the "subformula". You stick to this class definition in the Nginx formula file:

class NginxUploadModule < Formula
  url 'http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz'
  md5 '2681a6167551830a23336fa41bc539a1'
end

and then in installthe Nginx formula method you will do something like

NginxUploadModule.new.brew do
  (buildpath/'where/you/want/the/files').install Dir['*']
end

adjust the path accordingly.

There are several examples of this in the Homebrew base repository; grepping for "new.brew" should give you a lot.

+5
source

https://github.com/Homebrew/homebrew/blob/master/Library/Contributions/example-formula.rb

# Additional downloads can be defined as resources and accessed in the
# install method. Resources can also be defined inside a stable, devel, or
# head block. This mechanism replaces ad-hoc "subformula" classes.
resource "additional_files" do
  url "https://example.com/additional-stuff.tar.gz"
  sha1 "deadbeef7890123456789012345678901234567890"
end

# Additional downloads can be defined as resources (see above).
# The stage method will create a temporary directory and yield
# to a block.
resource("additional_files").stage { bin.install "my/extra/tool" }
+3

All Articles