I am trying to write a shell script to automate installation of a bunch of dependencies for a project on macOS which will be an equivalent script for the same that works on EL6/EL7 and uses the
yum package manager. This script will try to leverage
HomeBrew to do the same.
A few of the tools/dependencies/packages that I want to automate installation are
git and so forth. I want to first check if any of these exist already, then update them or else install them. As you can see in this following snippet I am first trying to check if
brew exists already, then update it or else simply install it.
#!/bin/sh echo Checking brew #Check if Homebrew is already installed else prompt the user to do so. BREW_INSTALLED="/usr/local/bin/brew" #Variables to check if dependencies exist. HOMEBREW=$(which brew) echo $HOMEBREW if [ "$HOMEBREW" == "$BREW_INSTALLED" ]; then echo "Brew is already installed." echo "Update Brew" brew update else /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" fi
Now, my questions are (multipart question!)
- Is it the right way to use
which Xwhere X can be gcc, make etc. and then compare them with hardcoded
/usr/bin/Xto check their existence? Since I have quite a list of them I need to check and install so declaring variables for all and cross checking with paths somehow doesn't seem appropriate to me.
- How to handle the situation where the user has these packages installed but at some different location for whatever reason they might have? (This seems a bit objective but to ensure the project compiles and builds upon these dependencies should I force these paths only?)
- Also, one or more packages might be
gitrepos and need to be cloned, compiled, make installed on the fly. What should be the proper place to put the generated
.dylibs and create symlinks to make sure all these interdependent packages can find one another and work in peace?
- Is there anything equivalent to
jenvto isolate all these installations (of course using HomeBrew they end up in
/usr/local/Cellar)? But, as macOS does come with at least a few of them (git, gcc etc.) I don't want to duplicate installations.
P.S. Any help in terms of a direction, resource or an example project working with large amount of dependencies will help. I just can't figure out the right keywords or the right resources to look for a solution or a partial solution. Thanks. :)