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?
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.
Install everything under libexec:
libexec.install Dir["*"]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With