Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a whole directory of files with Homebrew?

I'm using Homebrew to install a script, which depends on a directory of resources being in the same directory as the script. For example:

.
├── directory/
└── script.sh

How do I make a directory where script.sh is install with Homebrew? I have tried my formula as:

class Script < Formula
  ...
  def install
    bin.install "script.sh"
    bin.install "directory/"
  end
end

The problem is that both script.sh and directory/ are installed to /usr/local/Cellar/script/, but only script.sh is installed to /usr/local/bin/.

I have also tried replacing bin.install "directory/ with bin.install Dir["directory/"], but it did not resolve the issue.

How would I make it so script.sh can see directory/, which is in /usr/local/Cellar/script/directory/, from within my formula? Can I symlink from /usr/local/bin within my formula?

like image 941
wcarhart Avatar asked Oct 22 '25 05:10

wcarhart


1 Answers

This is a common pattern in Homebrew formulae. The solution is not to install the directory under bin/, as that directory is supposed to contains executables only, but rather to install both the script and the directory in some place, then create a wrapper in bin/ that calls the script from that place.

  1. Install everything under libexec:

     libexec.install Dir["*"]
    
  2. Write a wrapper in bin:

     bin.write_exec_script libexec/"script.sh"
    

Full formula:

class Myformula < Formula
  desc "..."
  homepage "..."
  url "..."
  sha256 "..."
  
  def install
    libexec.install Dir["*"]
    bin.write_exec_script libexec/"script.sh"
  end
end
like image 51
bfontaine Avatar answered Oct 24 '25 01:10

bfontaine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!