Apple - With Homebrew, how to check if a software/package is installed?
you could do something like this:
brew list <formula1> || brew install <formula1>
This will error on list and continue with install if not installed otherwise it will just list package files. (one could modify this further as a function or alias in .bashrc to make it easier to type)
It should also be noted that you can type brew info <formula>
which will tell you whether or not a formula is installed. You can parse the response for "Not installed" and then run the installer if it finds the string.